예제 #1
0
 def test_saved_model_fp16(self):
   self.params['hparams'] = 'mixed_precision=true'
   inspector = model_inspect.ModelInspector(**self.params)
   inspector.run_model('saved_model')
   self.assertTrue(
       os.path.exists(os.path.join(self.savedmodel_dir, 'saved_model.pb')))
   utils.set_precision_policy('float32')
    def test_saved_model_infer_dynamic_batch(self):
        # Build saved model with dynamic batch size.
        self.params['batch_size'] = None
        inspector = model_inspect.ModelInspector(**self.params)
        inspector.run_model('saved_model')

        outdir = os.path.join(self.tempdir, 'infer_imgout_dyn')
        os.mkdir(outdir)

        img_path = os.path.join(self.tempdir, 'img.jpg')
        Image.fromarray(self.test_image).save(img_path)
        test_image2 = np.random.randint(0, 244, (640, 320, 3)).astype(np.uint8)
        img2_path = os.path.join(self.tempdir, 'img2.jpg')
        Image.fromarray(test_image2).save(img2_path)

        # serve images with batch size 1.
        tf.reset_default_graph()
        self.params['batch_size'] = 1
        self.assertFalse(os.path.exists(os.path.join(outdir, '0.jpg')))
        inspector.run_model('saved_model_infer',
                            input_image=img_path,
                            output_image_dir=outdir)
        self.assertTrue(os.path.exists(os.path.join(outdir, '0.jpg')))

        # serve images with batch size 2.
        tf.reset_default_graph()
        self.params['batch_size'] = 2
        self.assertFalse(os.path.exists(os.path.join(outdir, '1.jpg')))
        fname = img_path.replace('img.jpg', 'img*.jpg')
        inspector.run_model('saved_model_infer',
                            input_image=fname,
                            output_image_dir=outdir)
        self.assertTrue(os.path.exists(os.path.join(outdir, '1.jpg')))
 def test_saved_model(self):
   inspector = model_inspect.ModelInspector(**self.params)
   self.assertFalse(
       os.path.exists(os.path.join(self.savedmodel_dir, 'saved_model.pb')))
   inspector.run_model('saved_model')
   self.assertTrue(
       os.path.exists(os.path.join(self.savedmodel_dir, 'saved_model.pb')))
   self.assertTrue(
       os.path.exists(
           os.path.join(self.savedmodel_dir, 'efficientdet-d0_frozen.pb')))
예제 #4
0
  def test_infer(self):
    outdir = os.path.join(self.tempdir, 'infer_imgout')
    os.mkdir(outdir)
    inspector = model_inspect.ModelInspector(**self.params)

    img_path = os.path.join(self.tempdir, 'img.jpg')
    Image.fromarray(self.test_image).save(img_path)

    self.assertFalse(os.path.exists(os.path.join(outdir, '0.jpg')))
    inspector.run_model('infer', input_image=img_path, output_image_dir=outdir)
    self.assertTrue(os.path.exists(os.path.join(outdir, '0.jpg')))

    out = np.sum(np.array(Image.open(os.path.join(outdir, '0.jpg'))))
    self.assertEqual(out // 10000000, 16)
예제 #5
0
 def test_saved_model(self):
   if tf.__version__ >= '2.3.0-dev20200521':
     self.params['tflite_path'] = os.path.join(self.savedmodel_dir, 'x.tflite')
   inspector = model_inspect.ModelInspector(**self.params)
   self.assertFalse(
       os.path.exists(os.path.join(self.savedmodel_dir, 'saved_model.pb')))
   inspector.run_model('saved_model')
   self.assertTrue(
       os.path.exists(os.path.join(self.savedmodel_dir, 'saved_model.pb')))
   self.assertTrue(
       os.path.exists(
           os.path.join(self.savedmodel_dir, 'efficientdet-d0_frozen.pb')))
   if self.params.get('tflite_path', None):
     self.assertTrue(
         os.path.exists(os.path.join(self.savedmodel_dir, 'x.tflite')))
예제 #6
0
  def test_saved_model_graph_infer(self):
    inspector = model_inspect.ModelInspector(**self.params)
    inspector.run_model('saved_model')
    tf.reset_default_graph()

    # Use the frozen graph to do inference.
    inspector.saved_model_dir = os.path.join(self.params['saved_model_dir'],
                                             'efficientdet-d0_frozen.pb')
    outdir = os.path.join(self.tempdir, 'pb_infer_imgout')
    os.mkdir(outdir)

    img_path = os.path.join(self.tempdir, 'img.jpg')
    Image.fromarray(self.test_image).save(img_path)

    self.assertFalse(os.path.exists(os.path.join(outdir, '0.jpg')))
    inspector.run_model(
        'saved_model_infer', input_image=img_path, output_image_dir=outdir)
    self.assertTrue(os.path.exists(os.path.join(outdir, '0.jpg')))

    out = np.sum(np.array(Image.open(os.path.join(outdir, '0.jpg'))))
    self.assertEqual(out // 10000000, 16)
 def test_eval_ckpt(self):
     inspector = model_inspect.ModelInspector(**self.params)
     inspector.run_model('ckpt')
 def test_bm(self):
     inspector = model_inspect.ModelInspector(**self.params)
     inspector.run_model('bm')
 def test_freeze_model(self):
     inspector = model_inspect.ModelInspector(**self.params)
     inspector.run_model('freeze')
 def test_dry_run(self):
     inspector = model_inspect.ModelInspector(**self.params)
     inspector.run_model('dry')
예제 #11
0
import random
import os
import tensorflow.compat.v1 as tf
import numpy as np
import itertools
import model_inspect

from waymo_open_dataset.utils import range_image_utils
from waymo_open_dataset.utils import transform_utils
from waymo_open_dataset.utils import frame_utils

from waymo_open_dataset import dataset_pb2
from waymo_open_dataset import label_pb2
from waymo_open_dataset.protos import metrics_pb2

inspector = model_inspect.ModelInspector('efficientdet-d0', 'logdir')
filepath = '/mnt/pool0-100/shape-it/validation_data/segment-14486517341017504003_3406_349_3426_349_with_camera_labels.tfrecord'
dataset = tf.data.TFRecordDataset(filepath, compression_type='')

numFrames = 0
config_dict = {}
config_dict['line_thickness'] = 3
config_dict['max_boxes_to_draw'] = 15
config_dict['min_score_thresh'] = 0.5
for data in dataset:
    if numFrames >= 3:
        break
    numFrames = numFrames + 1
    frame = dataset_pb2.Frame()
    frame.ParseFromString(bytearray(data.numpy()))
    numImages = 0