lucasosouza
1/4/2017 - 11:34 AM

new_images.py

# import images
import os
import cv2
images = []
labels = []
for img in os.listdir('../'):
    # import only images
    if img[-3:] == 'jpg':
        # resize to the same size used in the training set
        images.append(cv2.resize(plt.imread('../' + img), (32,32)))
        # the name of the images is the number corresponding to its label
        # so img[:2] is the label, like 01, or 35
        labels.append(int(img[:2]))
        
# create X_new and y_new
X_new = np.array(images)
y_new = np.array(labels)
print(X_new.shape, y_new.shape)

# predicting for new labels
with tf.Session() as sess: 
    sess.run(tf.initialize_all_variables())
    softmax_pred = tf.nn.top_k(tf.nn.softmax(logits), 5)
    feed_dict = {
        x: X_new,
        y: y_new
    }
    classification = sess.run(softmax_pred, feed_dict) 

# printing the probability distribution
for i in range(len(classification.values)):
    print(list(zip(classification.values[i], classification.indices[i])))
    
# print the correct labels for each, to compare with the probability distribution
print(y_new)