tensorflow1.X固定名字变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import tensorflow as tf 

#接口定义
try: tf.get_variable(name,
shape=None,dtype=None,
initializer=None,
regularizer=None,
trainable=True,
collections=None,
caching_device=None,
partitioner=None,
validate_shape=True,
use_resource=None,
custom_getter=None)
except: pass


#1. name是变量的唯一标志符,不能重复
#2. 设置reuse=ture,可以重复引用,

a =tf.get_variable('var1',initializer=[1,2,3])# [1 2 3], var1:0
b =tf.get_variable('var2',initializer=[1])#[1],var2:0

SESS = tf.Session(); SESS.run(tf.global_variables_initializer())

print(a.eval(session=SESS),a.name,
b.eval(session=SESS),b.name,
sep='\n')

转载请注明来源 https://tianweiye.github.io