为什么“ zip参数必须支持迭代”,此代码中出现错误?

时间:2019-06-13 16:14:10

标签: python tensorflow

我正在构建手写文本识别nn,并且我尝试执行此代码,但是我得到了“ zip参数#2必须支持迭代”,并且我不明白为什么会发生此错误 请帮助

char_arr = [c for c in r"""i(jQXr).gA&t#enw75:0l6*2KVOz/hL-?UIP'bv,McTJ9pdY4xfy3+"N1ZHDSqGWCFE!skRoB;8uam"""]
num_dic = {n: i for i, n in enumerate(char_arr)}

global_step = tf.Variable(0,trainable=False)

Y = tf.sparse_placeholder(tf.int32)

data_label = 'apple'

indices = [[i] for i in range(0,len(data_label))]
values = [char_arr.index(c) for c in list(data_label)]
shape = [len(data_label)]
label = tf.SparseTensorValue(indices, values, shape)

label = tf.convert_to_tensor_or_sparse_tensor(label)


sess.run(optimizer, feed_dict={X : model, Y : label, keep_prob : 0.6})

print('Step :',global_step,', label :',data_label)

我得到了这些错误:

  File "<ipython-input-6-44645c5acb58>", line 1, in <module>
    runfile('C:/Users/samsung/Desktop/손글씨/HC+nn_v2.py', wdir='C:/Users/samsung/Desktop/손글씨')

  File "C:\Users\samsung\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\samsung\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/samsung/Desktop/손글씨/HC+nn_v2.py", line 136, in <module>
    sess.run(optimizer, feed_dict={X : base, Y : label, keep_prob : 0.6})

  File "C:\Users\samsung\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 900, in run
    run_metadata_ptr)

  File "C:\Users\samsung\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1072, in _run
    for subfeed, subfeed_val in _feed_fn(feed, feed_val):

  File "C:\Users\samsung\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1052, in _feed_fn
    return feed_fn(feed, feed_val)

  File "C:\Users\samsung\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 111, in <lambda>
    [feed.indices, feed.values, feed.dense_shape], feed_val)),

TypeError: zip argument #2 must support iteration

0 个答案:

没有答案