我正在尝试按照本教程对SVHN数据集进行分类: https://www.tensorflow.org/versions/0.6.0/tutorials/deep_cnn/index.html
我正在使用train_32x32.mat文件。为了将它与CNN代码(如上所述)一起使用,我使用这个简单的代码将.mat文件转换为几个.bin文件:
import numpy as np
import scipy.io
from array import array
read_input = scipy.io.loadmat('data/train_32x32.mat')
j=0
output_file = open('data_batch_%d.bin' % j, 'ab')
for i in range(0, 64000):
# create new bin file
if i>0 and i % 12800 == 0:
output_file.close()
j=j+1
output_file = open('data_batch_%d.bin' % j, 'ab')
# Write to bin file
if read_input['y'][i] == 10:
read_input['y'][i] = 0
read_input['y'][i].astype('uint8').tofile(output_file)
read_input['X'][:,:,:,i].astype('uint32').tofile(output_file)
output_file.close()
但是当我尝试使用这些自定义的.bin文件对SVHN进行分类时,我遇到了错误“无效的参数:指数无效(超出范围)”,如下所示:
Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4
W tensorflow/core/common_runtime/executor.cc:1027] 0x1a53160 Compute status: Invalid argument: Indices are not valid (out of bounds). Shape: dim { size: 128 } dim { size: 10 }
[[Node: SparseToDense = SparseToDense[T=DT_FLOAT, Tindices=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](concat, SparseToDense/output_shape, SparseToDense/sparse_values, SparseToDense/default_value)]]
Traceback (most recent call last):
File "cifar10_train.py", line 138, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/default/_app.py", line 11, in run
sys.exit(main(sys.argv))
File "cifar10_train.py", line 134, in main
train()
File "cifar10_train.py", line 104, in train
_, loss_value = sess.run([train_op, loss])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 345, in run
results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 419, in _do_run
e.code)
tensorflow.python.framework.errors.InvalidArgumentError: Indices are not valid (out of bounds). Shape: dim { size: 128 } dim { size: 10 }
[[Node: SparseToDense = SparseToDense[T=DT_FLOAT, Tindices=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](concat, SparseToDense/output_shape, SparseToDense/sparse_values, SparseToDense/default_value)]]
Caused by op u'SparseToDense', defined at:
File "cifar10_train.py", line 138, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/default/_app.py", line 11, in run
sys.exit(main(sys.argv))
File "cifar10_train.py", line 134, in main
train()
File "cifar10_train.py", line 76, in train
loss = cifar10.loss(logits, labels)
File "/home/sarah/Documents/SVHN/cifar10.py", line 364, in loss
dense_labels = tf.sparse_to_dense(concated,[FLAGS.batch_size, NUM_CLASSES],1.0, 0.0)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_sparse_ops.py", line 153, in sparse_to_dense
default_value=default_value, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 633, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1710, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 988, in __init__
self._traceback = _extract_stack()
我在stackoverflow中找到了类似的问题TensorFlow CIFAR10 Example。但即使我改变标签,它仍然无效。
如果我做错了或不理解任何逻辑,请告诉我。
由于
萨拉
答案 0 :(得分:0)
我安装的Tensorflow版本出了问题(可能是个错误)。升级到新版本解决了这个问题。
由于