Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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 什么是;fc1=tf.重塑(conv2,[-1,权重[';wd1';].获取形状().作为列表()[0]])”;做什么?_Python_Tensorflow2.0 - Fatal编程技术网

Python 什么是;fc1=tf.重塑(conv2,[-1,权重[';wd1';].获取形状().作为列表()[0]])”;做什么?

Python 什么是;fc1=tf.重塑(conv2,[-1,权重[';wd1';].获取形状().作为列表()[0]])”;做什么?,python,tensorflow2.0,Python,Tensorflow2.0,这个get.shape().as_list()[0]做什么 def conv_net(x, weights, biases, dropout): # Layer 1 - 28*28*1 to 14*14*32 conv1 = conv2d(x, weights['wc1'], biases['bc1']) conv1 = maxpool2d(conv1, k=2) # Layer 2 - 14*14*32 to 7*7*64 conv2 = conv2d

这个
get.shape().as_list()[0]
做什么

def conv_net(x, weights, biases, dropout):
    # Layer 1 - 28*28*1 to 14*14*32
    conv1 = conv2d(x, weights['wc1'], biases['bc1'])
    conv1 = maxpool2d(conv1, k=2)

    # Layer 2 - 14*14*32 to 7*7*64
    conv2 = conv2d(conv1, weights['wc2'], biases['bc2'])
    conv2 = maxpool2d(conv2, k=2)

为了更好地理解
get.shape().as_list()
,这里我提供了一个简单的例子,希望对您有所帮助

fc1 = tf.reshape(conv2, [-1, weights['wd1'].get_shape().as_list()[0]])
输出:

import tensorflow as tf
c = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
Shape = c.get_shape().as_list()
print(Shape)  
Shape = c.get_shape().as_list()[0] 
tf.reshape(c, [-1])
这意味着
c
2行3列
。 当我们打印
Shape=c.get_Shape().as_list()[0]
时,它以列表格式返回
c
0个
元素(通常它以元组形式返回形状为(2,3))

输出:

import tensorflow as tf
c = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
Shape = c.get_shape().as_list()
print(Shape)  
Shape = c.get_shape().as_list()[0] 
tf.reshape(c, [-1])
当我们使用
tf.reformate
时,它返回一个新的张量,该张量的值与旧的张量的值具有相同的顺序,除了由shape指定的新形状

当我们通过[-1]
形状时,它会变平为1D

2
输出:

import tensorflow as tf
c = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
Shape = c.get_shape().as_list()
print(Shape)  
Shape = c.get_shape().as_list()[0] 
tf.reshape(c, [-1])

fc1=tf.重塑(conv2,[-1,权重['wd1'].获取形状().作为列表()[0]]))


总而言之,我们将把
conv2
层(即2D)的权重展平(即1D),并提取
weights['wd1']
0th
元素

获取
weights['wd1']
的当前形状的第0th元素。如果需要更多详细信息,请仔细阅读。这是一个更复杂的话题。