启动resnet v2冻结模型丢失准确性

时间:2017-12-17 17:35:28

标签: python tensorflow neural-network deep-learning resnet

经过模特训练后,我有几个项目:

Checkpoint file
model.ckpt.index file
model.ckpt.meta file
model.ckpt file
a graph.pbtxt file.

我使用官方freeze_graph.py

将模型冻结到frozen_model.pb中

我已将output_node_names设置为InceptionResnetV2 / Logits / Predictions并输入到--prefix / batch:0。

所以,我使用这个脚本加载了冻结图:

import tensorflow as tf
from scipy.misc import imread, imresize
import numpy as np

img = imread("./test.jpg")
img = imresize(img, (299,299,3))
img = img.astype(np.float32)
img = np.expand_dims(img, 0)

labels_dict = {0:'normal', 1:'not'}

#Define the filename of the frozen graph
graph_filename = "./frozen_model.pb"

#Create a graph def object to read the graph
with tf.gfile.GFile(graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())

Construct the graph and import the graph from graphdef
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def)

#We define the input and output node we will feed in
input_node = graph.get_tensor_by_name('import/batch:0')
output_node = graph.get_tensor_by_name('import/InceptionResnetV2/Logits/Predictions:0')

with tf.Session() as sess:
    predictions = sess.run(output_node, feed_dict = {input_node: img})
    print predictions
    label_predicted = np.argmax(predictions[0])

print 'Predicted result:', labels_dict[label_predicted]

结果总是得到索引0 - 这意味着 - 正常,实际上它不是。

我做错了什么?当我使用预训练的初始训练和评估数据集时,resnet-v2的准确度为70%

1 个答案:

答案 0 :(得分:0)

首先,您必须预处理输入图像(输入图像范围应在[-1,1]范围内)。在“ expand_dims”之前,您可以添加以下行:

img -= 127.5
img /= 127.5

第二,如果您使用了引用的冻结脚本,则输入层可能如下:

input_node = graph.get_tensor_by_name('import/input:0')