Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
b4ea1bf3
Commit
b4ea1bf3
authored
2 months ago
by
s193396
Browse files
Options
Downloads
Patches
Plain Diff
removed unsqueeze since extra dimension is added in dataloader
parent
ed05746d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/ml/_ml_utils.py
+4
-4
4 additions, 4 deletions
qim3d/ml/_ml_utils.py
with
4 additions
and
4 deletions
qim3d/ml/_ml_utils.py
+
4
−
4
View file @
b4ea1bf3
...
...
@@ -81,7 +81,7 @@ def train_model(
for
data
in
train_loader
:
inputs
,
targets
=
data
inputs
=
inputs
.
to
(
device
)
targets
=
targets
.
to
(
device
).
unsqueeze
(
1
)
targets
=
targets
.
to
(
device
)
#
.unsqueeze(1)
optimizer
.
zero_grad
()
outputs
=
model
(
inputs
)
...
...
@@ -111,7 +111,7 @@ def train_model(
for
data
in
val_loader
:
inputs
,
targets
=
data
inputs
=
inputs
.
to
(
device
)
targets
=
targets
.
to
(
device
).
unsqueeze
(
1
)
targets
=
targets
.
to
(
device
)
#
.unsqueeze(1)
with
torch
.
no_grad
():
outputs
=
model
(
inputs
)
...
...
@@ -239,7 +239,7 @@ def inference(data: torch.utils.data.Dataset, model: torch.nn.Module) -> tuple[t
# if there is only one image
if
inputs
.
dim
()
==
2
:
inputs
=
inputs
.
unsqueeze
(
0
)
inputs
=
inputs
.
unsqueeze
(
0
)
# TODO: Not sure if unsqueeze (add extra dimension) is necessary
targets
=
targets
.
unsqueeze
(
0
)
preds
=
preds
.
unsqueeze
(
0
)
...
...
@@ -270,7 +270,7 @@ def volume_inference(volume: np.ndarray, model: torch.nn.Module, threshold:float
for
idx
in
np
.
arange
(
len
(
volume
)):
input_with_channel
=
np
.
expand_dims
(
volume
[
idx
],
axis
=
0
)
input_tensor
=
torch
.
tensor
(
input_with_channel
,
dtype
=
torch
.
float32
).
to
(
device
)
input_tensor
=
input_tensor
.
unsqueeze
(
0
)
input_tensor
=
input_tensor
.
unsqueeze
(
0
)
# TODO: Not sure if unsqueeze (add extra dimension) is necessary
output
=
model
(
input_tensor
)
>
threshold
output
=
output
.
cpu
()
if
device
==
"
cuda
"
else
output
output_detached
=
output
.
detach
()
...
...
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