tensorflow / models

Models and examples built with TensorFlow
Other
77.01k stars 45.78k forks source link

Feature request: SSD Mobilenet needs instance keys for ML Engine #4770

Closed josealb closed 4 years ago

josealb commented 6 years ago

System information

Describe the problem

I am attempting to use an SSD mobilenet object detection model in ML Engine. I trained the model and the detections are correct. However, I just learned that batch predictions from ML Engine can return scrambled and instance keys must be used to assign each prediction to its input. If I try doing this with the current models I get errors.

Source code / logs

This is how I attempt to create a TF_Record with keys:

with tf.python_io.TFRecordWriter(predict_instance_tfr) as tfr_writer:
        with open(predict_instance_json, "w") as fp:
            blobs = bucket.list_blobs(prefix=folder_name)
            for blob in blobs:
                image_name=blob.name
                image_name = (image_name.split('/'))[1]
                if (image_name.split('.')[-1:] == ['jpg'] or image_name.split('.')[-1:] == ['jpeg']):
                    blob.download_to_filename(image_name)
                    img = Image.open(image_name)
                    img = img.resize((width, height), Image.ANTIALIAS)
                    output_str = io.BytesIO()
                    img.save(output_str, "JPEG")
                                        example = tf.train.Example(
                    features=tf.train.Features(
                        feature={
                            #'key': _int64_feature(instance_key),
                            'image': _bytes_feature(output_str.getvalue())
                        }))
                    tfr_writer.write(example.SerializeToString())

And here is the error I get:

('Exception during running the graph: assertion failed: [Unable to decode bytes as JPEG, PNG, GIF, or BMP]\n\t [[Node: map/while/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert = Assert[T=[DT_STRING], summarize=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](map/while/decode_image/cond_jpeg/cond_png/cond_gif/is_bmp, map/while/decode_image/cond_jpeg/cond_png/cond_gif/Assert_1/Assert/data_0)]]', 1)

Thank you

karmel commented 6 years ago

Based on the error message, it sounds like the images are perhaps not being found or are not in the expected format. Can you simplify this block of code to just load a single, hard-coded path to an image you know is there? Does that still fail? That will help isolate the problem.

tensorflowbutler commented 4 years ago

Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

josealb commented 4 years ago

I can close the issue, it didn't turn out to be a big issue since the returned inferences were usually in order. It's also so old that maybe it has been fixed