Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bio Volumentations
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
cbia
Bio Volumentations
Commits
a73f5bb6
There was an error fetching the commit references. Please try again later.
Commit
a73f5bb6
authored
3 weeks ago
by
Lucia D. Hradecka
Browse files
Options
Downloads
Patches
Plain Diff
refactor functional.py: remove repeated logic
parent
ac5ceb38
No related branches found
No related tags found
1 merge request
!12
Make version 1.3.2 default
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/augmentations/functional.py
+13
-29
13 additions, 29 deletions
src/augmentations/functional.py
with
13 additions
and
29 deletions
src/augmentations/functional.py
+
13
−
29
View file @
a73f5bb6
...
...
@@ -269,25 +269,6 @@ def rot90_keypoints(keypoints, factor, axes, img_shape):
return
keypoints
def
pad
(
img
,
pad_width
,
border_mode
,
cval
,
mask
=
True
):
if
not
mask
:
pad_width
=
[(
0
,
0
)]
+
pad_width
if
len
(
img
.
shape
)
>
len
(
pad_width
):
pad_width
=
pad_width
+
[(
0
,
0
)]
assert
len
(
img
.
shape
)
==
len
(
pad_width
)
if
border_mode
==
"
constant
"
:
return
np
.
pad
(
img
,
pad_width
,
border_mode
,
constant_values
=
cval
)
if
border_mode
==
"
linear_ramp
"
:
return
np
.
pad
(
img
,
pad_width
,
border_mode
,
end_values
=
cval
)
result
=
np
.
pad
(
img
,
pad_width
,
border_mode
)
return
result
def
pad_keypoints
(
keypoints
,
pad_size
):
a
,
b
,
c
,
d
,
e
,
f
=
pad_size
...
...
@@ -307,9 +288,11 @@ def pad_pixels(img, input_pad_width: TypeSextetInt, border_mode, cval, mask=Fals
pad_width
=
[(
0
,
0
)]
+
pad_width
# zeroes for temporal dimension
if
len
(
img
.
shape
)
==
5
:
if
len
(
img
.
shape
)
==
5
:
# if len(img.shape) > len(pad_width):
pad_width
=
pad_width
+
[(
0
,
0
)]
assert
len
(
img
.
shape
)
==
len
(
pad_width
)
if
border_mode
==
"
constant
"
:
return
np
.
pad
(
img
,
pad_width
,
border_mode
,
constant_values
=
cval
)
if
border_mode
==
"
linear_ramp
"
:
...
...
@@ -323,22 +306,23 @@ def get_spatial_shape(array: np.array, mask: bool) -> TypeSpatialShape:
# Used in crop()
def
get_pad_dims
(
spatial_shape
:
TypeSpatialShape
,
crop_shape
:
TypeSpatialShape
):
pad_dims
=
[
]
def
get_pad_dims
(
spatial_shape
:
TypeSpatialShape
,
crop_shape
:
TypeSpatialShape
)
->
TypeSextetInt
:
pad_dims
=
[
0
]
*
6
for
i
in
range
(
3
):
i_dim
,
c_dim
=
spatial_shape
[
i
],
crop_shape
[
i
]
current_pad_dims
=
(
0
,
0
)
if
i_dim
<
c_dim
:
pad_size
=
c_dim
-
i_dim
if
pad_size
%
2
!=
0
:
pad_dims
.
append
(
(
int
(
pad_size
//
2
+
1
),
int
(
pad_size
//
2
))
)
current_pad_dims
=
(
int
(
pad_size
//
2
+
1
),
int
(
pad_size
//
2
))
else
:
pad_dims
.
append
((
int
(
pad_size
//
2
),
int
(
pad_size
//
2
)))
else
:
pad_dims
.
append
((
0
,
0
))
return
pad_dims
current_pad_dims
=
(
int
(
pad_size
//
2
),
int
(
pad_size
//
2
))
pad_dims
[
i
*
2
:(
i
+
1
)
*
2
]
=
current_pad_dims
return
tuple
(
pad_dims
)
# Too similar to the random_crop. Could be made into one function
def
crop
(
input_array
:
np
.
array
,
crop_shape
:
TypeSpatialShape
,
crop_position
:
TypeSpatialShape
,
...
...
@@ -352,7 +336,7 @@ def crop(input_array: np.array,
UserWarning
)
# pad
input_array
=
pad
(
input_array
,
pad_dims
,
border_mode
,
cval
,
mask
)
input_array
=
pad
_pixels
(
input_array
,
pad_dims
,
border_mode
,
cval
,
mask
)
# test
input_spatial_shape
=
get_spatial_shape
(
input_array
,
mask
)
...
...
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