我写了一个张量流CNN,它已经训练好了.我希望恢复它以便在几个样本上运行它但不幸的是它吐出来:
ValueError:没有要保存的变量
我的评估代码可以在这里找到:
import tensorflow as tf
import main
import Process
import Input
eval_dir = "/Users/Zanhuang/Desktop/NNP/model.ckpt-30"
checkpoint_dir = "/Users/Zanhuang/Desktop/NNP/checkpoint"
init_op = tf.initialize_all_variables()
saver = tf.train.Saver()
def evaluate():
with tf.Graph().as_default() as g:
sess.run(init_op)
ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
saver.restore(sess, eval_dir)
images, labels = Process.eval_inputs(eval_data = eval_data)
forward_propgation_results = Process.forward_propagation(images)
top_k_op = tf.nn.in_top_k(forward_propgation_results, labels, 1)
print(top_k_op)
def main(argv=None):
evaluate()
if __name__ == '__main__':
tf.app.run()
Run Code Online (Sandbox Code Playgroud) 我在tensorflow中构建了一个卷积神经网络.它经过培训,现在我打开包装并进行评估.
import main
import Process
import Input
eval_dir = "/Users/Zanhuang/Desktop/NNP/model.ckpt-250"
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:
tf.train.start_queue_runners(sess=sess)
sess.run(init_op)
saver.restore(sess, eval_dir)
print(sess.run(top_k_op))
def main(argv=None):
evaluate()
if __name__ == '__main__':
tf.app.run()
Run Code Online (Sandbox Code Playgroud)
不幸的是,出现了一个奇怪的错误,我不知道为什么.
W tensorflow/core/kernels/queue_base.cc:2
W tensorflow/core/kernels/queue_base.cc:294] _0_input_producer: Skipping cancelled enqueue attempt with queue not closed
W tensorflow/core/kernels/queue_base.cc:294] _1_batch/fifo_queue: Skipping cancelled enqueue attempt with queue not closed
E …Run Code Online (Sandbox Code Playgroud) 我一直在尝试将1750*1750图像输入Tensorflow,但在使用tf.image.decode_jpeg()函数将图像转换为Tensor之后,我不知道如何标记和提供数据.
目前,我的代码是:
import tensorflow as tf
import numpy as np
import imageflow
import os, glob
sess = tf.InteractiveSession()
def read_jpeg(filename_queue):
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
my_img = tf.image.decode_jpeg(value)
my_img.set_shape([1750, 1750, 1])
print(value)
return my_img
#####################################################
def read_image_data():
jpeg_files = []
images_tensor = []
i = 1
WORKING_PATH = "/Users/Zanhuang/Desktop/NNP/DATA"
jpeg_files_path = glob.glob(os.path.join(WORKING_PATH, '*.jpeg'))
for filename in jpeg_files_path:
print(i)
i += 1
jpeg_files.append(filename)
filename_queue = tf.train.string_input_producer(jpeg_files)
mlist = [read_jpeg(filename_queue) for _ in range(len(jpeg_files))]
init = tf.initialize_all_variables()
sess = tf.Session() …Run Code Online (Sandbox Code Playgroud) 我建立了一个卷积模型,只是发现我的代码或Tensorflow的代码中存在大量内存泄漏。谁能发现问题并深入了解问题所在?
以下是一个最小的可复制示例及其一些输出:
Process.py:
import os
import sys
import tensorflow as tf
import Input
import os, re
FLAGS = tf.app.flags.FLAGS
TOWER_NAME = 'tower'
tf.app.flags.DEFINE_integer('batch_size', 1, "hello")
tf.app.flags.DEFINE_string('data_dir', '/home/zan/Desktop/Neural-Network-Prostate', "hello")
NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = Input.NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN
NUM_EXAMPLES_PER_EPOCH_FOR_EVAL = Input.NUM_EXAMPLES_PER_EPOCH_FOR_EVAL
NUM_EPOCHS_PER_DECAY = 3
MOVING_AVERAGE_DECAY = 0.9999
NUM_EPOCHS_PER_DECAY = 30
LEARNING_RATE_DECAY_FACTOR = 0.1
INITIAL_LEARNING_RATE = 0.1
def _activation_summary(x):
tensor_name = re.sub('%s_[0-9]*/' % TOWER_NAME, '', x.op.name)
tf.histogram_summary(tensor_name + '/activations', x)
tf.scalar_summary(tensor_name + '/sparsity', tf.nn.zero_fraction(x))
def inputs():
if not FLAGS.data_dir:
raise ValueError('Source Data Missing')
data_dir = FLAGS.data_dir
images, labels …Run Code Online (Sandbox Code Playgroud)