是否有函数调用或其他方法来计算张量流模型中的参数总数?
通过参数,我的意思是:可训练变量的N个暗矢量具有N个参数,NxM
矩阵具有N*M
参数等。因此,本质上,我想对张量流会话中所有可训练变量的形状尺寸的乘积求和。
循环遍历中每个变量的形状tf.trainable_variables()
。
total_parameters = 0
for variable in tf.trainable_variables():
# shape is an array of tf.Dimension
shape = variable.get_shape()
print(shape)
print(len(shape))
variable_parameters = 1
for dim in shape:
print(dim)
variable_parameters *= dim.value
print(variable_parameters)
total_parameters += variable_parameters
print(total_parameters)
更新:由于这个答案,我写了一篇文章来澄清Tensorflow中的动态/静态形状:https ://pgaleone.eu/tensorflow/2018/07/28/understanding-tensorflow-tensors-shape-static-dynamic/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句