Hi Friends, when I try to run the code for lesson notebook, I get the error as below. Can you pls guide me on how to fix it?
I created new folder called Lesson1 and copied lesson1.ipynb, utils.py and vgg16.py into the new folder and tried to execute the notebook file line by line.
ModuleNotFoundError Traceback (most recent call last)
----> 1 import utils; reload(utils)
2 from utils import plots
/Users/kprayagai/Documents/Magesh/MachineLearning/JeremyTutorials/lesson1/utils.py in ()
1 from future import division,print_function
2 import math, os, json, sys, re
----> 3 import cPickle as pickle
4 from glob import glob
5 import numpy as np
ModuleNotFoundError: No module named ‘cPickle’
Here are my theano and tensor versions.
Using Theano backend.
Pls let me know if you need more details.
Since you’re using python 3 try updating utils.py to
Hi Brendan - Thanks. I already see an import ‘import cPickle as pickle’ in utils.py. Do you mean to replace
"import cPickle as pickle" with “import pickle”?
Hi - I did replace “import cPickle as pickle” with “import pickle” but now am getting an error that No module named ‘bcolz’.
Haha you’re living up to your username Try pip installing bcolz and Google for stack overflow posts if you continue to see errors.
Hi - I fixed that issue by installing bcolz. But now am getting a different error now.
from keras.regularizers import l2, activity_l2, l1, activity_l1
43 from keras.layers.normalization import BatchNormalization
44 from keras.optimizers import SGD, RMSprop, Adam
ImportError: cannot import name ‘activity_l2’
I also see a Warning as below. I think it is something to do with installation or configuration but not able to figure out the problem. I tried to see what is there in keras.json, but I could not find a folder called ~/.keras itself. Not sure how to figure out the problem. But I did install keras.
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
Using TensorFlow backend.
I tried executing further, but face another issue on vgg16 as well. May be is this because of the above issue?
import vgg16; reload(vgg16)
3 from vgg16 import Vgg16
NameError: name ‘reload’ is not defined
If you are the newbie then recommended way is to use Python 2.7.x and Keras 1.x .
The lessons in part 1 were made with that and errors you are getting because of version mismatch.
Hi - I tried to downgrade keras, but I get an error when I try to. (tried the solution as per one of the posts from google)
conda install keras=1.2.2
PackageNotFoundError: Package missing in current osx-64 channels:
I followed the post - Keras 2 Released, and fixed most of the errors due to keras now. But am still getting error - NameError: name ‘reload’ is not defined.
Hope there are other similar users who has faced the same, and hoping to find some solution there.
Thanks for all the friends, for the help and guidance.
This error is coming as reload method has been changed in new Python.
So as I already suggested.
Please use virtual environment or conda to create new python env which is based on 2.7.x
If you use anaconda then command is
conda create -n python2 python=2.7 anaconda
The use it by
source activate python2
Install all packages in this environment
sudo pip install <>
sudo pip install keras
This will work for everything without error.
Hi - Thanks. I will try to set up python 2.7 based environment and try the same. Thanks for the help.
If you see
NameError: name 'reload' is not defined I’d recommend just removing the
reload(vgg16) part, I’m not sure it is necessary anyway.
The reload problem in Python3.X can be solved as following:
from imp import reload
In Python 2.x, this was a builtin, but in 3.x, it’s in the imp module.
Why the change from
pickle? - see here, but in summary…
In Python 2, you can speed up your pickle access with cPickle. (In Python3, importing pickle will automatically use the accelerated version if it is available.)
An alternative to pip installing
bcolz is to install it using Anaconda Navigator. Go to the Environments tab and search for the bcolz package.
Did you download the data? If you don’t have a data directory off your nbs directory, you’ll get all sorts of errors.