Hi, I wanted to document a similar problem with vgg16()
I’ve had. First my setup (MacOS):
- python2.7 environment setup via conda (Miniconda3).
- Theano .9.0 dev install following their guide:
- Keras 1.2.2
- .keras/keras.json is set to “tensorflow” and “th”
- I think I’m using MKL as my BLAS.
- Theano and Keras were both pip installed to my environment.
Issue:
I’m working alongside the cats_vs_dogs_redux notebook trying to build my own. When I try to instantiate vgg = Vgg16()
I got an error:
/Users/WayNoxchi/Miniconda3/envs/FAI/lib/python2.7/site-packages/keras/backend/theano_backend.py in in_train_phase(x, alt)
1173 elif _LEARNING_PHASE is 0:
1174 return alt
-> 1175 x = theano.ifelse.ifelse(_LEARNING_PHASE, x, alt)
1176 # x = theano.ifelse(_LEARNING_PHASE, x, alt)
1177 x._uses_learning_phase = True
AttributeError: 'module' object has no attribute 'ifelse'
I can post the full traceback if anyone likes. It essentially goes from
self.create()
in line 33 vgg16.pyc
–> self.FCBlock()
line 77 vgg16.pyc
–> model.add(Dropout(0.5))
line 63 vgg16.pyc
–> output_tensor = layer(self.outputs[0])
line 332 /keras/models.pyc
–> self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
line 572 /keras/engine/topology.pyc
–> Node.create_node(self, inbound_layers, node_indices, tensor_indices)
line 635 /keras/engine/topology.pyc
–> output_tensors = to_list(outbound_layer.call(input_tensors[0], mas k=input_masks[0]))
line 166 /keras/engine/topology.pyc
–> x = K.in_train_phase(dropped_inputs, lambda: x)
line 111 /keras/layers/core.pyc
And finally:
–> x = theano.ifelse.ifelse(_LEARNING_PHASE, x, alt)
line 1174 /keras/backend/theano_backend.py
Steps I took to fix this:
-
Commented out all references of http://www.platform.ai/models/ and replaced them with http://files.fast.ai/models/ in
vgg16.py
-
Uninstalled Keras & Theano. Reinstalled Keras 1.2.2 (Keras 2 renames
activity_l2
tol2
, so some compatibility breaks) with Theano .9.0. -
Uninstalled Keras & Theano. Reinstalled Keras 1.2.2 with Theano 0.8.0.
-
Tried to ensure I had Theano linked to MKL due to this comment referencing this comment.
-
Reinstalled the original Keras & Theano setup. Dove into
/lib/python2.7/site-packages/keras/backend/theano_backend.py
(inside my environment folder).
Then I tried to figure out exactly why theano.ifelse.ifelse(...)
was causing problems. The best I could do with Google was the comment talking about linking MKL. I used a python shell in terminal to find when theano.ifelse.ifelse
would work and when not.
>>> import theano
>>> theano.ifelse.ifelse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ifelse'
< quit & restart shell >
>>> import theano
>>> import theano.ifelse
>>> theano.ifelse.ifelse
<function ifelse at 0x114da9d70>
so then I did probably the most hackish thing I’ve done so far and added the line
from theano.ifelse import ifelse
as the 2nd line in theano_backend.py
.
Then when I ran vgg = Vgg16()
in the notebook (after restarting everything of course) I finally go the message:
"Downloading data from http://files.fast.ai/models/vgg16.h5
"
But it doesn’t end there. Mysteriously I started getting a new error:
ImportError: No module named h5py
from line 2701 of /keras/engine/topology.pyc.
Not sure what I touched or if I touched anything. Maybe I should delete the .pyc file and let it recompile it?
… that did not fix it.
Google…google…google…(I’m debugging this as I’m writing this at this point) I find this, of course I conda install the wrong thing, hdf5: 1.8.17-1
instead of h5py, but when I do install h5py: 2.7.0-np112py27_0
:
“Downloading data from http://files.fast.ai/models/vgg16.h5
”
So… yeah. Watch it be as simple as me downloading an older version of utils.py or accidentally deleting some dependency. But I figured this was worth documenting. Will be setting up GPU support for my Win8.1 machine this weekend, will see how that goes (in a relevant thread).
By the way, big thanks to Jeremy Howard & everyone who worked on this course. This is definitely being a crash course in a literal sense for me and it’s awesome. We’ll see how things are a few months from now.