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
ac6a7a44
Commit
ac6a7a44
authored
2 months ago
by
s193396
Browse files
Options
Downloads
Patches
Plain Diff
dimensions as tuple instead of unpacked
parent
d0b1d98a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
qim3d/ml/_augmentations.py
+9
-4
9 additions, 4 deletions
qim3d/ml/_augmentations.py
qim3d/ml/_data.py
+3
-3
3 additions, 3 deletions
qim3d/ml/_data.py
with
12 additions
and
7 deletions
qim3d/ml/_augmentations.py
+
9
−
4
View file @
ac6a7a44
...
...
@@ -41,14 +41,12 @@ class Augmentation:
self
.
transform_test
=
transform_test
self
.
is_3d
=
is_3d
def
augment
(
self
,
im
_h
:
int
,
im_w
:
int
,
im_d
:
int
|
None
=
Non
e
,
level
:
str
|
None
=
None
):
def
augment
(
self
,
im
g_shape
:
tupl
e
,
level
:
str
|
None
=
None
):
"""
Creates an augmentation pipeline based on the specified level.
Args:
im_h (int): Height of the image.
im_w (int): Width of the image.
im_d (int, optional): Depth of the image (for 3D).
img_shape (tuple): Dimensions of the image.
level (str, optional): Level of augmentation. One of [None,
'
light
'
,
'
moderate
'
,
'
heavy
'
].
Raises:
...
...
@@ -59,6 +57,13 @@ class Augmentation:
RandGaussianSmooth
,
NormalizeIntensity
,
Resize
,
CenterSpatialCrop
,
SpatialPad
)
# Check if 2D or 3D
if
len
(
img_shape
)
==
2
:
im_h
,
im_w
=
img_shape
elif
len
(
img_shape
)
==
3
:
im_d
,
im_h
,
im_w
=
img_shape
# Check if one of standard augmentation levels
if
level
not
in
[
None
,
'
light
'
,
'
moderate
'
,
'
heavy
'
]:
raise
ValueError
(
f
"
Invalid transformation level:
{
level
}
. Please choose one of the following levels: None,
'
light
'
,
'
moderate
'
,
'
heavy
'
.
"
)
...
...
This diff is collapsed.
Click to expand it.
qim3d/ml/_data.py
+
3
−
3
View file @
ac6a7a44
...
...
@@ -271,9 +271,9 @@ def prepare_datasets(path: str, val_fraction: float, model: nn.Module, augmentat
final_shape
=
check_resize
(
orig_shape
,
resize
,
n_channels
,
is_3d
)
train_set
=
Dataset
(
root_path
=
path
,
transform
=
augmentation
.
augment
(
*
final_shape
,
level
=
augmentation
.
transform_train
))
val_set
=
Dataset
(
root_path
=
path
,
transform
=
augmentation
.
augment
(
*
final_shape
,
level
=
augmentation
.
transform_validation
))
test_set
=
Dataset
(
root_path
=
path
,
split
=
'
test
'
,
transform
=
augmentation
.
augment
(
*
final_shape
,
level
=
augmentation
.
transform_test
))
train_set
=
Dataset
(
root_path
=
path
,
transform
=
augmentation
.
augment
(
final_shape
,
level
=
augmentation
.
transform_train
))
val_set
=
Dataset
(
root_path
=
path
,
transform
=
augmentation
.
augment
(
final_shape
,
level
=
augmentation
.
transform_validation
))
test_set
=
Dataset
(
root_path
=
path
,
split
=
'
test
'
,
transform
=
augmentation
.
augment
(
final_shape
,
level
=
augmentation
.
transform_test
))
split_idx
=
int
(
np
.
floor
(
val_fraction
*
len
(
train_set
)))
indices
=
torch
.
randperm
(
len
(
train_set
))
...
...
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