keras-team / keras-cv

Industry-strength Computer Vision workflows with Keras
Other
1k stars 333 forks source link

0.5.1 breaks `plot_image_gallery` #1923

Closed Philmod closed 1 year ago

Philmod commented 1 year ago

This line of code I was using with the version 0.5.0 is broken with 0.5.1:

keras_cv.visualization.plot_image_gallery(
  [image], rows=1, cols=1, value_range=(0, 255), show=True, scale=4
)

Here is the error:

File ".../keras_cv/visualization/plot_image_gallery.py", line 134, in plot_image_gallery
    images.shape[0] if len(images.shape) == 4 else 1
AttributeError: 'list' object has no attribute 'shape'
gianlucasama commented 1 year ago

From what I see [image] should be a tf.Tensor, np.array or a tf.data.Dataset as written in the docs, not a list. Try np.array(image) and let me know if it works.

Philmod commented 1 year ago

I followed the first example from this page and it does use np.array:

Screenshot 2023-07-11 at 08 54 03

gianlucasama commented 1 year ago

The example is a little old probably, it should be fixed nonetheless addressing the API change, but for now you can just do:

image = np.array(image)
keras_cv.visualization.plot_image_gallery(
    image, rows=1, cols=1, value_range=(0, 255), show=True, scale=4,
)
Philmod commented 1 year ago

Screenshot 2023-07-11 at 09 55 29

gianlucasama commented 1 year ago

Apparently, as the intepreter is telling you, the visualization function wants a batched input for the "images" parameter. Just do:

image = np.array(image)
image = np.expand_dims(image, 0)
keras_cv.visualization.plot_image_gallery(
    image, rows=1, cols=1, value_range=(0, 255), show=True, scale=4
)
Philmod commented 1 year ago

Thanks. Anyway, that was a breaking change in 0.5.1 vs 0.5.0 imho.

jbischof commented 1 year ago

Please file an issue on the guide to update.

ianstenbit commented 1 year ago

+1 -- this change did break our example, but it's because the example is wrong.

Thanks for the report -- if you open an issue on keras.io we can get the example updated

ianstenbit commented 1 year ago

This issue belongs on keras.io, so I'm going to close this copy of it.