python argument out of range_OutOfRangeError:RandomShuffleequeue'_7_shuffle_batch_1/random_shuffle_q...

真的很感谢你读我的问题

我的数据集大约是9779张图像(.dcm)。有两个标签,一个是1,有5000个训练图像,另一个是0,有4779个图像。在

我使用TFrecords合并并构建一个数据集。然后把它传给CNN的模特。在writer = tf.python_io.TFRecordWriter("train.tfrecords")

for idx, img_path in enumerate(all_images):#all_images is a list containing all path of all images

img = dm.read_file(img_path)

pixel_bytes = img.PixelData

img_raw = pixel_bytes

if idx < len_all_cancer_images:

example = tf.train.Example(features=tf.train.Features(feature={

"label": tf.train.Feature(int64_list = tf.train.Int64List(value = [1])),

'img_raw': tf.train.Feature(bytes_list = tf.train.BytesList(value = [img_raw]))}))

writer.write(example.SerializeToString())

else:

example = tf.train.Example(features=tf.train.Features(feature={

"label": tf.train.Feature(int64_list = tf.train.Int64List(value=[0])),

'img_raw': tf.train.Feature(bytes_list = tf.train.BytesList(value = [img_raw]))}))

writer.write(example.SerializeToString())

writer.close()

然后我用TFRecordReader来读取它

^{pr2}$

当我想读我的数据时img_batch, label_batch = tf.train.shuffle_batch([img, label],

batch_size = 200, capacity = 9779,

min_after_dequeue = 2000)

init = tf.global_variables_initializer()

with tf.Session() as sess:

sess.run(init)

coord = tf.train.Coordinator()

threads = tf.train.start_queue_runners(coord = coord)

for i in xrange(1):

a, b = sess.run([img_batch, label_batch])

a_ = a[0]

b_ = b[0]

img_1 = tf.reshape(a_[0, :, :, :], [512, 512])

print img_1.shape

print b_.shape

print b_

print '********************'

plt.imshow(sess.run(img_1), cmap='gray')

我想选取一些数据并打印出来,但是错误。。。在

第一个:InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 524288 values, but the requested shape has 262144

[[Node: Reshape = Reshape[T=DT_UINT8, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](DecodeRaw, Reshape/shape)]]

第二:Traceback (most recent call last):

File "", line 1, in

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile

execfile(filename, namespace)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile

builtins.execfile(filename, *where)

File "/Users/wuzhenglin/Python_nice/SAL_LUNG/test.py", line 96, in

read_and_decode()

File "/Users/wuzhenglin/Python_nice/SAL_LUNG/test.py", line 82, in read_and_decode

a, b = sess.run([img_batch, label_batch])

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 767, in run

run_metadata_ptr)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 965, in _run

feed_dict_string, options, run_metadata)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1015, in _do_run

target_list, options, run_metadata)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1035, in _do_call

raise type(e)(node_def, op, message)

tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_7_shuffle_batch_1/random_shuffle_queue' is closed and has insufficient elements (requested 200, current size 0)

[[Node: shuffle_batch_1 = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch_1/random_shuffle_queue, shuffle_batch_1/n)]]

Caused by op u'shuffle_batch_1', defined at:

File "", line 1, in

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile

execfile(filename, namespace)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile

builtins.execfile(filename, *where)

File "/Users/wuzhenglin/Python_nice/SAL_LUNG/test.py", line 96, in

read_and_decode()

File "/Users/wuzhenglin/Python_nice/SAL_LUNG/test.py", line 71, in read_and_decode

min_after_dequeue = 2000)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 1165, in shuffle_batch

name=name)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 739, in _shuffle_batch

dequeued = queue.dequeue_many(batch_size, name=name)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/data_flow_ops.py", line 458, in dequeue_many

self._queue_ref, n=n, component_types=self._dtypes, name=name)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 1310, in _queue_dequeue_many_v2

timeout_ms=timeout_ms, name=name)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op

op_def=op_def)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2327, in create_op

original_op=self._default_original_op, op_def=op_def)

File "/Users/wuzhenglin/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1226, in __init__

self._traceback = _extract_stack()

OutOfRangeError (see above for traceback): RandomShuffleQueue '_7_shuffle_batch_1/random_shuffle_queue' is closed and has insufficient elements (requested 200, current size 0)

[[Node: shuffle_batch_1 = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch_1/random_shuffle_queue, shuffle_batch_1/n)]]

还有一些有用的信息图像.dcm512*512为RGB

非常感谢:-)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值