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
Tensorflow 在张量流代码中重塑完全连接层的输入?_Tensorflow - Fatal编程技术网

Tensorflow 在张量流代码中重塑完全连接层的输入?

Tensorflow 在张量流代码中重塑完全连接层的输入?,tensorflow,Tensorflow,在下面的代码中,我有两个最大池和两个卷积层。在将_out2合用后,我想添加一个完全连接的层。 如果我提到 `W-input=tf.reshape(pooling_out2, [-1,FLAGS.image_size*FLAGS.image_size*32])` 它将获取图像的初始值。假设我从图像大小28开始。我应该给出什么命令来重塑池的维度 `batch_size = 4 input = tf.Variable(tf.random_normal([batch_size

在下面的代码中,我有两个最大池和两个卷积层。在将_out2合用后,我想添加一个完全连接的层。 如果我提到

`W-input=tf.reshape(pooling_out2, [-1,FLAGS.image_size*FLAGS.image_size*32])`
它将获取图像的初始值。假设我从图像大小28开始。我应该给出什么命令来重塑池的维度

    `batch_size = 4
     input =     tf.Variable(tf.random_normal([batch_size,FLAGS.image_size,FLAGS.image_size,FLAGS.input_channel]))
    filter = weight_variable([FLAGS.image_size,FLAGS.image_size,FLAGS.input_channel,FLAGS.filter_channel])
    filter_2= 
 weight_variable([FLAGS.filter_size,FLAGS.filter_size,FLAGS.filter_channel,32])
    def conv2d(inputs,filters):
        return tf.nn.conv2d(inputs,filters,strides=[1,2,2,1],padding='SAME')
    def max_pool(conv_out):
        return tf.nn.max_pool(conv_out,ksize=[1,FLAGS.filter_size,FLAGS.filter_size,1],strides=[1,2,2,1],padding='SAME')
    conv_out1 = conv2d(input,filter)
    pooling_out1 = max_pool(conv_out1)
    conv_out2 = conv2d(pooling_out1,filter_2)
    pooling_out2 = max_pool(conv_out2)`

可以使用命令tf.shape获得tensorflow张量的形状(作为tensorflow张量)

那么,在第一个维度之后乘以维度就足够了,比如:

last_shape = tf.shape(pooling_out2)
n_features = tf.reduce_prod(last_shape[1:])
new_shape = [last_shape[0], n_features]
W_input = tf.reshape(pooling_out2, new_shape)