Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inference problem #6

Open
misaghkord opened this issue Nov 14, 2017 · 5 comments
Open

inference problem #6

misaghkord opened this issue Nov 14, 2017 · 5 comments

Comments

@misaghkord
Copy link

hi @potterhsu
i have a very odd problem i have trained my model and got an very good accuracy. but when i try to inference my images if i use batch sizes lower than 16 (i.e 1) i get rangom numbers mostly 9.
can you please help me?

@potterhsu
Copy link
Owner

Could you please provide a minimal reproduction of your issue? Also have you followed our sample guide: inference_sample.ipynb and inference_outside_sample.ipynb?

@misaghkord
Copy link
Author

misaghkord commented Nov 14, 2017

tnx for your quick response:
i used this code from your inference_outside_sample.ipynb:

import tensorflow as tf
from model import Model


path_to_image_files = ['data/images/18.jpg', 'data/images/31.jpg', 'data/images/62.jpg',
                       'data/images/522.jpg', 'data/images/952.jpg', 'data/images/888.jpg']

images = []
for path_to_image_file in path_to_image_files:
    image = tf.image.decode_jpeg(tf.read_file(path_to_image_file), channels=3)
    image = tf.reshape(image, tf.shape(image))
    image = tf.image.convert_image_dtype(image, dtype=tf.float32)
    image = tf.multiply(tf.subtract(image, 0.5), 2)
    image = tf.image.resize_images(image, [65, 290])
    images.append(image)
images = tf.stack(images)


digits_logits = Model.inference(images)
digits_predictions = tf.argmax(digits_logits, axis=2)
digits_predictions_string = tf.reduce_join(tf.as_string(digits_predictions), axis=1)

sess = tf.InteractiveSession()
restorer = tf.train.Saver()
checkpoint_path = tf.train.latest_checkpoint('logs/train')
restorer.restore(sess, checkpoint_path)
digits_predictions_string_val, images_val = sess.run([digits_predictions_string, images])
images_val = (images_val / 2.0) + 0.5


idx = 5
image_val = images_val[idx]
digits_prediction_string_val = digits_predictions_string_val[idx]

print ('digits: %s' % digits_prediction_string_val)

sess.close()

you will notice that my data has different dimensions.
i get correct results when using 6 images in batch for example but when using 2 images i get completely different result.

@potterhsu
Copy link
Owner

It seems weird, the number of images should not affect the result.
What are the shapes of images and digits_logits in your case?

@misaghkord
Copy link
Author

image shape = [65 290 3]
digits_logits = [16 11]
i got around this problem by fine tuning my network with batch size 1 after the main training was done.
now i get accurate results by feeding single image to the network.

@jewes
Copy link

jewes commented Nov 6, 2018

change image = tf.reshape(image, [64, 64, 3]) to image = tf.image.resize_images(image, (64, 64), method=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants