我正在尝试运行“猫和狗”示例,但我陷入了输入数据步骤。有人可以帮助我理解为什么我做错了并帮助我解决它吗?
先谢谢了。 ps:我不太清楚为什么会在C:\ Users \ siqiz \ Desktop \ tensorflowLearing \ 01Catsvsdogs \ traincat.2893.jpg中出现错误,因为我的所有图片都应保存为C:\ Users \ siqiz \ Desktop \ tensorflowLearing \ 01Catsvsdogs \ train \ cat.0.jpg
import matplotlib.pyplot as plt
BATCH_SIZE = 2
CAPACITY = 256
IMG_W = 208
IMG_H = 208
train_dir = 'C:\\Users\\siqiz\\Desktop\\tensorflowLearing\\01Catsvsdogs\\train\\'
image_list, label_list = get_files(train_dir)
image_batch, label_batch = get_batch(image_list, label_list, IMG_W, IMG_H, BATCH_SIZE, CAPACITY)
with tf.Session() as sess:
i = 0
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
try:
while not coord.should_stop() and i<1:
img, label = sess.run([image_batch, label_batch])
# just test one batch
for j in np.arange(BATCH_SIZE):
print('label: %d' %label[j])
plt.imshow(img[j,:,:,:])
plt.show()
i+=1
except tf.errors.OutOfRangeError:
print('done!')
finally:
coord.request_stop()
coord.join(threads)
def get_batch(image, label, image_W, image_H, batch_size, capacity):
'''
Args:
image: list type
label: list type
image_W: image width
image_H: image height
batch_size: batch size
capacity: the maximum elements in queue
Returns:
image_batch: 4D tensor [batch_size, width, height, 3], dtype=tf.float32
label_batch: 1D tensor [batch_size], dtype=tf.int32
'''
image = tf.cast(image, tf.string)
label = tf.cast(label, tf.int32)
# make an input queue
input_queue = tf.train.slice_input_producer([image, label])
label = input_queue[1]
image_contents = tf.read_file(input_queue[0])
image = tf.image.decode_jpeg(image_contents, channels=3)
######################################
# data argumentation should go to here
######################################
image = tf.image.resize_image_with_crop_or_pad(image, image_W, image_H)
image = tf.image.per_image_standardization(image)
image_batch, label_batch = tf.train.batch([image, label],
batch_size= batch_size,
num_threads= 64,
capacity = capacity)
#you can also use shuffle_batch
# image_batch, label_batch = tf.train.shuffle_batch([image,label],
# batch_size=BATCH_SIZE,
# num_threads=64,
# capacity=CAPACITY,
# min_after_dequeue=CAPACITY-1)
label_batch = tf.reshape(label_batch, [batch_size])
image_batch = tf.cast(image_batch, tf.float32)
return image_batch, label_batch
错误是
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.NotFoundError'>, NewRandomAccessFile failed to Create/Open: C:\Users\siqiz\Desktop\tensorflowLearing\01Catsvsdogs\traincat.2893.jpg : ???????????
; No such file or directory
[[Node: ReadFile = ReadFile[_device="/job:localhost/replica:0/task:0/device:CPU:0"](input_producer/Gather)]]
Done training -- epoch limit reached
Traceback (most recent call last):
File "<ipython-input-26-0683f80cdbe4>", line 1, in <module>
run_training()
File "C:/Users/siqiz/Desktop/tensorflowLearing/newCatAndDogs/01 cats vs dogs/training.py", line 95, in run_training
coord.join(threads)
File "C:\Users\siqiz\Anaconda3\lib\site-packages\tensorflow\python\training\coordinator.py", line 389, in join
six.reraise(*self._exc_info_to_raise)
File "C:\Users\siqiz\Anaconda3\lib\site-packages\six.py", line 693, in reraise
raise value
File "C:\Users\siqiz\Anaconda3\lib\site-packages\tensorflow\python\training\queue_runner_impl.py", line 252, in _run
enqueue_callable()
File "C:\Users\siqiz\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1259, in _single_operation_run
None)
File "C:\Users\siqiz\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 516, in __exit__
c_api.TF_GetCode(self.status.status))
NotFoundError: NewRandomAccessFile failed to Create/Open: C:\Users\siqiz\Desktop\tensorflowLearing\01Catsvsdogs\traincat.2893.jpg : ???????????
; No such file or directory
[[Node: ReadFile = ReadFile[_device="/job:localhost/replica:0/task:0/device:CPU:0"](input_producer/Gather)]]
答案 0 :(得分:0)
仔细阅读此错误:“创建/打开失败:C:\ Users \ siqiz \ Desktop \ tensorflowLearing \ 01Catsvsdogs \ traincat.2893.jpg” 您的文件名必须是cat.2893.jpg,但是在这里,您的计算机识别出的文件名是“ traincat.2893.jpg”。
您可以尝试删除“ train_dir”末尾的“ \\”,如下所示: train_dir ='C:\ Users \ siqiz \ Desktop \ tensorflowLearing \ 01Catsvsdogs \ train'
我不确定它是否有效,因为我没有研究过Windows上的tensorflow,而是研究了Ubuntu.lol上的tensorflow