Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'imagenet_utils' for Jupyter but exists on Spyder

import numpy as np
import os
import time
from vgg16 import VGG16
from keras.preprocessing import image
from imagenet_utils import preprocess_input, decode_predictions
from keras.layers import Dense, Activation, Flatten
from keras.layers import merge, Input
from keras.models import Model
from keras.utils import np_utils
from sklearn.utils import shuffle
from sklearn.cross_validation import train_test_split
from keras.models import load_model

I was running a vgg model in my pc using Spyder everything was working fine, but when I tried running the code in Jupyter for using cloud gpu I got the following error:

 >>>>>
ImportError Traceback (most recent call last)
<ipython-input-12-4398e37e021e> in <module>()
----> 1 from imagenet_utils import preprocess_input, decode_predictions

ImportError: No module named 'imagenet_utils'<<<

Why do I have this when its working fine in another IDE quite fine? I am using Jupyter for training the model in cloud using Floyd web service.

like image 675
sachsom Avatar asked Jan 28 '23 21:01

sachsom


2 Answers

Try importing it like:

from keras.applications.vgg16 import preprocess_input, decode_prediction

This is the standard way according to the Keras Applications doc page. More reference about Keras Applications can be found there also.

Note: Be aware that it is decode_prediction and not decode_predictions in plural.

like image 177
DarkCygnus Avatar answered Apr 09 '23 18:04

DarkCygnus


As opposed to the older versions of keras (or tensorflow), you will need to be model-specific while importing imagenet_utils functions preprocess_input and decode_predictions.

For example, if you're working with Tensorflow 2 and working with ResNet50, you will have to do it in following manner

from tensorflow.keras.applications.resnet50 import decode_predictions, preprocess_input

In this case it is decode_predictions (plural) and not decode_prediction. Similar for VGG16 and other models

like image 40
SidK Avatar answered Apr 09 '23 18:04

SidK