Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
bf03f4ed
"...text-generation-inference.git" did not exist on "f59fb8b630844c2ad2cd80e689202de89d45c37e"
Unverified
Commit
bf03f4ed
authored
Aug 04, 2023
by
Philip Meier
Committed by
GitHub
Aug 04, 2023
Browse files
cleanup spatial_size -> canvas_size (#7783)
parent
9ebf10af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
+16
-16
test/common_utils.py
test/common_utils.py
+15
-15
test/test_transforms_v2_functional.py
test/test_transforms_v2_functional.py
+1
-1
No files found.
test/common_utils.py
View file @
bf03f4ed
...
@@ -423,7 +423,7 @@ DEFAULT_SPATIAL_SIZES = (
...
@@ -423,7 +423,7 @@ DEFAULT_SPATIAL_SIZES = (
)
)
def
_parse_
canvas_
size
(
size
,
*
,
name
=
"size"
):
def
_parse_size
(
size
,
*
,
name
=
"size"
):
if
size
==
"random"
:
if
size
==
"random"
:
raise
ValueError
(
"This should never happen"
)
raise
ValueError
(
"This should never happen"
)
elif
isinstance
(
size
,
int
)
and
size
>
0
:
elif
isinstance
(
size
,
int
)
and
size
>
0
:
...
@@ -478,13 +478,13 @@ class TensorLoader:
...
@@ -478,13 +478,13 @@ class TensorLoader:
@
dataclasses
.
dataclass
@
dataclasses
.
dataclass
class
ImageLoader
(
TensorLoader
):
class
ImageLoader
(
TensorLoader
):
canvas
_size
:
Tuple
[
int
,
int
]
=
dataclasses
.
field
(
init
=
False
)
spatial
_size
:
Tuple
[
int
,
int
]
=
dataclasses
.
field
(
init
=
False
)
num_channels
:
int
=
dataclasses
.
field
(
init
=
False
)
num_channels
:
int
=
dataclasses
.
field
(
init
=
False
)
memory_format
:
torch
.
memory_format
=
torch
.
contiguous_format
memory_format
:
torch
.
memory_format
=
torch
.
contiguous_format
canvas_size
:
Tuple
[
int
,
int
]
=
dataclasses
.
field
(
init
=
False
)
canvas_size
:
Tuple
[
int
,
int
]
=
dataclasses
.
field
(
init
=
False
)
def
__post_init__
(
self
):
def
__post_init__
(
self
):
self
.
canvas
_size
=
self
.
canvas_size
=
self
.
shape
[
-
2
:]
self
.
spatial
_size
=
self
.
canvas_size
=
self
.
shape
[
-
2
:]
self
.
num_channels
=
self
.
shape
[
-
3
]
self
.
num_channels
=
self
.
shape
[
-
3
]
def
load
(
self
,
device
):
def
load
(
self
,
device
):
...
@@ -550,7 +550,7 @@ def make_image_loader(
...
@@ -550,7 +550,7 @@ def make_image_loader(
):
):
if
not
constant_alpha
:
if
not
constant_alpha
:
raise
ValueError
(
"This should never happen"
)
raise
ValueError
(
"This should never happen"
)
size
=
_parse_
canvas_
size
(
size
)
size
=
_parse_size
(
size
)
num_channels
=
get_num_channels
(
color_space
)
num_channels
=
get_num_channels
(
color_space
)
def
fn
(
shape
,
dtype
,
device
,
memory_format
):
def
fn
(
shape
,
dtype
,
device
,
memory_format
):
...
@@ -590,7 +590,7 @@ make_images = from_loaders(make_image_loaders)
...
@@ -590,7 +590,7 @@ make_images = from_loaders(make_image_loaders)
def
make_image_loader_for_interpolation
(
def
make_image_loader_for_interpolation
(
size
=
(
233
,
147
),
*
,
color_space
=
"RGB"
,
dtype
=
torch
.
uint8
,
memory_format
=
torch
.
contiguous_format
size
=
(
233
,
147
),
*
,
color_space
=
"RGB"
,
dtype
=
torch
.
uint8
,
memory_format
=
torch
.
contiguous_format
):
):
size
=
_parse_
canvas_
size
(
size
)
size
=
_parse_size
(
size
)
num_channels
=
get_num_channels
(
color_space
)
num_channels
=
get_num_channels
(
color_space
)
def
fn
(
shape
,
dtype
,
device
,
memory_format
):
def
fn
(
shape
,
dtype
,
device
,
memory_format
):
...
@@ -687,11 +687,11 @@ def make_bounding_box(
...
@@ -687,11 +687,11 @@ def make_bounding_box(
)
)
def
make_bounding_box_loader
(
*
,
extra_dims
=
(),
format
,
canvas
_size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
dtype
=
torch
.
float32
):
def
make_bounding_box_loader
(
*
,
extra_dims
=
(),
format
,
spatial
_size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
dtype
=
torch
.
float32
):
if
isinstance
(
format
,
str
):
if
isinstance
(
format
,
str
):
format
=
datapoints
.
BoundingBoxFormat
[
format
]
format
=
datapoints
.
BoundingBoxFormat
[
format
]
canvas
_size
=
_parse_
canvas_size
(
canvas
_size
,
name
=
"canvas_size"
)
spatial
_size
=
_parse_
size
(
spatial
_size
,
name
=
"canvas_size"
)
def
fn
(
shape
,
dtype
,
device
):
def
fn
(
shape
,
dtype
,
device
):
*
batch_dims
,
num_coordinates
=
shape
*
batch_dims
,
num_coordinates
=
shape
...
@@ -699,21 +699,21 @@ def make_bounding_box_loader(*, extra_dims=(), format, canvas_size=DEFAULT_PORTR
...
@@ -699,21 +699,21 @@ def make_bounding_box_loader(*, extra_dims=(), format, canvas_size=DEFAULT_PORTR
raise
pytest
.
UsageError
()
raise
pytest
.
UsageError
()
return
make_bounding_box
(
return
make_bounding_box
(
format
=
format
,
canvas_size
=
canvas
_size
,
batch_dims
=
batch_dims
,
dtype
=
dtype
,
device
=
device
format
=
format
,
canvas_size
=
spatial
_size
,
batch_dims
=
batch_dims
,
dtype
=
dtype
,
device
=
device
)
)
return
BoundingBoxesLoader
(
fn
,
shape
=
(
*
extra_dims
,
4
),
dtype
=
dtype
,
format
=
format
,
spatial_size
=
canvas
_size
)
return
BoundingBoxesLoader
(
fn
,
shape
=
(
*
extra_dims
,
4
),
dtype
=
dtype
,
format
=
format
,
spatial_size
=
spatial
_size
)
def
make_bounding_box_loaders
(
def
make_bounding_box_loaders
(
*
,
*
,
extra_dims
=
DEFAULT_EXTRA_DIMS
,
extra_dims
=
DEFAULT_EXTRA_DIMS
,
formats
=
tuple
(
datapoints
.
BoundingBoxFormat
),
formats
=
tuple
(
datapoints
.
BoundingBoxFormat
),
canvas
_size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
spatial
_size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
dtypes
=
(
torch
.
float32
,
torch
.
float64
,
torch
.
int64
),
dtypes
=
(
torch
.
float32
,
torch
.
float64
,
torch
.
int64
),
):
):
for
params
in
combinations_grid
(
extra_dims
=
extra_dims
,
format
=
formats
,
dtype
=
dtypes
):
for
params
in
combinations_grid
(
extra_dims
=
extra_dims
,
format
=
formats
,
dtype
=
dtypes
):
yield
make_bounding_box_loader
(
**
params
,
canvas_size
=
canvas
_size
)
yield
make_bounding_box_loader
(
**
params
,
spatial_size
=
spatial
_size
)
make_bounding_boxes
=
from_loaders
(
make_bounding_box_loaders
)
make_bounding_boxes
=
from_loaders
(
make_bounding_box_loaders
)
...
@@ -738,7 +738,7 @@ def make_detection_mask(size=DEFAULT_SIZE, *, num_objects=5, batch_dims=(), dtyp
...
@@ -738,7 +738,7 @@ def make_detection_mask(size=DEFAULT_SIZE, *, num_objects=5, batch_dims=(), dtyp
def
make_detection_mask_loader
(
size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
*
,
num_objects
=
5
,
extra_dims
=
(),
dtype
=
torch
.
uint8
):
def
make_detection_mask_loader
(
size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
*
,
num_objects
=
5
,
extra_dims
=
(),
dtype
=
torch
.
uint8
):
# This produces "detection" masks, i.e. `(*, N, H, W)`, where `N` denotes the number of objects
# This produces "detection" masks, i.e. `(*, N, H, W)`, where `N` denotes the number of objects
size
=
_parse_
canvas_
size
(
size
)
size
=
_parse_size
(
size
)
def
fn
(
shape
,
dtype
,
device
):
def
fn
(
shape
,
dtype
,
device
):
*
batch_dims
,
num_objects
,
height
,
width
=
shape
*
batch_dims
,
num_objects
,
height
,
width
=
shape
...
@@ -779,7 +779,7 @@ def make_segmentation_mask_loader(
...
@@ -779,7 +779,7 @@ def make_segmentation_mask_loader(
size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
*
,
num_categories
=
10
,
extra_dims
=
(),
dtype
=
torch
.
uint8
size
=
DEFAULT_PORTRAIT_SPATIAL_SIZE
,
*
,
num_categories
=
10
,
extra_dims
=
(),
dtype
=
torch
.
uint8
):
):
# This produces "segmentation" masks, i.e. `(*, H, W)`, where the category is encoded in the values
# This produces "segmentation" masks, i.e. `(*, H, W)`, where the category is encoded in the values
canvas_
size
=
_parse_
canvas_
size
(
size
)
size
=
_parse_size
(
size
)
def
fn
(
shape
,
dtype
,
device
):
def
fn
(
shape
,
dtype
,
device
):
*
batch_dims
,
height
,
width
=
shape
*
batch_dims
,
height
,
width
=
shape
...
@@ -787,7 +787,7 @@ def make_segmentation_mask_loader(
...
@@ -787,7 +787,7 @@ def make_segmentation_mask_loader(
(
height
,
width
),
num_categories
=
num_categories
,
batch_dims
=
batch_dims
,
dtype
=
dtype
,
device
=
device
(
height
,
width
),
num_categories
=
num_categories
,
batch_dims
=
batch_dims
,
dtype
=
dtype
,
device
=
device
)
)
return
MaskLoader
(
fn
,
shape
=
(
*
extra_dims
,
*
canvas_
size
),
dtype
=
dtype
)
return
MaskLoader
(
fn
,
shape
=
(
*
extra_dims
,
*
size
),
dtype
=
dtype
)
def
make_segmentation_mask_loaders
(
def
make_segmentation_mask_loaders
(
...
@@ -841,7 +841,7 @@ def make_video_loader(
...
@@ -841,7 +841,7 @@ def make_video_loader(
extra_dims
=
(),
extra_dims
=
(),
dtype
=
torch
.
uint8
,
dtype
=
torch
.
uint8
,
):
):
size
=
_parse_
canvas_
size
(
size
)
size
=
_parse_size
(
size
)
def
fn
(
shape
,
dtype
,
device
,
memory_format
):
def
fn
(
shape
,
dtype
,
device
,
memory_format
):
*
batch_dims
,
num_frames
,
_
,
height
,
width
=
shape
*
batch_dims
,
num_frames
,
_
,
height
,
width
=
shape
...
...
test/test_transforms_v2_functional.py
View file @
bf03f4ed
...
@@ -884,7 +884,7 @@ def test_correctness_perspective_bounding_boxes(device, startpoints, endpoints):
...
@@ -884,7 +884,7 @@ def test_correctness_perspective_bounding_boxes(device, startpoints, endpoints):
pcoeffs
=
_get_perspective_coeffs
(
startpoints
,
endpoints
)
pcoeffs
=
_get_perspective_coeffs
(
startpoints
,
endpoints
)
inv_pcoeffs
=
_get_perspective_coeffs
(
endpoints
,
startpoints
)
inv_pcoeffs
=
_get_perspective_coeffs
(
endpoints
,
startpoints
)
for
bboxes
in
make_bounding_boxes
(
canvas
_size
=
canvas_size
,
extra_dims
=
((
4
,),)):
for
bboxes
in
make_bounding_boxes
(
spatial
_size
=
canvas_size
,
extra_dims
=
((
4
,),)):
bboxes
=
bboxes
.
to
(
device
)
bboxes
=
bboxes
.
to
(
device
)
output_bboxes
=
F
.
perspective_bounding_boxes
(
output_bboxes
=
F
.
perspective_bounding_boxes
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment