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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
c5e81efe
Commit
c5e81efe
authored
Jul 7, 2023
by
ofhkr
Browse files
Options
Downloads
Patches
Plain Diff
UNet Data Augmentation Tool
parent
d82d3a48
No related branches found
No related tags found
1 merge request
!5
UNet Data Augmentation Tool
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/notebooks/Unet.ipynb
+34
-43
34 additions, 43 deletions
docs/notebooks/Unet.ipynb
qim3d/utils/__init__.py
+1
-0
1 addition, 0 deletions
qim3d/utils/__init__.py
qim3d/utils/augmentations.py
+87
-0
87 additions, 0 deletions
qim3d/utils/augmentations.py
with
122 additions
and
43 deletions
docs/notebooks/Unet.ipynb
+
34
−
43
View file @
c5e81efe
This diff is collapsed.
Click to expand it.
qim3d/utils/__init__.py
+
1
−
0
View file @
c5e81efe
from
.
import
internal_tools
from
.
import
internal_tools
from
.
import
models
from
.
import
models
from
.augmentations
import
Augmentation
from
.data
import
Dataset
from
.data
import
Dataset
\ No newline at end of file
This diff is collapsed.
Click to expand it.
qim3d/utils/augmentations.py
0 → 100644
+
87
−
0
View file @
c5e81efe
"""
Class for choosing or customizing data augmentations with albumentations
"""
import
albumentations
as
A
from
albumentations.pytorch
import
ToTensorV2
class
Augmentation
:
"""
Class for defining image augmentation transformations using Albumentations library.
Raises:
ValueError: If the provided level is neither None,
'
light
'
,
'
moderate
'
,
'
heavy
'
, nor a custom augmentation.
Attributes:
resize (int): The target size to resize the image.
mean (float): The mean value for normalizing pixel intensities.
std (float): The standard deviation value for normalizing pixel intensities.
Methods:
augment(level=None): Apply image augmentation transformations based on the specified level, or on a
custom albumentations augmentation. The available levels are None,
'
light
'
,
'
moderate
'
, and
'
heavy
'
.
Usage:
my_augmentation = Augmentation()
moderate_augment = augmentation.augment(level=
'
moderate
'
)
"""
def
__init__
(
self
,
resize
=
256
,
mean
=
0.5
,
std
=
0.5
):
self
.
resize
=
resize
self
.
mean
=
mean
self
.
std
=
std
def
augment
(
self
,
level
=
None
):
# Check if one of standard augmentation levels
if
level
not
in
[
None
,
'
light
'
,
'
moderate
'
,
'
heavy
'
]:
# Check if the custom transformation is an albumentation:
if
not
isinstance
(
level
,
A
.
core
.
composition
.
Compose
):
raise
ValueError
(
"
Custom Transformations need to be an instance of Albumentations Compose class,
"
"
or one of the following levels: None,
'
light
'
,
'
moderate
'
,
'
heavy
'"
)
# Custom transformation
else
:
return
level
# Default transformation
elif
level
is
None
:
augment
=
A
.
Compose
([
A
.
Resize
(
self
.
resize
,
self
.
resize
),
A
.
Normalize
(
mean
=
(
self
.
mean
),
std
=
(
self
.
std
)),
ToTensorV2
()
])
# Choosing light augmentation
elif
level
==
'
light
'
:
augment
=
A
.
Compose
([
A
.
Resize
(
self
.
resize
,
self
.
resize
),
A
.
RandomRotate90
(),
A
.
Normalize
(
mean
=
(
self
.
mean
),
std
=
(
self
.
std
)),
ToTensorV2
()
])
# Choosing moderate augmentation
elif
level
==
'
moderate
'
:
augment
=
A
.
Compose
([
A
.
Resize
(
self
.
resize
,
self
.
resize
),
A
.
RandomRotate90
(),
A
.
HorizontalFlip
(
p
=
0.3
),
A
.
VerticalFlip
(
p
=
0.3
),
A
.
GlassBlur
(
sigma
=
0.7
,
p
=
0.1
),
A
.
Affine
(
scale
=
[
0.8
,
1.2
],
translate_percent
=
(
0.1
,
0.1
)),
A
.
Normalize
(
mean
=
(
self
.
mean
),
std
=
(
self
.
std
)),
ToTensorV2
()
])
# Choosing heavy augmentation
elif
level
==
'
heavy
'
:
augment
=
A
.
Compose
([
A
.
Resize
(
self
.
resize
,
self
.
resize
),
A
.
RandomRotate90
(),
A
.
HorizontalFlip
(
p
=
0.7
),
A
.
VerticalFlip
(
p
=
0.7
),
A
.
GlassBlur
(
sigma
=
1.2
,
iterations
=
2
,
p
=
0.3
),
A
.
Affine
(
scale
=
[
0.8
,
1.4
],
translate_percent
=
(
0.2
,
0.2
),
shear
=
(
-
15
,
15
)),
A
.
Normalize
(
mean
=
(
self
.
mean
),
std
=
(
self
.
std
)),
ToTensorV2
()
])
return
augment
\ No newline at end of file
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