PyTorch-Deep-Dream
PyTorch-Deep-Dream copied to clipboard
Error when I run python deep_dream.py --input_image images/supermarket.jpg
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
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.
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.
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)))
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