def test(self, dataloader, backup_path, epoch, batch_size=128):
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.25)
self.sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
# ????
self.saver = tf.train.Saver(write_version=tf.train.SaverDef.V2)
model_path = os.path.join(backup_path, 'model_%d.ckpt' % (epoch))
assert(os.path.exists(model_path+'.index'))
self.saver.restore(self.sess, model_path)
print('read model from %s' % (model_path))
# ??????????
accuracy_list = []
test_images = dataloader.data_augmentation(dataloader.test_images,
flip=False, crop=True, crop_shape=(24,24,3), whiten=True, noise=False)
test_labels = dataloader.test_labels
for i in range(0, dataloader.n_test, batch_size):
batch_images = test_images[i: i+batch_size]
batch_labels = test_labels[i: i+batch_size]
[avg_accuracy] = self.sess.run(
fetches=[self.accuracy],
feed_dict={self.images:batch_images,
self.labels:batch_labels,
self.keep_prob:1.0})
accuracy_list.append(avg_accuracy)
print('test precision: %.4f' % (numpy.mean(accuracy_list)))
self.sess.close()
评论列表
文章目录