标签:utf-8 session run tensor scope ble set usr ini
由于tf.Variable() 每次都在创建新对象,所有reuse=True 和它并没有什么关系。对于get_variable(),来说,如果已经创建的变量对象,就把那个对象返回,如果没有创建变量对象的话,就创建一个新的。#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 12 18:18:06 2018
@author: myhaspl
"""
import tensorflow as tf
tf.reset_default_graph()
x1=tf.Variable(12.1,name="x1")
x2=tf.Variable(18.22,name="x2")
with tf.variable_scope("test1"):
var1=tf.get_variable("x1",shape=(),dtype=tf.float32)
with tf.variable_scope("test2"):
var2=tf.get_variable("var",shape=[2],initializer=tf.constant_initializer([1.3,2.]),dtype=tf.float32)
with tf.Session() as sess:
tf.global_variables_initializer().run()
print(x1.eval())
print(sess.run(var1))
print(sess.run(var2))
标签:utf-8 session run tensor scope ble set usr ini
原文地址:http://blog.51cto.com/13959448/2330223