Giter Club home page Giter Club logo

Comments (17)

kushia avatar kushia commented on August 25, 2024 10

Did you forget to preprocess your input for the prediction ?

from deep-learning-models.

triployd avatar triployd commented on August 25, 2024 2

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.

gugarosa avatar gugarosa commented on August 25, 2024 1

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.

geemmm avatar geemmm commented on August 25, 2024 1

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.

toqitahamid avatar toqitahamid commented on August 25, 2024

What are you doing in this method decode_predictions(preds)? Can you share the code?

from deep-learning-models.

kushia avatar kushia commented on August 25, 2024

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.

leminhlong-pixta avatar leminhlong-pixta commented on August 25, 2024

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.

oleksandr-kovalov avatar oleksandr-kovalov commented on August 25, 2024

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.

leminhlong-pixta avatar leminhlong-pixta commented on August 25, 2024

Preprocessing solved my problem

from deep-learning-models.

PythonImageDeveloper avatar PythonImageDeveloper commented on August 25, 2024

@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.

ividal avatar ividal commented on August 25, 2024

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.

R-Miner avatar R-Miner commented on August 25, 2024

I have the same problem. I did the preorpocessing of the input image as well. Anyone solved the issue?

from deep-learning-models.

tom-neumark avatar tom-neumark commented on August 25, 2024

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.

DongChen06 avatar DongChen06 commented on August 25, 2024

Anybody solves the problem? Thank you!

from deep-learning-models.

slimguat avatar slimguat commented on August 25, 2024

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.

zeshankhan avatar zeshankhan commented on August 25, 2024

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.

Shivam1603 avatar Shivam1603 commented on August 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.