eriklindernoren / PyTorch-Deep-Dream

Minimal PyTorch implementation of Deep Dream
MIT License
145 stars 34 forks source link

Error when I run python deep_dream.py --input_image images/supermarket.jpg #1

Open Vkomini opened 5 years ago

Vkomini commented 5 years ago

When I run this: python deep_dream.py --input_image images/supermarket.jpg I get the following error" invalid value encountered in true_divide zoom = (numpy.array(input.shape) - 1) / zoom_div /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/ndimage/interpolation.py:532: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed. "the returned array has changed.", UserWarning) Dreaming: 10%|█ | 1/10 [00:01<00:11, 1.23s/it] Traceback (most recent call last): File "deep_dream.py", line 86, in num_octaves=args.num_octaves, File "deep_dream.py", line 51, in deep_dream input_image = octave_base + detail ValueError: operands could not be broadcast together with shapes (1,3,31,44) (1,3,22,31)

djpecot commented 4 years ago

Interesting... I also get an error but differnt message: Traceback (most recent call last): File "deep_dream.py", line 97, in <module> plt.imsave(f"outputs/output_{filename}", dreamed_image) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\pyplot.py", line 2140, in imsave return matplotlib.image.imsave(fname, arr, **kwargs) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\image.py", line 1496, in imsave rgba = sm.to_rgba(arr, bytes=True) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\cm.py", line 271, in to_rgba raise ValueError("Floating point image RGB values " ValueError: Floating point image RGB values must be in the 0..1 range.

inter-faced commented 4 years ago

Interesting... I also get an error but differnt message: Traceback (most recent call last): File "deep_dream.py", line 97, in <module> plt.imsave(f"outputs/output_{filename}", dreamed_image) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\pyplot.py", line 2140, in imsave return matplotlib.image.imsave(fname, arr, **kwargs) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\image.py", line 1496, in imsave rgba = sm.to_rgba(arr, bytes=True) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\cm.py", line 271, in to_rgba raise ValueError("Floating point image RGB values " ValueError: Floating point image RGB values must be in the 0..1 range.

I get the same error when running on Google Colab with CUDA Version: 10.1:

Dreaming: 100% 10/10 [00:16<00:00, 1.61s/it] Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Traceback (most recent call last): File "deep_dream.py", line 92, in <module> plt.imsave(f"outputs/output_{filename}", dreamed_image) File "/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py", line 2066, in imsave return matplotlib.image.imsave(fname, arr, **kwargs) File "/usr/local/lib/python3.6/dist-packages/matplotlib/image.py", line 1550, in imsave rgba = sm.to_rgba(arr, bytes=True) File "/usr/local/lib/python3.6/dist-packages/matplotlib/cm.py", line 226, in to_rgba raise ValueError("Floating point image RGB values " ValueError: Floating point image RGB values must be in the 0..1 range.

ghost commented 3 years ago

The issue exists here, https://github.com/eriklindernoren/PyTorch-Deep-Dream/blob/637de95ffca461d49ae49538d0d44f0e89ffdf0f/deep_dream.py#L92

Try normalising the dreamed_image in range of [0,1] and then saving it. Replace L92 with,

plt.imsave(f"outputs/output_{filename}", norm(dreamed_image))
def norm(x):
    return np.array((x - np.min(x)) / (np.max(x) - np.min(x)))
ghost commented 1 year ago

Interesting... I also get an error but differnt message: Traceback (most recent call last): File "deep_dream.py", line 97, in <module> plt.imsave(f"outputs/output_{filename}", dreamed_image) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\pyplot.py", line 2140, in imsave return matplotlib.image.imsave(fname, arr, **kwargs) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\image.py", line 1496, in imsave rgba = sm.to_rgba(arr, bytes=True) File "C:\Users\dougl\anaconda3\envs\pytorchdeepdream\lib\site-packages\matplotlib\cm.py", line 271, in to_rgba raise ValueError("Floating point image RGB values " ValueError: Floating point image RGB values must be in the 0..1 range.

Same issue. The problem is here:

def deprocess(image_np):
    image_np = image_np.squeeze().transpose(1, 2, 0)
    image_np = image_np * std.reshape((1, 1, 3)) + mean.reshape((1, 1, 3))
    image_np = np.clip(image_np, 0.0, 255.0) # Issue is here at this range of!
    return image_np

Update the range passed to this function to:

image_np = np.clip(image_np, 0.0, 255.0) 

Here is the suggested update to fix the issue:

def deprocess(image_np):
    image_np = image_np.squeeze().transpose(1, 2, 0)
    image_np = image_np * std.reshape((1, 1, 3)) + mean.reshape((1, 1, 3))
    image_np = np.clip(image_np, 0.0, 1.0)  # Adjusted to clip between 0 and 1
    return image_np