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
82a26070
Commit
82a26070
authored
Aug 02, 2022
by
Fan Yang
Committed by
A. Unique TensorFlower
Aug 02, 2022
Browse files
Allow dynamic batch size for batched NMS only in detection model export.
PiperOrigin-RevId: 464868859
parent
50e86708
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
official/vision/serving/detection.py
official/vision/serving/detection.py
+8
-1
official/vision/serving/detection_test.py
official/vision/serving/detection_test.py
+2
-4
No files found.
official/vision/serving/detection.py
View file @
82a26070
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
"""Detection input and model functions for serving/inference."""
"""Detection input and model functions for serving/inference."""
from
typing
import
Mapping
,
Text
from
typing
import
Mapping
,
Text
from
absl
import
logging
import
tensorflow
as
tf
import
tensorflow
as
tf
from
official.vision
import
configs
from
official.vision
import
configs
...
@@ -35,7 +37,12 @@ class DetectionModule(export_base.ExportModule):
...
@@ -35,7 +37,12 @@ class DetectionModule(export_base.ExportModule):
def
_build_model
(
self
):
def
_build_model
(
self
):
if
self
.
_batch_size
is
None
:
if
self
.
_batch_size
is
None
:
raise
ValueError
(
'batch_size cannot be None for detection models.'
)
# Only batched NMS is supported with dynamic batch size.
self
.
params
.
task
.
model
.
detection_generator
.
nms_version
=
'batched'
logging
.
info
(
'nms_version is set to `batched` because only batched NMS is '
'supported with dynamic batch size.'
)
input_specs
=
tf
.
keras
.
layers
.
InputSpec
(
shape
=
[
self
.
_batch_size
]
+
input_specs
=
tf
.
keras
.
layers
.
InputSpec
(
shape
=
[
self
.
_batch_size
]
+
self
.
_input_image_size
+
[
3
])
self
.
_input_image_size
+
[
3
])
...
...
official/vision/serving/detection_test.py
View file @
82a26070
...
@@ -124,8 +124,6 @@ class DetectionExportTest(tf.test.TestCase, parameterized.TestCase):
...
@@ -124,8 +124,6 @@ class DetectionExportTest(tf.test.TestCase, parameterized.TestCase):
def
test_build_model_fail_with_none_batch_size
(
self
):
def
test_build_model_fail_with_none_batch_size
(
self
):
params
=
exp_factory
.
get_exp_config
(
'retinanet_resnetfpn_coco'
)
params
=
exp_factory
.
get_exp_config
(
'retinanet_resnetfpn_coco'
)
with
self
.
assertRaisesRegex
(
ValueError
,
'batch_size cannot be None for detection models.'
):
detection
.
DetectionModule
(
detection
.
DetectionModule
(
params
,
batch_size
=
None
,
input_image_size
=
[
640
,
640
])
params
,
batch_size
=
None
,
input_image_size
=
[
640
,
640
])
...
...
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