Tensorflow模型无法正常恢复和运行

时间:2016-08-13 20:34:40

标签: tensorflow

我已经构建并成功训练了卷积模型,但是我无法恢复模型并对其进行评估。该程序抛出一堆错误而没有给出答案。

我的评估代码在这里:

import tensorflow as tf

import main
import Process
import Input

eval_dir = "/Users/Zanhuang/Desktop/NNP/model.ckpt-98"
checkpoint_dir = "/Users/Zanhuang/Desktop/NNP/checkpoint"


def evaluate():
  with tf.Graph().as_default() as g:
    images, labels = Process.eval_inputs()
    forward_propgation_results = Process.forward_propagation(images)
    init_op = tf.initialize_all_variables()
    saver = tf.train.Saver()
    top_k_op = tf.nn.in_top_k(forward_propgation_results, labels, 1)

  with tf.Session(graph = g) as sess:
    sess.run(init_op)
    tf.train.start_queue_runners(sess=sess)
    saver.restore(sess, eval_dir)
    for i in range(100):
        print(sess.run(top_k_op))

def main(argv = None):
    evaluate()

if __name__ == '__main__':
  tf.app.run()

我对eval的输出看起来像这样:但没有程序运行。它只是停留在那里。

 E tensorflow/core/client/tensor_c_api.cc:485] /Users/Zanhuang/Desktop/NNP/Prostate_Cancer_Data1.bin
     [[Node: ReaderRead = ReaderRead[_class=["loc:@FixedLengthRecordReader", "loc:@input_producer"], _device="/job:localhost/replica:0/task:0/cpu:0"](FixedLengthRecordReader, input_producer)]]
ERROR:tensorflow:Exception in QueueRunner: /Users/Zanhuang/Desktop/NNP/Prostate_Cancer_Data1.bin
 [[Node: ReaderRead = ReaderRead[_class=["loc:@FixedLengthRecordReader", "loc:@input_producer"], _device="/job:localhost/replica:0/task:0/cpu:0"](FixedLengthRecordReader, input_producer)]]

以下是我保存模型和检查点文件的程序的主要部分。

import Input
import Process

import time
import numpy as np

import tensorflow as tf
from datetime import datetime

FLAGS = tf.app.flags.FLAGS

def train():
    with tf.Session() as sess:
        images, labels = Process.inputs()

        forward_propgation_results = Process.forward_propagation(images)

        train_loss, cost = Process.error(forward_propgation_results, labels)

        image_summary_t = tf.image_summary(images.name, images, max_images = 2)

        summary_op = tf.merge_all_summaries()

        init = tf.initialize_all_variables()

        saver = tf.train.Saver()

        sess.run(init)

        saver = tf.train.Saver(tf.all_variables())

        tf.train.start_queue_runners(sess = sess)

        train_dir = "/Users/Zanhuang/Desktop/NNP/model.ckpt"

        summary_writer = tf.train.SummaryWriter(train_dir, sess.graph)

        for step in range(100):
            start_time = time.time()
            print(sess.run([train_loss, cost]))
            duration = time.time() - start_time
            if step % 1 == 0:
                num_examples_per_step = FLAGS.batch_size
                examples_per_sec = num_examples_per_step / duration
                sec_per_batch = float(duration)

                format_str = ('%s: step %d, (%.1f examples/sec; %.3f ''sec/batch)')
                print (format_str % (datetime.now(), step, examples_per_sec, sec_per_batch))

                summary_str = sess.run(summary_op)
                summary_writer.add_summary(summary_str, step)

                if step % 2 == 0:
                    checkpoint_path = train_dir
                    saver.save(sess, checkpoint_path, global_step = step)


def main(argv = None):
    train()

if __name__ == '__main__':
  tf.app.run()

0 个答案:

没有答案