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难进料批量_Python_Tensorflow - Fatal编程技术网

Python Tensorflow难进料批量

Python Tensorflow难进料批量,python,tensorflow,Python,Tensorflow,作为前言,我了解了如何制作无尺寸张量及其主要用法 我的隐藏层取决于我传递的数据的批量大小。因此,我将批量大小传递给占位符。不幸的是,这给我带来了一大堆压力和错误,因为许多函数在没有大小的形状上不能很好地工作。我正在寻找一种方法来使用张量的动态形状来计算隐藏层中的节点数 目前,我收到了这个错误 InvalidArgumentError(回溯见上文):必须为数据类型为int32的占位符张量'placeholder_2'提供一个值 [[Node:Placeholder_2=Placeholder dT

作为前言,我了解了如何制作无尺寸张量及其主要用法

我的隐藏层取决于我传递的数据的批量大小。因此,我将批量大小传递给占位符。不幸的是,这给我带来了一大堆压力和错误,因为许多函数在没有大小的形状上不能很好地工作。我正在寻找一种方法来使用张量的动态形状来计算隐藏层中的节点数

目前,我收到了这个错误

InvalidArgumentError(回溯见上文):必须为数据类型为int32的占位符张量'placeholder_2'提供一个值 [[Node:Placeholder_2=Placeholder dType=DT_INT32,shape=[],_device=“/job:localhost/replica:0/task:0/cpu:0”]]

它不喜欢使用运行时未知的形状初始化fill常量。我非常感谢你的帮助

下面是隔离错误的代码片段

import tensorflow as tf

x = tf.placeholder(tf.float32, shape=(None, 784))

nodes = tf.div(tf.shape(x)[0],2)

bias = tf.Variable(tf.constant(.1 ,shape = [nodes]), validate_shape =  False )

init = tf.initialize_all_variables()
sess = tf.InteractiveSession()
sess.run(init)
我还收到了以下错误:

形状=[int(dim)表示形状中的尺寸] TypeError:int()参数必须是字符串、类似对象的字节或数字,而不是“张量”

将加注管更换为时

bias = tf.Variable(tf.constant(.1 ,shape = [nodes]), validate_shape = False )
提前谢谢。

张量的形状不能依赖于另一个张量。形状必须仅包含整数值,或
,表示形状未知。如果要对形状执行计算,则需要使用对整数进行运算的Python原语,而不是对张量进行运算的Tensorflow原语来执行这些计算

(您也不应该关闭形状验证,这表明您做错了。)

也就是说,神经网络的不同层对批量大小使用不同的值是不寻常的——你确定这就是你想要做的吗

如果确定,请尝试以下方法:

import tensorflow as tf

batch_size = 32

x = tf.placeholder(tf.float32, shape=(batch_size, 784))
bias = tf.Variable(tf.constant(.1, shape = [batch_size / 2]))

init = tf.initialize_all_variables()
sess = tf.InteractiveSession()
sess.run(init)

我希望这有帮助

嗨,我打算让层使用不同的批量大小,这取决于示例大小。由于我做了更多的研究,我发现这是不必要的,非常感谢!快速提问:张量x的形状是(?,784),对吗?既然我希望[0]是空的,那么如何使用tf.shape(x)[0]访问784呢。