Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SonoNet_PyTorch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jakambs
SonoNet_PyTorch
Commits
6055426d
Commit
6055426d
authored
2 years ago
by
Jakob Ambsdorf
Browse files
Options
Downloads
Patches
Plain Diff
add support for arguments, make CUDA optional
parent
0f3ecae7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test.py
+39
-24
39 additions, 24 deletions
test.py
with
39 additions
and
24 deletions
test.py
+
39
−
24
View file @
6055426d
...
...
@@ -3,7 +3,9 @@ test.py: Modified version of the original example.py file.
This file runs classification on the examples images.
'''
import
argparse
import
glob
import
matplotlib.pyplot
as
plt
from
matplotlib.pyplot
import
imread
import
numpy
as
np
...
...
@@ -25,20 +27,7 @@ which provides a theano+lasagne implementation.
'''
print
(
disclaimer
)
# Configuration
network_name
=
'
SN64
'
# 'SN16', 'SN32' pr 'SN64'
display_images
=
False
# Whether or not to show the images during inference
GPU_NR
=
0
# Choose the device number of your GPU
# If you provide the original lasagne parameter file, it will be converted to a
# pytorch state_dict and saved as *.pth.
# In this repository, the converted parameters are already provided.
weights
=
True
# weights = ('/local/ball4916/dphil/SonoNet/SonoNet-weights/SonoNet{}.npz'
# .format(network_name[2:]))
# Other parameters
# Configuration parameters
crop_range
=
[(
115
,
734
),
(
81
,
874
)]
# [(top, bottom), (left, right)]
input_size
=
[
224
,
288
]
image_path
=
'
./example_images/*.tiff
'
...
...
@@ -94,22 +83,36 @@ def prepare_inputs():
return
input_list
def
main
():
def
main
(
args
):
# convert weights parameter for sononet
if
args
.
weights
==
'
default
'
:
weights
=
True
elif
args
.
weights
==
'
none
'
:
weights
=
False
elif
args
.
weights
==
'
random
'
:
weights
=
0
else
:
weights
=
args
.
weights
print
(
'
Loading network
'
)
net
=
sononet
.
SonoNet
(
network_name
,
weights
=
weights
)
net
=
sononet
.
SonoNet
(
args
.
network_name
,
weights
=
weights
)
net
.
eval
()
if
args
.
cuda
:
print
(
'
Moving to GPU:
'
)
torch
.
cuda
.
device
(
GPU_NR
)
torch
.
cuda
.
device
(
args
.
GPU_NR
)
print
(
torch
.
cuda
.
get_device_name
(
torch
.
cuda
.
current_device
()))
net
.
cuda
()
print
(
"
\n
Predictions using {}:
"
.
format
(
network_name
))
print
(
"
\n
Predictions using {}:
"
.
format
(
args
.
network_name
))
input_list
=
prepare_inputs
()
for
image
,
file_name
in
zip
(
input_list
,
glob
.
glob
(
image_path
)):
# Run inference
if
args
.
cuda
:
x
=
Variable
(
torch
.
from_numpy
(
image
).
cuda
())
else
:
x
=
Variable
(
torch
.
from_numpy
(
image
))
outputs
=
net
(
x
)
confidence
,
prediction
=
torch
.
max
(
outputs
.
data
,
1
)
...
...
@@ -119,10 +122,22 @@ def main():
.
format
(
label_names
[
prediction
[
0
]],
confidence
[
0
],
true_label
))
if
display_images
:
if
args
.
display_images
:
plt
.
imshow
(
np
.
squeeze
(
image
),
cmap
=
'
gray
'
)
plt
.
show
()
if
__name__
==
'
__main__
'
:
main
()
# argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'
SonoNet
'
)
parser
.
add_argument
(
'
--cuda
'
,
action
=
'
store_true
'
,
default
=
False
)
parser
.
add_argument
(
'
--network_name
'
,
type
=
str
,
default
=
'
SN64
'
,
help
=
'
SN16, SN32 or SN64
'
)
parser
.
add_argument
(
'
--display_images
'
,
type
=
bool
,
default
=
False
,
help
=
'
Whether or not to show the images during inference
'
)
parser
.
add_argument
(
'
--GPU_NR
'
,
type
=
int
,
default
=
0
,
help
=
'
Choose the device number of your GPU
'
)
parser
.
add_argument
(
'
--weights
'
,
type
=
str
,
default
=
'
default
'
,
help
=
'
Select weight initialization.
\
"
default
"
: Load weights from default *.pth weight file.
"
none
"
: No weights are initialized.
\
"
random
"
: Standard random weight initialization. Or: Pass the path to your own weight file
'
)
args
=
parser
.
parse_args
()
main
(
args
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment