Skip to content

Commit 3ab4157

Browse files
committed
Replace all tf.size with tf.shape.
tf.size is not supported by TFLite builtin.
1 parent 2b9880a commit 3ab4157

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

efficientdet/anchors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def nms_tf(dets, thresh):
130130

131131
keep = tf.TensorArray(tf.int32, size=0, dynamic_size=True)
132132
index = 0
133-
while tf.size(order) > 0:
133+
while tf.shape(order)[0] > 0:
134134
i = order[0]
135135
keep = keep.write(index, i)
136136
xx1 = tf.maximum(x1[i], tf.gather(x1, order[1:]))
@@ -334,7 +334,7 @@ def _generate_detections_tf(cls_outputs,
334334
width = boxes[:, 3] - boxes[:, 1]
335335

336336
detections = tf.stack([
337-
tf.cast(tf.tile(image_id, [tf.size(top_detection_idx)]), tf.float32),
337+
tf.cast(tf.tile(image_id, [tf.shape(top_detection_idx)[0]]), tf.float32),
338338
boxes[:, 0] * image_scale,
339339
boxes[:, 1] * image_scale,
340340
height * image_scale,

efficientdet/aug/autoaugment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def _apply_multi_bbox_augmentation(image, bboxes, prob, aug_func,
657657

658658
# If the bboxes are empty, then just give it _INVALID_BOX. The result
659659
# will be thrown away.
660-
bboxes = tf.cond(tf.equal(tf.size(bboxes), 0),
660+
bboxes = tf.cond(tf.equal(tf.shape(bboxes)[0], 0),
661661
lambda: tf.constant(_INVALID_BOX),
662662
lambda: bboxes)
663663

@@ -1352,7 +1352,7 @@ def apply_bbox_cutout(image, bboxes, pad_fraction):
13521352
return image
13531353

13541354
# Check to see if there are boxes, if so then apply boxcutout.
1355-
image = tf.cond(tf.equal(tf.size(bboxes), 0), lambda: image,
1355+
image = tf.cond(tf.equal(tf.shape(bboxes)[0], 0), lambda: image,
13561356
lambda: apply_bbox_cutout(image, bboxes, pad_fraction))
13571357

13581358
return image, bboxes

efficientdet/object_detection/matcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def matched_column_indicator(self):
9292

9393
def num_matched_columns(self):
9494
"""Returns number (int32 scalar tensor) of matched columns."""
95-
return tf.size(self.matched_column_indices())
95+
return tf.shape(self.matched_column_indices())[0]
9696

9797
def unmatched_column_indices(self):
9898
"""Returns column indices that do not match any row.
@@ -114,7 +114,7 @@ def unmatched_column_indicator(self):
114114

115115
def num_unmatched_columns(self):
116116
"""Returns number (int32 scalar tensor) of unmatched columns."""
117-
return tf.size(self.unmatched_column_indices())
117+
return tf.shape(self.unmatched_column_indices())[0]
118118

119119
def ignored_column_indices(self):
120120
"""Returns column indices that are ignored (neither Matched nor Unmatched).
@@ -137,7 +137,7 @@ def ignored_column_indicator(self):
137137

138138
def num_ignored_columns(self):
139139
"""Returns number (int32 scalar tensor) of matched columns."""
140-
return tf.size(self.ignored_column_indices())
140+
return tf.shape(self.ignored_column_indices())[0]
141141

142142
def unmatched_or_ignored_column_indices(self):
143143
"""Returns column indices that are unmatched or ignored.

efficientdet/object_detection/tf_example_decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _decode_png_mask(png_bytes):
7979
width = parsed_tensors['image/width']
8080
masks = parsed_tensors['image/object/mask']
8181
return tf.cond(
82-
tf.greater(tf.size(masks), 0),
82+
tf.greater(tf.shape(masks)[0], 0),
8383
lambda: tf.map_fn(_decode_png_mask, masks, dtype=tf.float32),
8484
lambda: tf.zeros([0, height, width], dtype=tf.float32))
8585

0 commit comments

Comments
 (0)