コード例 #1
0
    def test_image_no_detection(self):
        image = load_image(IMAGE_NO_DETECTION_PATH)

        detected_image, classes = detect(self.tf_sess, image)

        self.assertEqual((375, 500, 3), detected_image.shape)
        self.assertListEqual([], sorted(classes))
コード例 #2
0
    def test_image_4k_detection(self):
        image = load_image(IMAGE_4K_PATH)

        detected_image, classes = detect(self.tf_sess, image)

        self.assertEqual((2560, 3840, 3), detected_image.shape)
        self.assertListEqual(['car', 'person'], sorted(classes))
コード例 #3
0
    def test_image_fullhd_detection(self):
        image = load_image(IMAGE_FULL_HD_PATH)

        detected_image, classes = detect(self.tf_sess, image)

        self.assertEqual((1280, 1920, 3), detected_image.shape)
        self.assertListEqual(['car', 'person'], sorted(classes))
コード例 #4
0
def process_file_object(mc: Minio, tf_sess: tf.Session, bucket_name: str,
                        key: str, input_prefix: str, output_prefix: str):
    file_name = os.path.basename(key)

    print('Processing file: {}'.format(key))

    try:
        tmp_input_file_path = os.path.join('/tmp', file_name)
        tmp_output_file_path = os.path.join('/tmp', 'output_' + file_name)

        print('Downloading file: {}'.format(key))
        try:
            ret = mc.fget_object(bucket_name, key, tmp_input_file_path)
        except NoSuchKey:
            print('File not found, ignoring')
            return

        print('Loading image into memory')
        try:
            image_np = load_image(tmp_input_file_path)
        finally:
            os.remove(tmp_input_file_path)

        print('Detecting objects in file: {}'.format(tmp_input_file_path))
        image_np, classes = detect(tf_sess, image_np)
        print('Detected classes: {}'.format(','.join(classes)))

        metadata = {
            **(ret.metadata or {}),
            "x-amz-meta-classes": ','.join(classes),
        }

        try:
            save_image(image_np, tmp_output_file_path)

            output_key = key.replace(input_prefix, output_prefix, 1)

            print('Uploading file to: {}'.format(output_key))
            mc.fput_object(bucket_name,
                           output_key,
                           tmp_output_file_path,
                           metadata=metadata)
        finally:
            os.remove(tmp_output_file_path)
    finally:
        mc.remove_object(bucket_name, key)

    print('Finished processing file')
コード例 #5
0
    def check_image_output(self):
        with TemporaryFileName() as tmpfile:
            ret = self.mc.fget_object(self.bucket_name,
                                      self.output_object_name, tmpfile)
            tmp_image_metadata = ret.metadata

            tmp_image = load_image(tmpfile)

            self.assertEqual((480, 640, 3), tmp_image.shape)
            self.assertListEqual(
                sorted(
                    list(self.metadata.keys()) +
                    ['X-Amz-Meta-Classes', 'Content-Type']),
                sorted(tmp_image_metadata.keys()))
            self.assertEqual(self.metadata['X-Amz-Meta-Mqtt_topic'],
                             tmp_image_metadata['X-Amz-Meta-Mqtt_topic'])
            self.assertListEqual(
                ['car', 'person'],
                sorted(tmp_image_metadata['X-Amz-Meta-Classes'].split(',')))
コード例 #6
0
    def test_image_load(self):
        image = load_image(IMAGE_PATH)

        self.assertEqual((480, 640, 3), image.shape)