# plt.axis('off') # plt.show() with tf.Graph().as_default() as g: # gray_images = [] # for image in face_images: # grayed_image = tf.image.rgb_to_grayscale(face_image) # gray_images.append(grayed_image) images = np.reshape(face_images, [len(faces), 42, 42, 1]) # images = tf.pack(face_images) # images = tf.cast(tf.reshape(images, [len(faces), 42, 42, 1]), tf.float32) # print(images) with tf.Session() as sess: cnn = CNN.CNN_net(False) sess.run(tf.global_variables_initializer()) saver = tf.train.Saver(max_to_keep=1) model_file = tf.train.latest_checkpoint('ckpt1/') saver.restore(sess, model_file) feed_dict_test = {cnn.images: images} labels = sess.run(cnn.logits, feed_dict=feed_dict_test) # print(labels) im = Image.open(image_path) for i in range(len(face_images)): emotion = emotions[np.where(labels[i] == np.max(labels[i]))[0][0]]
import tensorflow as tf import datetime from timer import Timer from fer2013 import Fer2013 import numpy as np import CNN # img1 = utils.load_image("./test_data/tiger.jpeg") # img1_true_result = [1 if i == 292 else 0 for i in range(7)] # 1-hot result for tiger # batch1 = img1.reshape((1, 224, 224, 3)) with tf.Session() as sess: cnn = CNN.CNN_net() sess.run(tf.global_variables_initializer()) saver = tf.train.Saver(max_to_keep=1) train_timer = Timer() load_timer = Timer() fer2013 = Fer2013('train') fer2013_test = Fer2013('val') max_iter = 100000 summary_iter = 10 epoch = 0 for step in range(1, max_iter + 1): load_timer.tic()