我想用cnn对一些图片进行分类,但是当我运行代码时,它会在运行一段时间后报告错误
我检查过我的图片处理正确,但我不知道为什么总是出现错误,请帮助我!!!!
看来,我可以运行代码一段时间,但很快它报告错误:
Step 0,train loss = 2.77,train accuracy = 0.00
Step 50,train loss = 2.77,train accuracy = 0.00
Step 100,train loss = 2.65,train accuracy = 0.07
Step 150,train loss = 2.42,train accuracy = 0.00
Step 200,train loss = 2.47,train accuracy = 0.13
Step 250,train loss = 2.39,train accuracy = 0.33
Step 300,train loss = 2.27,train accuracy = 0.13
Step 350,train loss = 2.43,train accuracy = 0.27
Step 400,train loss = 2.37,train accuracy = 0.20
Step 450,train loss = 2.49,train accuracy = 0.20
Step 500,train loss = 2.15,train accuracy = 0.33
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, Got 24 frames, but animated gifs can only be decoded by tf.image.decode_gif or tf.image.decode_image
[[Node: DecodeJpeg_2 = DecodeJpeg[acceptable_fraction=0.5, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ReadFile_2)]]
Traceback (most recent call last):
File "<ipython-input-1-c0bd3b69ef1e>", line 1, in <module>
runfile('/Users/liuxueying/Documents/practice/cnn/untitled1.py', wdir='/Users/liuxueying/Documents/practice/cnn')
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 678, in runfile
execfile(filename, namespace)
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 106, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/liuxueying/Documents/practice/cnn/untitled1.py", line 486, in <module>
coord.join(threads)
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/coordinator.py", line 389, in join
six.reraise(*self._exc_info_to_raise)
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/training/queue_runner_impl.py", line 252, in _run
enqueue_callable()
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1205, in _single_operation_run
self._call_tf_sessionrun(None, {}, [], target_list, None)
File "/Users/liuxueying/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1350, in _call_tf_sessionrun
run_metadata)
InvalidArgumentError: Got 24 frames, but animated gifs can only be decoded by tf.image.decode_gif or tf.image.decode_image
[[Node: DecodeJpeg_2 = DecodeJpeg[acceptable_fraction=0.5, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](ReadFile_2)]]
这是我的图片处理代码:
def get_batch(image,label,image_W,image_H,batch_size,capacity):
image = tf.cast(image,tf.string)
label = tf.cast(label,tf.int32)
#tf.cast()ç¨æ¥åç±»å转æ¢
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,try_recover_truncated = True,acceptable_fraction=0.5)
#jpegæè
jpgæ ¼å¼é½ç¨decode_jpegå½æ°ï¼å
¶ä»æ ¼å¼å¯ä»¥å»æ¥çå®æ¹ææ¡£
image = tf.image.resize_image_with_crop_or_pad(image,image_W,image_H)
#resize
image = tf.image.per_image_standardization(image)
#对resizeåçå¾çè¿è¡æ ååå¤ç
image_batch,label_batch = tf.train.batch([image,label],batch_size = batch_size,num_threads=16,capacity = capacity)
label_batch = tf.reshape(label_batch,[batch_size])
image_batch = tf.cast(image_batch,tf.float32)
return image_batch,label_batch