Skip to content

Commit 4521414

Browse files
committed
Allow model_inspect_test to run under different tf versions.
Also fixed a few simple issues.
1 parent eb7b8b8 commit 4521414

File tree

9 files changed

+26
-21
lines changed

9 files changed

+26
-21
lines changed

efficientdet/dataset/create_coco_tfrecord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _get_caption_annotation(image_id):
339339
total_num_annotations_skipped)
340340

341341

342-
def main():
342+
def main(_):
343343
assert FLAGS.image_dir, '`image_dir` missing.'
344344
assert (FLAGS.image_info_file or FLAGS.object_annotations_file or
345345
FLAGS.caption_annotations_file), ('All annotation files are '

efficientdet/dataset/create_pascal_tfrecord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def dict_to_tf_example(data,
207207
return example
208208

209209

210-
def main():
210+
def main(_):
211211
if FLAGS.set not in SETS:
212212
raise ValueError('set must be in : {}'.format(SETS))
213213
if FLAGS.year not in YEARS:

efficientdet/g3doc/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ We have some internal fixes, which could potentially be available with the next
2626
### How can I run all tests?
2727

2828
!export PYTHONPATH="`pwd`:$PYTHONPATH"
29-
!find . -name "*_test.py" | parallel python &> test.log \
30-
&& echo "All passed" || echo "Failed! Search keyword FAILED in test.log"
29+
!find . -name "*_test.py" | parallel python &> /tmp/test.log \
30+
&& echo "All passed" || echo "Failed! Search keyword FAILED in /tmp/test.log"

efficientdet/inference.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ def export(self, output_dir, frozen_pb=True, tflite_path=None):
725725
logging.info('Free graph saved at %s', pb_path)
726726

727727
if tflite_path:
728-
print(tf.__version__)
729728
input_name = signitures['image_arrays'].op.name
730729
height, width = self.params['image_size']
731730
input_shapes = {input_name: [None, height, width, 3]}

efficientdet/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
FLAGS = flags.FLAGS
121121

122122

123-
def main():
123+
def main(_):
124124
if FLAGS.use_tpu:
125125
tpu_cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver(
126126
FLAGS.tpu,

efficientdet/model_inspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def benchmark_model(self, warmup_runs, bm_runs, num_threads,
370370
for i in range(warmup_runs):
371371
start_time = time.time()
372372
sess.run(output_name, feed_dict={input_name: img})
373-
print('Warm up: {} {:.4f}s'.format(i, time.time() - start_time))
373+
logging.info('Warm up: {} {:.4f}s'.format(i, time.time() - start_time))
374374

375375
print('Start benchmark runs total={}'.format(bm_runs))
376376
start = time.perf_counter()
@@ -448,7 +448,7 @@ def run_model(self, runmode, **kwargs):
448448
raise ValueError('Unkown runmode {}'.format(runmode))
449449

450450

451-
def main():
451+
def main(_):
452452
if tf.io.gfile.exists(FLAGS.logdir) and FLAGS.delete_logdir:
453453
logging.info('Deleting log dir ...')
454454
tf.io.gfile.rmtree(FLAGS.logdir)

efficientdet/model_inspect_test.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class ModelInspectTest(tf.test.TestCase):
3838

3939
def setUp(self):
4040
super(ModelInspectTest, self).setUp()
41-
self.tempdir = tempfile.gettempdir()
41+
sys_tempdir = tempfile.gettempdir()
42+
self.tempdir = os.path.join(sys_tempdir, '_inspect_test')
43+
os.mkdir(self.tempdir)
4244

4345
np.random.seed(111)
4446
tf.random.set_random_seed(111)
@@ -59,6 +61,10 @@ def setUp(self):
5961
batch_size=1,
6062
hparams='')
6163

64+
def tearDown(self):
65+
super(ModelInspectTest, self).tearDown()
66+
shutil.rmtree(self.tempdir)
67+
6268
def test_dry_run(self):
6369
inspector = model_inspect.ModelInspector(**self.params)
6470
inspector.run_model('dry')
@@ -88,7 +94,7 @@ def test_infer(self):
8894
self.assertTrue(os.path.exists(os.path.join(outdir, '0.jpg')))
8995

9096
out = np.sum(np.array(Image.open(os.path.join(outdir, '0.jpg'))))
91-
self.assertEqual(out, 168044958)
97+
self.assertEqual(out // 1000000, 168)
9298

9399
def test_saved_model(self):
94100
inspector = model_inspect.ModelInspector(**self.params)
@@ -126,7 +132,7 @@ def test_saved_model_infer(self):
126132
self.assertTrue(os.path.exists(os.path.join(outdir, '0.jpg')))
127133

128134
out = np.sum(np.array(Image.open(os.path.join(outdir, '0.jpg'))))
129-
self.assertEqual(out, 168044958)
135+
self.assertEqual(out // 1000000, 168)
130136

131137
def test_saved_model_infer_dynamic_batch(self):
132138
# Build saved model with dynamic batch size.
@@ -180,7 +186,7 @@ def test_saved_model_graph_infer(self):
180186
self.assertTrue(os.path.exists(os.path.join(outdir, '0.jpg')))
181187

182188
out = np.sum(np.array(Image.open(os.path.join(outdir, '0.jpg'))))
183-
self.assertEqual(out, 168044958)
189+
self.assertEqual(out // 1000000, 168)
184190

185191

186192
if __name__ == '__main__':

efficientdet/visualize/vis_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def cdf_plot(values):
956956
ax.set_xlabel('fraction of examples')
957957
fig.canvas.draw()
958958
width, height = fig.get_size_inches() * fig.get_dpi()
959-
image = np.fromstring(fig.canvas.tostring_rgb(), dtype='uint8').reshape(
959+
image = np.frombuffer(fig.canvas.tostring_rgb(), dtype='uint8').reshape(
960960
1, int(height), int(width), 3)
961961
return image
962962
cdf_plot = tf.py_func(cdf_plot, [values], tf.uint8)
@@ -984,7 +984,7 @@ def hist_plot(values, bins):
984984
ax.set_xlabel('value')
985985
fig.canvas.draw()
986986
width, height = fig.get_size_inches() * fig.get_dpi()
987-
image = np.fromstring(
987+
image = np.frombuffer(
988988
fig.canvas.tostring_rgb(), dtype='uint8').reshape(
989989
1, int(height), int(width), 3)
990990
return image

efficientdet/visualize/vis_utils_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_draw_bounding_boxes_on_image_tensors(self):
168168
min_score_thresh=0.2,
169169
keypoint_edges=keypoint_edges))
170170

171-
with self.test_session() as sess:
171+
with self.session() as sess:
172172
sess.run(tf.global_variables_initializer())
173173

174174
# Write output images for visualization.
@@ -215,7 +215,7 @@ def test_draw_bounding_boxes_on_image_tensors_with_track_ids(self):
215215
track_ids=track_ids,
216216
min_score_thresh=0.2))
217217

218-
with self.test_session() as sess:
218+
with self.session() as sess:
219219
sess.run(tf.global_variables_initializer())
220220

221221
# Write output images for visualization.
@@ -251,7 +251,7 @@ def test_draw_bounding_boxes_on_image_tensors_with_additional_channels(self):
251251
category_index,
252252
min_score_thresh=0.2))
253253

254-
with self.test_session() as sess:
254+
with self.session() as sess:
255255
sess.run(tf.global_variables_initializer())
256256

257257
final_images_np = sess.run(images_with_boxes)
@@ -280,7 +280,7 @@ def test_draw_bounding_boxes_on_image_tensors_grayscale(self):
280280
true_image_shape=image_shape,
281281
min_score_thresh=0.2))
282282

283-
with self.test_session() as sess:
283+
with self.session() as sess:
284284
sess.run(tf.global_variables_initializer())
285285

286286
final_images_np = sess.run(images_with_boxes)
@@ -336,15 +336,15 @@ def test_add_cdf_image_summary(self):
336336
values = [0.1, 0.2, 0.3, 0.4, 0.42, 0.44, 0.46, 0.48, 0.50]
337337
vis_utils.add_cdf_image_summary(values, 'PositiveAnchorLoss')
338338
cdf_image_summary = tf.get_collection(key=tf.GraphKeys.SUMMARIES)[0]
339-
with self.test_session():
339+
with self.session():
340340
cdf_image_summary.eval()
341341

342342
def test_add_hist_image_summary(self):
343343
values = [0.1, 0.2, 0.3, 0.4, 0.42, 0.44, 0.46, 0.48, 0.50]
344344
bins = [0.01 * i for i in range(101)]
345345
vis_utils.add_hist_image_summary(values, bins, 'ScoresDistribution')
346346
hist_image_summary = tf.get_collection(key=tf.GraphKeys.SUMMARIES)[0]
347-
with self.test_session():
347+
with self.session():
348348
hist_image_summary.eval()
349349

350350
def test_eval_metric_ops(self):
@@ -392,7 +392,7 @@ def test_eval_metric_ops(self):
392392
metric_ops = eval_metric_ops.get_estimator_eval_metric_ops(eval_dict)
393393
_, update_op = metric_ops[next(six.iterkeys(metric_ops))]
394394

395-
with self.test_session() as sess:
395+
with self.session() as sess:
396396
sess.run(tf.global_variables_initializer())
397397
value_ops = {}
398398
for key, (value_op, _) in six.iteritems(metric_ops):

0 commit comments

Comments
 (0)