name_scope || variable_scope
TensorFlow入门(七) 充分理解 name / variable_scope
tensorflow: 对variable_scope进行reuse的两种方法
TensorFlow基础:共享变量
tf.shape (tensor) || tensor.get_shape()
tensor.get_shape() 返回的是元组,元祖是python中的类型
tf.shape()返回的是tensor,tensor是tensorflow中类型
二者最大区别在于get_shape是静态的,也就是在建图的过程中有些tensor的某些维度已经推算出来了,这时我们需要使用这些维度时,可以使用静态方法获得。tf.shape是动态的,也就是它其实是tensorflow图中一个ops,tensor的维度是在运算时获得的,典型的比如batch大小。用法:
keys_len = tf.shape(keys)[1]
hidden_units = query.get_shape().as_list()[-1]
我们常见的问题“The last dimension of the inputs to Dense
should be defined. Found None
.”一般需要都是因为维度不确定导致的。需要我们使用静态方法显示说明。