Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow占位符,TypeError:set_shape()接受1个位置参数,但给出了2个_Python_Tensorflow_Typeerror_Placeholder - Fatal编程技术网

Python Tensorflow占位符,TypeError:set_shape()接受1个位置参数,但给出了2个

Python Tensorflow占位符,TypeError:set_shape()接受1个位置参数,但给出了2个,python,tensorflow,typeerror,placeholder,Python,Tensorflow,Typeerror,Placeholder,我试图用tensorflow建立自己的CNN网络,但当我 使用占位符,会发生一些错误 TypeError:set_shape()接受1个位置参数,但给出了2个 代码如下所示: def序列(): 完整的错误信息如下所示: 我真的不明白为什么会发生这种错误以及如何避免它。有人能帮我吗? 我非常感谢 调用tf.placeholder时,BATCH\u SIZE、inference.IMAGE\u SIZE和inference.NUM\u INPUT\u CHANEL的值是多少?BATCH\u S

我试图用tensorflow建立自己的CNN网络,但当我 使用占位符,会发生一些错误

TypeError:set_shape()接受1个位置参数,但给出了2个

代码如下所示:


def序列():

完整的错误信息如下所示:



我真的不明白为什么会发生这种错误以及如何避免它。有人能帮我吗? 我非常感谢


调用
tf.placeholder
时,
BATCH\u SIZE
inference.IMAGE\u SIZE
inference.NUM\u INPUT\u CHANEL
的值是多少?BATCH\u SIZE的值是3,inference。IMAGE\u SIZE为175,inference.NUM\u INPUT\u CHANEL为1。我似乎无法生成相同的错误。你能把你的全部文件都寄出去吗?我对
推理
对象及其类特别感兴趣。我已将代码文件上载到此博客,希望这会有所帮助。再次感谢您的回答,我应该添加一些内容。我尝试运行另一个包含占位符的文件,我也遇到了这个问题。真奇怪!调用
tf.placeholder
时,
BATCH\u SIZE
inference.IMAGE\u SIZE
inference.NUM\u INPUT\u CHANEL
的值是多少?BATCH\u SIZE的值是3,inference。IMAGE\u SIZE为175,inference.NUM\u INPUT\u CHANEL为1。我似乎无法生成相同的错误。你能把你的全部文件都寄出去吗?我对
推理
对象及其类特别感兴趣。我已将代码文件上载到此博客,希望这会有所帮助。再次感谢您的回答,我应该添加一些内容。我尝试运行另一个包含占位符的文件,我也遇到了这个问题。真奇怪!
# error happens in this line:
x = tf.placeholder(tf.float32,[BATCH_SIZE,
                               inference.IMAGE_SIZE,
                               inference.IMAGE_SIZE,
                               inference.NUM_INPUT_CHANEL],
                               name='input_x')          

y_ = tf.placeholder(tf.float32,[BATCH_SIZE,
                                inference.OUTPUT_CHANEL],
                                name='input_y')

regularizer = tf.contrib.layers.l2_regularizer(REGULARAZTION_RATE) 

y = inference.inference(x, True, regularizer)

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

variable_averages = tf.train.ExponentialMovingAverage(MOVING_AVERAGE_DECAY, global_step)

variable_averages_op = variable_averages.apply(tf.trainable_variables())

cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits( labels=tf.argmax(y_, 1), logits=y)

cross_entropy_mean = tf.reduce_mean(cross_entropy)

loss =cross_entropy_mean + tf.add_n(tf.get_collection('losses'))

learning_rate = tf.train.exponential_decay(LEARNING_RATE_BASE, global_step, num_examples/BATCH_SIZE, LEARNING_RATE_DECAY)

train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss, global_step=global_step)

with tf.control_dependencies([train_step, variable_averages_op]):

    train_op = tf.no_op(name='train')

saver = tf.train.Saver()

with tf.Session() as sess:

    tf.global_variables_initializer().run()

    for i in range(TRAINING_STEPS):

        dataset= DataConverted.read_datasets()

        xs=dataset.train

        ys=dataset.lables

        reshaped_xs = np.reshape(xs, (BATCH_SIZE, inference.IMAGE_SIZE, inference.IMAGE_SIZE, inference.NUM_INPUT_CHANEL))

        reshaped_ys = np.reshape(ys, (BATCH_SIZE,inference.OUTPUT_NODE))

        _, loss_value, step = sess.run([train_op, loss, global_step], feed_dict={x: reshaped_xs, y_: reshaped_ys})

        if i%100== 0:

            print("After %d training step(s), loss on training batch is %f." % (step, loss_value))

            saver.save(sess, os.path.join(MODEL_SAVE_PATH, MODEL_NAME), global_step=global_step)

def main(argv=None):

      train()

if __name__ == '__main__':

      tf.app.run()
 -  File "E:/WN/MachineLearning/FirstTry/train.py", line 31, in train
x = tf.placeholder(tf.float32,[BATCH_SIZE,inference.IMAGE_SIZE,inference.IMAGE_SIZE,inference.NUM_INPUT_CHANEL],name='input_x')
 - File "C:\Users\JJK\Anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1548, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
 - File "C:\Users\JJK\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2094, in _placeholder
name=name)
 - File "C:\Users\JJK\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
 -File "C:\Users\JJK\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
 - File "C:\Users\JJK\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1930, in set_shapes_for_outputs
output.set_shape(s)

- TypeError: set_shape() takes 1 positional argument but 2 were given