微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

加载 TensorFlow 1.11 模型后得到验证损失

如何解决加载 TensorFlow 1.11 模型后得到验证损失

我已经使用 TensorFlow 1.11 训练并保存了一个模型,即它以 .index、.Meta 和 .data 格式保存。当我训练模型时,我计算了损失(我使用的是 softmax_cross_entropy_with_logits)并且它工作正常。

但是,我想加载模型并在许多验证图片上进行测试。到目前为止一切顺利。

我还想计算验证损失。但是,每当我这样做时,我总是得到 0。我不确定我做错了什么。

这是一个代码片段:

[...]
def validate(mylabels):
  [...]
  session = tf.Session()

  labels = np.zeros((1,3))

  mode_folder = "mymodelfolder"
  saver = tf.train.import_Meta_graph(os.path.join(model_folder,'.Meta'))
  saver.restore(session,tf.train.latest_checkpoint(model_folder + "/./"))

  graph = tf.get_default_graph()

  network = graph.get_tensor_by_name("add_6:0")

  im_ph = graph.get_tensor_by_name("Placeholder:0")
  label_ph = graph.get_tensor_by_name("Placeholder_1:0")

  network=tf.nn.sigmoid(network)

  [...]

  cost = tf.reduce_mean(graph.get_tensor_by_name("softmax_cross_entropy_with_logits:0")) * 100

  imagepath = "myimages"
  for filename in os.listdir(imagepath):
    img = cv2.imread(imagepath + "/" + filename)
    img = img.reshape(1,height,width,3)
    Feed_dict_testing = {im_ph: img,label_ph: labels}
    result,loss = session.run([network,cost],Feed_dict = Feed_dict_testing)



版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。