【问题标题】:inception resnet v2 frozen model lost accuracyinception resnet v2 冻结模型失去准确性
【发布时间】:2018-05-31 03:55:33
【问题描述】:

模型训练后,我有几个项目:

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 - 这意味着 - 正常,但实际上并非如此。

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

【问题讨论】:

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


    【解决方案1】:

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

    img -= 127.5
    img /= 127.5
    

    其次,如果您使用您提到的冻结脚本,您的输入层可能如下:

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

    【讨论】:

      猜你喜欢
      • 2018-02-07
      • 2018-08-02
      • 2017-11-10
      • 2022-01-23
      • 1970-01-01
      • 2018-11-08
      • 2017-02-06
      • 2017-10-13
      • 2021-09-27
      相关资源
      最近更新 更多