question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same prediction for all inputs with inception model

See original GitHub issue

Hi everyone! I trained an inception model with my custom images (dataset of 8.000 images), then saved it. And when I try to make predictions with it, whatever is the input images to predict, it’s the same output! I checked everything, and all was seeming good to me…

# Here is the code to train the model `import os import numpy as np import pandas as pd from scipy.misc import imread from scipy.misc import imresize from inception_v3 import InceptionV3 from keras.preprocessing import image from keras.models import Model from keras.layers import Dense, GlobalAveragePooling2D from keras import backend as K import keras from keras.callbacks import ModelCheckpoint root_dir = os.path.abspath(‘.’) data_dir = os.path.join(root_dir, ‘data’) os.path.exists(root_dir) os.path.exists(data_dir) nb_epoch = int(raw_input("Nb epoch ? : ")) print (‘…Debut parsing et resize…’) train = pd.read_csv(os.path.join(data_dir, ‘images’, ‘test.csv’)) train.head() temp = [] for img_name in train.filename: image_path = os.path.join(data_dir, ‘images’, img_name) img_tmp = imread(image_path, mode=‘RGB’) img = imresize(img_tmp, (299, 299)) img = img.astype(‘float32’) temp.append(img) print (‘…Fin parsing et resize…’) train_x = np.stack(temp) train_x = train_x#, train_x[split_size:] train_y = keras.utils.np_utils.to_categorical(train.label.values) base_model = InceptionV3(weights=None, include_top=False)

x = base_model.output x = GlobalAveragePooling2D()(x) x = Dense(1024, activation=‘relu’)(x) predictions = Dense(196, activation=‘softmax’)(x)

model = Model(input=base_model.input, output=predictions)

print (‘…Debut compilation du model…’) model.compile(optimizer=‘rmsprop’, loss=‘categorical_crossentropy’) print (‘…Fin compilation du model…’) filepath=“weights-improvement-{epoch:02d}.hdf5” checkpoint = ModelCheckpoint(filepath, verbose=1, save_best_only=True, mode=‘max’) callbacks_list = [checkpoint] print (‘Debut entrainement’) trained_model = model.fit(train_x, train_y, nb_epoch=nb_epoch, callbacks=callbacks_list, batch_size=8) model.save(‘car_model.h5’) print (‘Fin de l'entrainement’) `

## And here is the code to make predictions

`import os import numpy as np import pandas as pd from scipy.misc import imread from scipy.misc import imresize from inception_v3 import InceptionV3 from inception_v3 import preprocess_input from keras.preprocessing import image from keras.models import Model from keras.layers import Dense, GlobalAveragePooling2D from keras import backend as K import keras from keras.callbacks import ModelCheckpoint from imagenet_utils import decode_predictions root_dir = os.path.abspath(‘.’) data_dir = os.path.join(root_dir, ‘data’) os.path.exists(root_dir) os.path.exists(data_dir)

base_model = InceptionV3(weights=None, include_top=False)

x = base_model.output x = GlobalAveragePooling2D()(x) x = Dense(1024, activation=‘relu’)(x) predictions = Dense(197, activation=‘softmax’)(x)

model = Model(input=base_model.input, output=predictions)

print (‘…Debut compilation du model…’) model.load_weights(‘car_model.h5’) model.compile(optimizer=‘rmsprop’, loss=‘categorical_crossentropy’) print (‘…Fin compilation du model…’)

#while True: #img_path = raw_input('Img path : ') img_path = ‘/home/images/truck1.jpg’ # Pas propre. A changer print (img_path) img_tmp = imread(img_path, mode=‘RGB’) img = imresize(img_tmp, (299, 299)) img = img.astype(‘float32’) x_ = np.expand_dims(img, axis=0) preds = model.predict(x_) decode_predictions(preds) print (‘Fin prediction’) `

I hope you’ll find the problem, because I don’t see at all…

(I trained the model over 50 epochs, so the problem don’t come for here)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:17

github_iconTop GitHub Comments

10reactions
kushiacommented, May 4, 2017

Did you forget to preprocess your input for the prediction ?

2reactions
triploydcommented, Nov 23, 2017

helllllllllo, @leminhlong-pixta i have the same problem as you described above. can you tell me a bit more specific about “preprocessing” ? did you solve the problem by subtracting mean or something ? thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

same predictions for all the inputs with a fine tuned inception ...
For any image as input, I have been getting the maximum score only in column 3 which means I'd get the same prediction...
Read more >
Advanced Guide to Inception v3 | Cloud TPU
It is an advanced view of the guide to running Inception v3 on Cloud TPU. ... The Estimator API enforces separation of model...
Read more >
Why I get same predictions values for diferent input data?
I describe deeper, I am trying to build a model that is capable to predict wicht machine must be planificate for the day...
Read more >
Inception V2 and V3 - Inception Network Versions
This factorization does not work well for early layers when input dimensions ... Inception V3 is similar to and contains all the features...
Read more >
What Is Transfer Learning? A Guide for Deep Learning | Built In
If you have the same input in both tasks, possibly reusing the model and making predictions for your new input is an option....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found