Keras: Error in Neural style transfer example

Created on 12 Dec 2017  路  12Comments  路  Source: rstudio/keras

First of all, thanks @jjallaire for your amaizing work!
I have an error when I play with de Neural Style example:

img <- image_load(target_image_path)
Show Traceback
Rerun with Debug
Error in py_call_impl(callable, dots$args, dots$keywords) :
ImportError: Could not import PIL.Image. The use ofarray_to_imgrequires PIL.

I think the error is because PIL is not installed. How can install it??

Most helpful comment

For me, if I install pillow in windows 10 as follows it works!

conda install -c conda-forge pillow

All 12 comments

The install_keras function should install Pillow automatically. If you aren't using install_keras then the following pip install command should install all of the additional dependencies of keras:

pip install --upgrade scipy h5py pyyaml requests Pillow

Yes, I've tried it, but it doesn't works for me (in windows 10). Anyway, in ubuntu 16.04 it works. The problem now is as follows:

model <- application_vgg19(input_tensor = input_tensor,
weights = "imagenet",
include_top = FALSE)

And the error:

Error in py_call_impl(callable, dots$args, dots$keywords) :
Exception: URL fetch failure on https://github.com/fchollet/deep-learning -models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5: None -- unknown url type: https

Detailed traceback:
File "/home/roger/anaconda3/lib/python3.6/site-packages/keras/applications/vgg19.py", line 174, inVGG19 file_hash='253f8cb515780f3b799900260a226db6') File "/home/roger/anaconda3/lib/python3.6/site-packages/keras/utils/data_utils.py", line 222, in get_file raise Exception(error_msg.format(origin, e.errno, e.reason))`

It looks like you have an issue with https in anaconda (possibly due to missing/conflicting cryto libraries in your system).

Ok, thanks!

I got the same https error:

> model <- application_vgg16(include_top=F,weights="imagenet")

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  Exception: URL fetch failure on https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5: None -- unknown url type: https 

Can you please be more specific about the solution? I am using Ubuntu and Anaconda 4.3.14. Thanks!

I don't know what the solution is in your instance (again, there is something wrong with the support for https in your Anaconda installation). You can Google the error message and see if there are any clues/leads that make sense to you: https://www.google.com/search?q=URL+fetch+failure+unknown+url+type%3A+https

@jjallaire , according to google, this can happen is python is not installed properly (compiled without ssl support). So I tested the https feature on the same 'r-tensorflow' conda env by running the https get python code directly:

import urllib
import urllib.request
urllib.request.urlretrieve("https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5", "/tmp/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5")

It worked. So I think the python/conda instance that R keras running on should be ok. But don't know why it failed if running inside rstudio ...

I'm honestly not sure why it fails from R either :-\

I almost encountered the same problem in R keras and windows 10.
I ran the codes from "Image Classification on Small Datasets with Keras" on https://tensorflow.rstudio.com/blog/keras-image-classification-on-small-datasets.html, which is an excerpt from Chapter 5 of Fran莽ois Chollet鈥檚 and J.J. Allaire鈥檚 book, Deep Learning with R (Manning Publications).

history <- model %>% fit_generator(

  • train_generator,
  • steps_per_epoch = 100,
  • epochs = 30,
  • validation_data = validation_generator,
  • validation_steps = 50
  • )
    Error in py_call_impl(callable, dots$args, dots$keywords) :
    StopIteration: Could not import PIL.Image. The use of array_to_img requires PIL.

Detailed traceback:
File "h:\Anaconda3\envs\r-tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(args, *kwargs)
File "h:\Anaconda3\envs\r-tensorflow\lib\site-packages\keras\models.py", line 1256, in fit_generator
initial_epoch=initial_epoch)
File "h:\Anaconda3\envs\r-tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(args, *kwargs)
File "h:\Anaconda3\envs\r-tensorflow\lib\site-packages\keras\engine\training.py", line 2145, in fit_generator
generator_output = next(output_generator)
File "h:\Anaconda3\envs\r-tensorflow\lib\site-packages\keras\utils\data_utils.py", line 561, in get
six.raise_from(StopIteration(e), e)
File "", line 3, in raise_from

I don't know why it fails. Does anybody have the solution? Thanks!

The Python PIL package should be installed as part of install_keras(). It's possible that it was installed but some system dependency that it has is either not satisfied or is encountering errors.

For me, if I install pillow in windows 10 as follows it works!

conda install -c conda-forge pillow

A walk around for this that I found works is using wget in the terminal to save the pre-trained model and then store that in the /.keras/models folder of your keras installation. This is what I've been using to circumvent the problem while following Rstudio Keras tutorials.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gokceneraslan picture gokceneraslan  路  6Comments

leonjessen picture leonjessen  路  4Comments

systats picture systats  路  4Comments

LarsHill picture LarsHill  路  6Comments

MaximilianPi picture MaximilianPi  路  5Comments