def test_beam_pipeline_bbox(self): num_frames = 1 temp_dir = tempfile.mkdtemp(dir=os.environ.get('TEST_TMPDIR')) json_path = self._create_json_file(temp_dir, num_frames, keep_bboxes=True) output_tfrecord = temp_dir + '/output' self._write_random_images_to_directory(temp_dir, num_frames) pipeline_options = beam.options.pipeline_options.PipelineOptions( runner='DirectRunner') p = beam.Pipeline(options=pipeline_options) create_cococameratraps_tfexample_main.create_pipeline( p, temp_dir, json_path, output_tfrecord_prefix=output_tfrecord, keep_bboxes=True) p.run() 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), num_frames) self.assert_expected_example_bbox( tf.train.Example.FromString(actual_output[0]))
def test_beam_pipeline(self): runner = runners.DirectRunner() num_frames = 1 temp_dir = tempfile.mkdtemp(dir=os.environ.get('TEST_TMPDIR')) json_path = self._create_json_file(temp_dir, num_frames) output_tfrecord = temp_dir + '/output' self._write_random_images_to_directory(temp_dir, num_frames) pipeline = create_cococameratraps_tfexample_main.create_pipeline( temp_dir, json_path, output_tfrecord_prefix=output_tfrecord) 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), num_frames) self.assert_expected_example( tf.train.Example.FromString(actual_output[0]))