'Problem with 'Unknown image file format' error for GCS image in Tensorflow style transfer demo
I'm wanting to use my own images for this Tensorflow Style Transfer demo, which I've copied to my own Colab notebook.
[https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization][1]
I have images stored in a GCS bucket but have been getting image format errors. To test this, I took one of the images from the Tensorflow demo, downloaded it and put it in my GCS bucket, added the link to the "Let's try it on more images" section of my demo code, and am getting the same file format error message I was previously getting with my own images.
Here's where I've inserted the GCS version of the image:
content_urls = dict(
tueblingen02='https://storage.cloud.google.com/01_bucket-02/Tuebingen_Neckarfront-vox.jpeg',
sea_turtle='https://upload.wikimedia.org/wikipedia/commons/d/d7/Green_Sea_Turtle_grazing_seagrass.jpg',
tuebingen='https://upload.wikimedia.org/wikipedia/commons/0/00/Tuebingen_Neckarfront.jpg',
grace_hopper='https://storage.googleapis.com/download.tensorflow.org/example_images/grace_hopper.jpg',
)
style_urls = dict(
kanagawa_great_wave='https://upload.wikimedia.org/wikipedia/commons/0/0a/The_Great_Wave_off_Kanagawa.jpg',
kandinsky_composition_7='https://upload.wikimedia.org/wikipedia/commons/b/b4/Vassily_Kandinsky%2C_1913_-_Composition_7.jpg',
etc ...
The resulting error message:
InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required. [Op:DecodeImage]
Full message:
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-16-3ded16359898> in <module>()
26 content_image_size = 384
27 style_image_size = 256
---> 28 content_images = {k: load_image(v, (content_image_size, content_image_size)) for k, v in content_urls.items()}
29 style_images = {k: load_image(v, (style_image_size, style_image_size)) for k, v in style_urls.items()}
30 style_images = {k: tf.nn.avg_pool(style_image, ksize=[3,3], strides=[1,1], padding='SAME') for k, style_image in style_images.items()}
3 frames
<ipython-input-16-3ded16359898> in <dictcomp>(.0)
26 content_image_size = 384
27 style_image_size = 256
---> 28 content_images = {k: load_image(v, (content_image_size, content_image_size)) for k, v in content_urls.items()}
29 style_images = {k: load_image(v, (style_image_size, style_image_size)) for k, v in style_urls.items()}
30 style_images = {k: tf.nn.avg_pool(style_image, ksize=[3,3], strides=[1,1], padding='SAME') for k, style_image in style_images.items()}
<ipython-input-2-1485a3082999> in load_image(image_url, image_size, preserve_aspect_ratio)
19 img = tf.io.decode_image(
20 tf.io.read_file(image_path),
---> 21 channels=3, dtype=tf.float32)[tf.newaxis, ...]
22 img = crop_center(img)
23 img = tf.image.resize(img, image_size, preserve_aspect_ratio=True)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/traceback_utils.py in error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
7184 def raise_from_not_ok_status(e, name):
7185 e.message += (" name: " + name if name is not None else "")
-> 7186 raise core._status_to_exception(e) from None # pylint: disable=protected-access
7187
7188
InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required. [Op:DecodeImage]
So that's confusing me because the image works fine when it's hosted elsewhere, leading me to believe it's not an image format issue, but something else.
I'd greatly appreciate any input or suggestions on what might be happening here. thx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
