我有以下功能,主要来自this question。那个人正在尝试阅读五个全部列的列。我正在尝试阅读两列:一列是图像文件路径,另一列是int。所以我需要打开文件并将其转换为张量。
所以我的问题是:如何读取文件并将其转换为必要的张量?
我尝试了很多不同的东西,例如读取文件并使用该字符串转换为张量。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>system-entities</key>
<array>
<dict>
<key>content-hint</key>
<string>Apple_HFS</string>
<key>dev-entry</key>
<string>/dev/disk2s1</string>
<key>mount-point</key>
<string>/Volumes/MonoDevelop</string>
<key>potentially-mountable</key>
<true/>
<key>unmapped-content-hint</key>
<string>48465300-0000-11AA-AA11-00306543ECAC</string>
<key>volume-kind</key>
<string>hfs</string>
</dict>
<dict>
<key>content-hint</key>
<string>GUID_partition_scheme</string>
<key>dev-entry</key>
<string>/dev/disk2</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>GUID_partition_scheme</string>
</dict>
</array>
</dict>
</plist>
我也试过使用numpy(不能回想起究竟是什么),但这也不起作用。
答案 0 :(得分:0)
好的,这是我失踪的地方:
def read_from_csv(filename_queue):
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
record_defaults = [[""],[0]]
image_path, label = tf.decode_csv(value, field_delim=" ", record_defaults=record_defaults)
#following line contains the important change...
image = tf.image.decode_jpeg(tf.read_file(image_path), channels=3)
return image, label
def input_pipeline(batch_size, num_epochs=None):
filename_queue = tf.train.string_input_producer(["./28_dense.csv"], num_epochs=num_epochs, shuffle=True)
image, label = read_from_csv(filename_queue)
image = tf.reshape(image, [28,28,3])
min_after_dequeue = 5
capacity = min_after_dequeue + 3 * batch_size
image_batch, label_batch = tf.train.batch( [image, label], batch_size=batch_size, capacity=capacity)
return image_batch, label_batch
file_length = 1
examples, labels = input_pipeline(file_length, 1)
我缺少的步骤只是用tf.read_file(image_path)
读取文件。我认为decode_jpeg
会这样做。
另外只是一个提示:检查TF内容的值(我犹豫说变量等)创建如下的会话:
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
real_value = sess.run([value]) # see value above
print(real_value)