Skip to content

Commit a0b82b2

Browse files
committed
remove out of date apis
1 parent e9d11f3 commit a0b82b2

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

efficientdet/backbone/efficientnet_model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from absl import logging
2727
import numpy as np
2828
import six
29-
from six.moves import xrange
3029
import tensorflow as tf
3130

3231
import utils
@@ -701,7 +700,7 @@ def _build(self):
701700
block_args = block_args._replace(
702701
input_filters=block_args.output_filters, strides=[1, 1])
703702
# pylint: enable=protected-access
704-
for _ in xrange(block_args.num_repeat - 1):
703+
for _ in range(block_args.num_repeat - 1):
705704
self._blocks.append(
706705
conv_block(block_args, self._global_params, name=block_name()))
707706

efficientdet/dataset/label_map_util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# ==============================================================================
1515
"""Label map utility functions."""
1616
from absl import logging
17-
from six.moves import range
1817

1918

2019
def _validate_label_map(label_map):

efficientdet/dataset/tfrecord_util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515
r"""TFRecord related utilities."""
16-
from six.moves import range
1716
import tensorflow as tf
1817

1918

efficientdet/visualize/shape_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515
"""Utils used to manipulate tensor shapes."""
16-
from six.moves import zip
1716
import tensorflow.compat.v1 as tf
1817

1918
from visualize import static_shape

efficientdet/visualize/vis_utils.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import PIL.ImageDraw as ImageDraw
2828
import PIL.ImageFont as ImageFont
2929
import six
30-
from six.moves import range
31-
from six.moves import zip
3230
import tensorflow.compat.v1 as tf
3331

3432
from visualize import shape_utils
@@ -105,7 +103,7 @@ def save_image_array_as_png(image, output_path):
105103
output_path: path to which image should be written.
106104
"""
107105
image_pil = Image.fromarray(np.uint8(image)).convert('RGB')
108-
with tf.gfile.Open(output_path, 'w') as fid:
106+
with tf.io.gfile.open(output_path, 'w') as fid:
109107
image_pil.save(fid, 'PNG')
110108

111109

@@ -214,7 +212,7 @@ def draw_bounding_box_on_image(image,
214212
# If the total height of the display strings added to the top of the bounding
215213
# box exceeds the top of the image, stack the strings below the bounding box
216214
# instead of above.
217-
display_str_heights = [font.getsize(ds)[1] for ds in display_str_list]
215+
display_str_heights = [font.getbbox(ds)[3] - font.getbbox(ds)[1] for ds in display_str_list]
218216
# Each display_str has a top and bottom margin of 0.05x.
219217
total_display_str_height = (1 + 2 * 0.05) * sum(display_str_heights)
220218

@@ -224,7 +222,8 @@ def draw_bounding_box_on_image(image,
224222
text_bottom = bottom + total_display_str_height
225223
# Reverse list and print from bottom to top.
226224
for display_str in display_str_list[::-1]:
227-
text_width, text_height = font.getsize(display_str)
225+
left, top, right, bottom = font.getbbox(display_str)
226+
text_width, text_height = (right - left, bottom - top)
228227
margin = np.ceil(0.05 * text_height)
229228
draw.rectangle([(left, text_bottom - text_height - 2 * margin),
230229
(left + text_width, text_bottom)],
@@ -300,9 +299,9 @@ def create_visualization_fn(category_index,
300299
include_keypoints=False,
301300
include_track_ids=False,
302301
**kwargs):
303-
"""Constructs a visualization function that can be wrapped in a py_func.
302+
"""Constructs a visualization function that can be wrapped in a numpy_function.
304303
305-
py_funcs only accept positional arguments. This function returns a suitable
304+
numpy_functions only accept positional arguments. This function returns a suitable
306305
function with the correct positional argument mapping. The positional
307306
arguments in order are:
308307
0: image
@@ -317,15 +316,15 @@ def create_visualization_fn(category_index,
317316
vis_only_masks_fn = create_visualization_fn(category_index,
318317
include_masks=True, include_keypoints=False, include_track_ids=False,
319318
**kwargs)
320-
image = tf.py_func(vis_only_masks_fn,
319+
image = tf.numpy_function(vis_only_masks_fn,
321320
inp=[image, boxes, classes, scores, masks],
322321
Tout=tf.uint8)
323322
324323
-- Example 2 --
325324
vis_masks_and_track_ids_fn = create_visualization_fn(category_index,
326325
include_masks=True, include_keypoints=False, include_track_ids=True,
327326
**kwargs)
328-
image = tf.py_func(vis_masks_and_track_ids_fn,
327+
image = tf.numpy_function(vis_masks_and_track_ids_fn,
329328
inp=[image, boxes, classes, scores, masks, track_ids],
330329
Tout=tf.uint8)
331330
@@ -346,7 +345,7 @@ def create_visualization_fn(category_index,
346345
"""
347346

348347
def visualization_py_func_fn(*args):
349-
"""Visualization function that can be wrapped in a tf.py_func.
348+
"""Visualization function that can be wrapped in a tf.numpy_function.
350349
351350
Args:
352351
*args: First 4 positional arguments must be: image - uint8 numpy array
@@ -496,11 +495,11 @@ def draw_boxes(image_and_detections):
496495
if original_image_spatial_shape is not None:
497496
image_and_detections[2] = _resize_original_image(image, original_shape)
498497

499-
image_with_boxes = tf.py_func(visualize_boxes_fn, image_and_detections[2:],
498+
image_with_boxes = tf.numpy_function(visualize_boxes_fn, image_and_detections[2:],
500499
tf.uint8)
501500
return image_with_boxes
502501

503-
images = tf.map_fn(draw_boxes, elems, dtype=tf.uint8, back_prop=False)
502+
images = tf.map_fn(draw_boxes, elems, fn_output_signature=tf.uint8, back_prop=False)
504503
return images
505504

506505

@@ -1106,8 +1105,8 @@ def image_summary_or_default_string(summary_name, image):
11061105
update_op = self.add_images([[images[0]]]) # pylint: disable=assignment-from-none
11071106
image_tensors = get_images()
11081107
else:
1109-
update_op = tf.py_func(self.add_images, [[images[0]]], [])
1110-
image_tensors = tf.py_func(get_images, [],
1108+
update_op = tf.numpy_function(self.add_images, [[images[0]]], [])
1109+
image_tensors = tf.numpy_function(get_images, [],
11111110
[tf.uint8] * self._max_examples_to_draw)
11121111
eval_metric_ops = {}
11131112
for i, image in enumerate(image_tensors):

efficientdet/visualize/vis_utils_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import numpy as np
1919
import PIL.Image as Image
2020
import six
21-
from six.moves import range
2221
import tensorflow.compat.v1 as tf
2322

2423
from visualize import standard_fields as fields

0 commit comments

Comments
 (0)