简体   繁体   English

初始resnet v2冻结的模型失去准确性

[英]inception resnet v2 frozen model lost accuracy

After model training, I had several items: 经过模型训练后,我有几个项目:

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

I freezed model into frozen_model.pb using official freeze_graph.py 我使用官方freeze_graph.py将模型冻结到frozen_model.pb中

I've set the output_node_names to InceptionResnetV2/Logits/Predictions and input to - prefix/batch:0. 我已经将output_node_names设置为InceptionResnetV2 / Logits / Predictions,并输入到-prefix / batch:0。

So, I load frozen graph using this script: 因此,我使用以下脚本加载冻结的图形:

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]

And results are always getting index 0 -which means - normal, when actually it is not. 结果总是得到索引0-这意味着-正常,而实际上却不是。

What I'm doing wrong? 我做错了什么? When I was training and evaluating dataset using a pretrained inception-resnet-v2 accuracy was 70% 当我使用预训练的Inception-resnet-v2训练和评估数据集时,准确性为70%

First of all you have to preprocess your input image (input image range is expected to be in range [-1, 1]). 首先,您必须预处理输入图像(输入图像范围应在[-1,1]范围内)。 Before "expand_dims" you can add these lines: 在“ expand_dims”之前,您可以添加以下行:

img -= 127.5
img /= 127.5

Secondly if you used the script that you referred for freezing, your input layer is probably as follows: 其次,如果使用引用的冻结脚本,则输入层可能如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM