コード例 #1
0
 def test_beam_pipeline(self):
     with InMemoryTFRecord([self._create_tf_example()]) as input_tfrecord:
         temp_dir = tempfile.mkdtemp(dir=os.environ.get('TEST_TMPDIR'))
         output_tfrecord = os.path.join(temp_dir, 'output_tfrecord')
         saved_model_path = self._export_saved_model()
         confidence_threshold = 0.8
         num_shards = 1
         pipeline_options = beam.options.pipeline_options.PipelineOptions(
             runner='DirectRunner')
         p = beam.Pipeline(options=pipeline_options)
         generate_detection_data.construct_pipeline(p, input_tfrecord,
                                                    output_tfrecord,
                                                    saved_model_path,
                                                    confidence_threshold,
                                                    num_shards)
         p.run()
         filenames = tf.io.gfile.glob(output_tfrecord + '-?????-of-?????')
         actual_output = []
         record_iterator = tf.data.TFRecordDataset(
             tf.convert_to_tensor(filenames)).as_numpy_iterator()
         for record in record_iterator:
             actual_output.append(record)
         self.assertEqual(len(actual_output), 1)
         self.assert_expected_example(
             tf.train.Example.FromString(actual_output[0]))
コード例 #2
0
 def test_beam_pipeline(self):
     with InMemoryTFRecord([self._create_tf_example()]) as input_tfrecord:
         runner = runners.DirectRunner()
         temp_dir = tempfile.mkdtemp(dir=os.environ.get('TEST_TMPDIR'))
         output_tfrecord = os.path.join(temp_dir, 'output_tfrecord')
         saved_model_path = self._export_saved_model()
         confidence_threshold = 0.8
         num_shards = 1
         pipeline = generate_detection_data.construct_pipeline(
             input_tfrecord, output_tfrecord, saved_model_path,
             confidence_threshold, num_shards)
         runner.run(pipeline)
         filenames = tf.io.gfile.glob(output_tfrecord + '-?????-of-?????')
         actual_output = []
         record_iterator = tf.python_io.tf_record_iterator(
             path=filenames[0])
         for record in record_iterator:
             actual_output.append(record)
         self.assertEqual(len(actual_output), 1)
         self.assert_expected_example(
             tf.train.Example.FromString(actual_output[0]))