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元素。如果需要更多详细信息,请仔细阅读。这是一个更复杂的话题。