Skip to content

Commit

Permalink
remove out of date apis
Browse files Browse the repository at this point in the history
  • Loading branch information
fsx950223 committed Sep 28, 2022
1 parent e9d11f3 commit a0b82b2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
3 changes: 1 addition & 2 deletions efficientdet/backbone/efficientnet_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from absl import logging
import numpy as np
import six
from six.moves import xrange
import tensorflow as tf

import utils
Expand Down Expand Up @@ -701,7 +700,7 @@ def _build(self):
block_args = block_args._replace(
input_filters=block_args.output_filters, strides=[1, 1])
# pylint: enable=protected-access
for _ in xrange(block_args.num_repeat - 1):
for _ in range(block_args.num_repeat - 1):
self._blocks.append(
conv_block(block_args, self._global_params, name=block_name()))

Expand Down
1 change: 0 additions & 1 deletion efficientdet/dataset/label_map_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# ==============================================================================
"""Label map utility functions."""
from absl import logging
from six.moves import range


def _validate_label_map(label_map):
Expand Down
1 change: 0 additions & 1 deletion efficientdet/dataset/tfrecord_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
# ==============================================================================
r"""TFRecord related utilities."""
from six.moves import range
import tensorflow as tf


Expand Down
1 change: 0 additions & 1 deletion efficientdet/visualize/shape_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
# ==============================================================================
"""Utils used to manipulate tensor shapes."""
from six.moves import zip
import tensorflow.compat.v1 as tf

from visualize import static_shape
Expand Down
27 changes: 13 additions & 14 deletions efficientdet/visualize/vis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import PIL.ImageDraw as ImageDraw
import PIL.ImageFont as ImageFont
import six
from six.moves import range
from six.moves import zip
import tensorflow.compat.v1 as tf

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


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

Expand All @@ -224,7 +222,8 @@ def draw_bounding_box_on_image(image,
text_bottom = bottom + total_display_str_height
# Reverse list and print from bottom to top.
for display_str in display_str_list[::-1]:
text_width, text_height = font.getsize(display_str)
left, top, right, bottom = font.getbbox(display_str)
text_width, text_height = (right - left, bottom - top)
margin = np.ceil(0.05 * text_height)
draw.rectangle([(left, text_bottom - text_height - 2 * margin),
(left + text_width, text_bottom)],
Expand Down Expand Up @@ -300,9 +299,9 @@ def create_visualization_fn(category_index,
include_keypoints=False,
include_track_ids=False,
**kwargs):
"""Constructs a visualization function that can be wrapped in a py_func.
"""Constructs a visualization function that can be wrapped in a numpy_function.
py_funcs only accept positional arguments. This function returns a suitable
numpy_functions only accept positional arguments. This function returns a suitable
function with the correct positional argument mapping. The positional
arguments in order are:
0: image
Expand All @@ -317,15 +316,15 @@ def create_visualization_fn(category_index,
vis_only_masks_fn = create_visualization_fn(category_index,
include_masks=True, include_keypoints=False, include_track_ids=False,
**kwargs)
image = tf.py_func(vis_only_masks_fn,
image = tf.numpy_function(vis_only_masks_fn,
inp=[image, boxes, classes, scores, masks],
Tout=tf.uint8)
-- Example 2 --
vis_masks_and_track_ids_fn = create_visualization_fn(category_index,
include_masks=True, include_keypoints=False, include_track_ids=True,
**kwargs)
image = tf.py_func(vis_masks_and_track_ids_fn,
image = tf.numpy_function(vis_masks_and_track_ids_fn,
inp=[image, boxes, classes, scores, masks, track_ids],
Tout=tf.uint8)
Expand All @@ -346,7 +345,7 @@ def create_visualization_fn(category_index,
"""

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

image_with_boxes = tf.py_func(visualize_boxes_fn, image_and_detections[2:],
image_with_boxes = tf.numpy_function(visualize_boxes_fn, image_and_detections[2:],
tf.uint8)
return image_with_boxes

images = tf.map_fn(draw_boxes, elems, dtype=tf.uint8, back_prop=False)
images = tf.map_fn(draw_boxes, elems, fn_output_signature=tf.uint8, back_prop=False)
return images


Expand Down Expand Up @@ -1106,8 +1105,8 @@ def image_summary_or_default_string(summary_name, image):
update_op = self.add_images([[images[0]]]) # pylint: disable=assignment-from-none
image_tensors = get_images()
else:
update_op = tf.py_func(self.add_images, [[images[0]]], [])
image_tensors = tf.py_func(get_images, [],
update_op = tf.numpy_function(self.add_images, [[images[0]]], [])
image_tensors = tf.numpy_function(get_images, [],
[tf.uint8] * self._max_examples_to_draw)
eval_metric_ops = {}
for i, image in enumerate(image_tensors):
Expand Down
1 change: 0 additions & 1 deletion efficientdet/visualize/vis_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import numpy as np
import PIL.Image as Image
import six
from six.moves import range
import tensorflow.compat.v1 as tf

from visualize import standard_fields as fields
Expand Down

0 comments on commit a0b82b2

Please sign in to comment.