我已经按照教程进行操作,显示的csv example似乎无法正常工作。它永远陷入困境......
以下是代码:
let queue = NSOperationQueue()
let op1 = NSBlockOperation { () -> Void in
let img1 = self.applyFilterTo(self.image!, filter: self.filtersImages[indexPath.row])
NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
cell.imageView.image = img1
})
}
queue.addOperation(op1);
cell.imageView.layer.cornerRadius = 5
cell.imageView.layer.masksToBounds = true
cell.filterLabel.text = self.filtersLabels[indexPath.row]
我正在使用Tensorflow 0.7.1和Python3。
我做错了什么?
我的文件只有这一行:
import tensorflow as tf
filename_queue = tf.train.string_input_producer(["file0.csv", "file1.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [[1], [1], [1], [1], [1]]
col1, col2, col3, col4, col5 = tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.pack([col1, col2, col3, col4])
with tf.Session() as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1200):
# Retrieve a single instance:
example, label = sess.run([features, col5])
coord.request_stop()
coord.join(threads)
答案 0 :(得分:4)
感谢您坚持尝试调试此功能。事实证明,您遇到了a recent commit中修复的错误,但修复程序尚未进入版本。有两种可能的修复方法(acquiring more processors除外):
在Python程序中,将以下内容添加到session creation:
config = tf.ConfigProto(inter_op_parallelism_threads=2)
with tf.Session(config=config) as sess:
# ...
问题的原因是TensorFlow使用有界线程池来调度操作,并且(直到修复)读取器操作可以阻塞,如果在读者完成之前必须运行另一个操作系统,则会导致死锁(例如因为生产者 - 消费者关系)。该修复程序通过异步运行读取器来解决此问题。
答案 1 :(得分:0)
在TensorFlow 0.10中可以省去一些人的悲伤,Bruno Oliveira的修正和Python 3.0中都需要格式化,即使使用正确的2.x打印语法,也不会在Python 2.x中使用。
import tensorflow as tf
filename_queue = tf.train.string_input_producer(["./iris.data"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
# Default values, in case of empty columns. Also specifies the type of the
# decoded result.
record_defaults = [tf.constant([], dtype=tf.float32), # Column 0
tf.constant([], dtype=tf.float32), # Column 1
tf.constant([], dtype=tf.float32), # Column 2
tf.constant([], dtype=tf.float32),
tf.constant([], dtype=tf.string)]
col1, col2, col3, col4, col5 = tf.decode_csv(
value, record_defaults=record_defaults)
features = tf.pack([col1, col2, col3, col4])
config = tf.ConfigProto(inter_op_parallelism_threads=2)
with tf.Session(config=config) as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for i in range(1200):
# Retrieve a single instance:
example, label = sess.run([features, col5])
print(example, label)
coord.request_stop()
coord.join(threads)