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
ModelZoo
ResNet50_tensorflow
Commits
bcd5283d
".github/git@developer.sourcefind.cn:wangsen/mineru.git" did not exist on "d8996b652f8b731a092187c8014c62441d2d9dcf"
Commit
bcd5283d
authored
Sep 23, 2021
by
Vishnu Banna
Browse files
non square mosaic update
parent
e2120dc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
20 deletions
+21
-20
official/vision/beta/projects/yolo/ops/mosaic.py
official/vision/beta/projects/yolo/ops/mosaic.py
+21
-20
No files found.
official/vision/beta/projects/yolo/ops/mosaic.py
View file @
bcd5283d
...
@@ -17,7 +17,7 @@ import random
...
@@ -17,7 +17,7 @@ import random
import
tensorflow
as
tf
import
tensorflow
as
tf
import
tensorflow_addons
as
tfa
import
tensorflow_addons
as
tfa
from
official.vision.beta.projects.
yolo.ops
import
preprocessing_ops
from
yolo.ops
import
preprocessing_ops
from
official.vision.beta.ops
import
box_ops
from
official.vision.beta.ops
import
box_ops
from
official.vision.beta.ops
import
preprocess_ops
from
official.vision.beta.ops
import
preprocess_ops
...
@@ -111,15 +111,31 @@ class Mosaic:
...
@@ -111,15 +111,31 @@ class Mosaic:
self
.
_output_size
[
0
]
*
min_offset
,
self
.
_output_size
[
0
]
*
min_offset
,
self
.
_output_size
[
0
]
*
(
1
-
min_offset
),
self
.
_output_size
[
0
]
*
(
1
-
min_offset
),
seed
=
self
.
_seed
)
seed
=
self
.
_seed
)
cut
=
[
cut_
x
,
cut_
y
]
cut
=
[
cut_
y
,
cut_
x
]
ishape
=
tf
.
convert_to_tensor
(
ishape
=
tf
.
convert_to_tensor
(
[
self
.
_output_size
[
1
],
self
.
_output_size
[
0
],
3
])
[
self
.
_output_size
[
0
],
self
.
_output_size
[
1
],
3
])
else
:
else
:
cut
=
None
cut
=
None
ishape
=
tf
.
convert_to_tensor
(
ishape
=
tf
.
convert_to_tensor
(
[
self
.
_output_size
[
1
]
*
2
,
self
.
_output_size
[
0
]
*
2
,
3
])
[
self
.
_output_size
[
0
]
*
2
,
self
.
_output_size
[
1
]
*
2
,
3
])
return
cut
,
ishape
return
cut
,
ishape
def
scale_boxes
(
self
,
patch
,
ishape
,
boxes
,
classes
,
xs
,
ys
):
"""Scale and translate the boxes for each image prior to patching."""
xs
=
tf
.
cast
(
xs
,
boxes
.
dtype
)
ys
=
tf
.
cast
(
ys
,
boxes
.
dtype
)
pshape
=
tf
.
cast
(
tf
.
shape
(
patch
),
boxes
.
dtype
)
ishape
=
tf
.
cast
(
ishape
,
boxes
.
dtype
)
translate
=
tf
.
cast
((
ishape
-
pshape
),
boxes
.
dtype
)
boxes
=
box_ops
.
denormalize_boxes
(
boxes
,
pshape
[:
2
])
boxes
=
boxes
+
tf
.
cast
([
translate
[
0
]
*
ys
,
translate
[
1
]
*
xs
,
translate
[
0
]
*
ys
,
translate
[
1
]
*
xs
],
boxes
.
dtype
)
boxes
=
box_ops
.
normalize_boxes
(
boxes
,
ishape
[:
2
])
return
boxes
,
classes
def
_select_ind
(
self
,
inds
,
*
args
):
def
_select_ind
(
self
,
inds
,
*
args
):
items
=
[]
items
=
[]
for
item
in
args
:
for
item
in
args
:
...
@@ -210,22 +226,6 @@ class Mosaic:
...
@@ -210,22 +226,6 @@ class Mosaic:
classes
,
is_crowd
,
area
=
self
.
_select_ind
(
inds
,
classes
,
is_crowd
,
area
)
classes
,
is_crowd
,
area
=
self
.
_select_ind
(
inds
,
classes
,
is_crowd
,
area
)
return
image
,
boxes
,
classes
,
is_crowd
,
area
,
area
return
image
,
boxes
,
classes
,
is_crowd
,
area
,
area
def
scale_boxes
(
self
,
patch
,
ishape
,
boxes
,
classes
,
xs
,
ys
):
"""Scale and translate the boxes for each image prior to patching."""
xs
=
tf
.
cast
(
xs
,
boxes
.
dtype
)
ys
=
tf
.
cast
(
ys
,
boxes
.
dtype
)
pshape
=
tf
.
cast
(
tf
.
shape
(
patch
),
boxes
.
dtype
)
ishape
=
tf
.
cast
(
ishape
,
boxes
.
dtype
)
translate
=
tf
.
cast
((
ishape
-
pshape
),
boxes
.
dtype
)
boxes
=
box_ops
.
denormalize_boxes
(
boxes
,
pshape
[:
2
])
boxes
=
boxes
+
tf
.
cast
([
translate
[
0
]
*
ys
,
translate
[
1
]
*
xs
,
translate
[
0
]
*
ys
,
translate
[
1
]
*
xs
],
boxes
.
dtype
)
boxes
=
box_ops
.
normalize_boxes
(
boxes
,
ishape
[:
2
])
return
boxes
,
classes
# mosaic full frequency doubles model speed
# mosaic full frequency doubles model speed
def
_process_image
(
self
,
sample
,
shiftx
,
shifty
,
cut
,
ishape
):
def
_process_image
(
self
,
sample
,
shiftx
,
shifty
,
cut
,
ishape
):
"""Process and augment each image."""
"""Process and augment each image."""
...
@@ -396,3 +396,4 @@ class Mosaic:
...
@@ -396,3 +396,4 @@ class Mosaic:
return
self
.
_apply
return
self
.
_apply
else
:
else
:
return
self
.
_skip
return
self
.
_skip
\ No newline at end of file
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