Comments (17)
Did you forget to preprocess your input for the prediction ?
from deep-learning-models.
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!
from deep-learning-models.
I'm also having the same problem as you! No matter which network I use, I always get the same predictions for different images. This only happens when I try to train my own network and save either its whole configuration or weights.
If I'm using the pre-built weights from VGG, ResNet, whatever, it seems to be working fine.
from deep-learning-models.
After img = img.astype('float32'), try to add img = img/255. to make sure every value is between 0 and 1.
from deep-learning-models.
What are you doing in this method decode_predictions(preds)? Can you share the code?
from deep-learning-models.
Hi, sure :
def decode_predictions(preds, top=5):
results = []
for pred in preds:
top_indices = pred.argsort()[-top:][::-1]
for i in top_indices :
print ("prediction is " + i)
return "Prediction Over"
This function is inspired by the function "decode_pred" in the file imagenet_utils.py
But it always return the same top-5 labels no matter what's the input image I try..
from deep-learning-models.
I have the same problem. Logits are the same even though inputs are different for inception v4. I also use my custom code for predicting tags for images.
import tensorflow as tf
import inception_base_model
import math
from datetime import datetime
from image_processing import ImageProcessing
import numpy as np
from collections import OrderedDict
from lib.inception_model import inception_base_model as inception
class InceptionOutput(object):
def __init__(self, checkpoint_dir):
self.checkpoint_dir = checkpoint_dir
def output(self, image, num_classes, vocab, threshold=0.5):
with tf.Session() as sess:
img_processing = ImageProcessing()
image = img_processing.process_image(image)
logits, _ = inception_base_model.inference(image, num_classes=num_classes,
for_training=False)
ckpt = tf.train.get_checkpoint_state(self.checkpoint_dir)
if ckpt:
variable_averages = tf.train.ExponentialMovingAverage(
inception.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
restorer = tf.train.Saver(variables_to_restore)
checkpoint_path = ckpt.model_checkpoint_path
restorer.restore(sess, checkpoint_path)
print('%s: Pre-trained model restored from %s' %
(str(datetime.now()), str(checkpoint_path)))
# Assuming model_checkpoint_path looks something like:
# /my-favorite-path/imagenet_train/model.ckpt-0,
# extract global_step from it.
global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
print('Succesfully loaded model from %s at step=%s.' %
(ckpt.model_checkpoint_path, global_step))
else:
print('No checkpoint file found')
sess.run(tf.initialize_all_variables())
logits = sess.run(logits)
return self.get_top_dict(logits[0], vocab, threshold)
def get_top_dict(self, output_logits, rev_target_vocab, threshold):
trans_confidence_dict = OrderedDict()
temp = np.argsort(output_logits)
top_logit_indices = temp[-5:]
for logit_index in top_logit_indices:
# Numpy array has one element. Inside that element is a list of logits for vocab
trans_logit = output_logits[logit_index]
#Continue with if the logit index does not exist
if len(rev_target_vocab) <= logit_index:
continue
trans = tf.compat.as_str(rev_target_vocab[logit_index])
# Faster than tensorflow's sigmoid.
confidence = 1.0 / (1.0 + math.exp(-trans_logit))
if (trans not in trans_confidence_dict and confidence >= threshold) or \
(trans in trans_confidence_dict and confidence > trans_confidence_dict[trans]):
# Add confidence and translation to dictionary if the key has higher confidence or
# if the key doesn't exist in dictionary.
trans_confidence_dict[trans] = confidence
return trans_confidence_dict
from deep-learning-models.
I have exactly the same problem for keras 2.0.3(tensorflow) and InceptionV3 (custom trained) model.
Pre-build weights from VGG, InceptionV3 works just fine.
But if I train my own top layers - model gives the same prediction for any object.
My model has val_acc is ~95-97% according to output from training and validation using fit_generator
from deep-learning-models.
Preprocessing solved my problem
from deep-learning-models.
@leminhlong-pixta , Hi , i've trained inception-v4 for my own dataset but i don;t know for prediction for test images , have you some code about prediction ? i use tf-slim library.
from deep-learning-models.
Having the same problem: output class is always the same for all images I input, even if I do predictions one by one. The next time I load the model, the "favourite" class changes, but still applies to all input images.
I'm using ImageDataGenerator with the corresponding preprocess_input function, then flow_from_directory to feed the images.
Observed in:
Tensorflow's Keras 2.1.4-tf with Python3.6 on Ubuntu 16.04.
- Keras pretrained VGG16, using vgg16 preprocess_input inside my ImageDataGenerator. Loading with
model = VGG16(weights="imagenet")
- Keras pretrained InceptionV3, using inception_v3 preprocess_input, loading with
model = InceptionV3(weights="imagenet")
I load my data with:
datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
datagen.flow_from_directory(
data_root_dir, target_size=(image_size[0:2]),
batch_size=1, save_to_dir='preview', save_prefix='t',
save_format='jpeg')
And then do the predictions with:
labels_out = model.predict(image)
I see the same behaviour with model.predict_on_batch(image)
Any ideas...?
from deep-learning-models.
I have the same problem. I did the preorpocessing of the input image as well. Anyone solved the issue?
from deep-learning-models.
I have the same issue. I ran retrain.py against the flowers example. I ran label_image.py and it worked as expected. Then I tried to load the model using the LabelImage.java example (passing in Placeholder as input and final_results as output) and I always get the same prediction.
from deep-learning-models.
Anybody solves the problem? Thank you!
from deep-learning-models.
After img = img.astype('float32'), try to add img = img/255. to make sure every value is between 0 and 1.
this was my problem thanks brah
from deep-learning-models.
I got the same issue the increase in the training dataset and epochs makes the output probabilities similar for different images. At <10 epochs and dataset of size 10 the model is predicting different probabilities for different images but for more than 100 epochs and dataset of 1000s it generates an exactly same probability distribution for each class.
from deep-learning-models.
I am having the same issue. Has anyone solved it? I have tried pre-processing, still having the same trouble.
from deep-learning-models.
Related Issues (20)
- Optimize AUC metric on compile function with R Keras API
- Resnet50 raises AttributeError: 'NoneType' object has no attribute 'image_data_format'
- An existing connection was forcibly closed by the remote host HOT 1
- Resnet50 has wrong shape after stem - problem was corrected in keras-applications version.
- Making a Keras layer dynamic for Tensorflow operations(Tensorflow object detection API) HOT 1
- Would it be possible to integrate object detection or image segmentation models?
- ImportError: cannot import name '_obtain_input_shape' from 'keras.applications.imagenet_utils' (C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\applications\imagenet_utils.py) HOT 1
- -- issue is added by mistake --
- Why keras is slower HOT 1
- Why keras is slower'
- how to change the models' path ?
- No normalization in prepocess_input function HOT 1
- keras applications
- Loading Keras Model for Multiprocess
- download speed too slow HOT 2
- NameError: name 'X_val_prep' is not defined
- ValueError: Error when checking input: expected vgg16_input to have shape (244, 244, 3) but got array with shape (224, 224, 3)
- The model expects 0 input arrays, but only received one array.
- SignatureDoesNotMatch when downloading the releases v0.7 HOT 1
- I downloaded the pretrained model of resnet50 but it doesn't works
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deep-learning-models.