name_scope与variable_scope 详解

本文深入解析TensorFlow中name_scope与variable_scope的区别与联系,通过实验对比二者对变量命名的影响,探讨如何利用它们来确保变量名的唯一性及重用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

name_scope 与 variable_scope详解


[参考文献]:

1.scope 命名方法

2.name&variable scope

3.tf.variable_scope和tf.name_scope的用法


1.scope是干什么的

顾名思义“scope”的意思是“范围”,那么name_scope和variable_scope就是针对name所做的范围定义。典型的 TensorFlow 可以有数以千计的节点,在构建各op的过程中,命名要做到不重复,那么在编写程序的时候就要特别注意,例如“x”、“y”、”W”、”B”甚至“weight”等经常使用的变量/常量命名就很可能会重复,否则就要增加一个字符串来表示不同的op所属,例如在x前加train成为train_x,在x前加scan成为scan_x等等,一方面表明此变量、常量所属“范围”的标识,这个name_scope和variable_scope就是干这个事情的,另一方面是从name上保证此变量命名的唯一性。有了这个scope的存在,其中描述的变量和常量就会在机器当中自动给添加前缀描述,作为对各个变量、常量的区分。在这里的编程和以前使用C、C++不同之处就是,C/C++当中的变量名实际相当于我们这里的XXX.name()而不是XXX,计算机区分的是XXX.name()。简单说,有了scope,那么在tensorflow当中就是用op/tensor名来划定范围,实现对变量或者常量名的唯一性定义,避免冲突。

2.scope是怎么干的

接下来我们要分析的问题是:究竟name_scope()和variable_scope()对可以产生变量的tf.get_variable()和tf.Variable()会有什么不同?为了一探究竟,接下来做一些测试:

2.1 tf.name_scope对tf.get_variable()的影响

import tensorflow as tf

with tf.name_scope("a_name_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    var1 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
var1:0
[ 1.]

[结论]:

name_scope()没有对 tf.get_variable()产生的变量增加“范围”。于是,如果再有相同的变量名生成,即便name_scope使用了新的名字“a_name_scope_new”,仍旧会破坏“唯一性”,从而导致出错“该变量已经定义过了!”,试验一下:

with tf.name_scope("a_name_scope_new") as myscope:
    initializer = tf.constant_initializer(value=1)
    var1 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)
---------------------------------------------------------------------------

ValueError: Variable var1 already exists, disallowed. Did you mean to set reuse=True in VarScope? 

【结论】:

果然出错了!“Variable var1 already exists, disallowed.”,说明name_scope没有对get_variable()增加“范围”。那我现在还想生成一个新的变量var2而且要让其内容与var1相同怎么办?

with tf.name_scope("a_name_scope") as myscope:
    #initializer = tf.constant_initializer(value=1)
    var2 = tf.get_variable(name='var2', dtype=tf.float32, initializer=var1)
    #var2=var1
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # var2:0
    print(sess.run(var2))   # [ 1.]
var1:0
[ 1.]
var2:0
[ 1.]

【结论】:

看结果,的确生成了新的变量var2。如果我不想生成新的变量var2,而只想做个变量的名称更改怎么办?注意,这里就和C、C++有不同了。
with tf.name_scope("a_name_scope") as myscope:
    var3=var1
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
    print(var3.name)        # var1:0
    print(sess.run(var3))   # [ 1.]
var1:0
[ 1.]
var1:0
[ 1.]

【结论】:

虽然有一个变量var3,但是其name和值都是与var1相同的,计算机认的是name,认为这两个是完全一样的,并不是新建,只是引用,我们可以理解为是C语言中的指针,指针的名字可以千奇百怪,但是其指向的地址内容才是其真正的归属。所以,这个变量var3你可以随时设置,不会引起重复性、唯一性的错误——“Variable var1 already exists, disallowed.”。

变量的名称只是指针名,变量的name是地址

with tf.name_scope("a_name_scope") as myscope:
    var3=var1

【结论】:

的确没有引起错误提示。

2.2 variable_scope对get_variable的影响

那么接着分析,既然name_scope对get_variable没有增加“范围”,那variable_scope呢?
with tf.variable_scope("a_variable_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    var1 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # a_variable_scope/var1:0
    print(sess.run(var1))   # [ 1.]
a_variable_scope/var1:0
[ 1.]

【结论】:variable_scope对get_variable有命名的影响

看到var1指向的内容被新建了,其name变成了“a_variable_scope/var1:0”,也就是说对计算机而言这已经是一个新的内容了,需要一个新的内存来存储,这个和之前的var1.name = var1:0已经不是一个东西了.同时,我们想要找到之前的var1的name已经是不能够了,这个完全就是C/C++指针的意思,指针指向了一个新的内存,如果不使用一个新的指针指向旧的地址,那么就会导致旧地址的内容无法检索了。验证一下:
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # a_variable_scope/var1:0
    print(sess.run(var1))   # [ 1.]
    print(var3.name)        # var1:0
    print(sess.run(var3))   # [ 1.]
a_variable_scope/var1:0
[ 1.]
var1:0
[ 1.]

【结论】: 变量名就是指针,变量的name属性是地址

var3是前面对旧的var1的内容的指针,虽然在前面var1指向了新建的内容(a_variable_scope/var1:0),但是原有内容的指针给了var3,所以现在仍旧可以通过指针找到旧地址内容。前面看到了,使用variable_scope能够产生新的变量,即增加了“范围”标识的变量,那么这个能否再次执行产生新的变量呢?也就是说,新产生的name为(a_variable_scope/var1:0)的地址能否再次被新建?
with tf.variable_scope("a_variable_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    var1 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)
ValueError: Variable a_variable_scope/var1 already exists, disallowed. Did you mean to set reuse=True in VarScope? 

【结论】:get_variable取值的唯一性仍旧需要保证

可见虽然variable_scope可以增加name“范围”,但是get_variable取值的唯一性仍旧需要维护,否则就会出错,你是不可以任性新建的。那我现在就是想重用此变量,我就是想更改一个变量名而已,行吗?当然行,之前我们就采用了直接变量名赋值就行了“var3=var1”,这样变量名改为了var3,但是其name仍旧是var1的name,从c理解就是,指针随便建,地址唯一不变,街道名你随便改,可是街道你不能随便拆改。那还有一种材料中介绍的方法,就是使用reuse_variables(),但是一旦重用的对象本身不存在就会报错。这里说的对象不是“指针”,而是指针地址,而且是带有variable_scope指定的“范围”的指针地址。
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # a_variable_scope/var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # var2:0
    print(sess.run(var2))   # [ 1.]
    print(var3.name)        # var1:0
    print(sess.run(var3))   # [ 1.]
a_variable_scope/var1:0
[ 1.]
var2:0
[ 1.]
var1:0
[ 1.]

【分析】:

看看上面三个变量,如果在 tf.variable_scope(“a_variable_scope”)下则会增加“范围”——(a_variable_scope),显然,var1是已存在的对象,而var2虽然也是有已有的地址,但是如果在 tf.variable_scope当中使用get_variable来获取则会新建一个name为:(a_variable_scope/var2:0),所以var2不能当做是已有地址的变量来被重用,否则会出错。var1是可以被重用的,因为他的确是一个已有的范围内的地址。

with tf.variable_scope("a_variable_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    myscope.reuse_variables()
    var2 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)    
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # a_variable_scope/var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_variable_scope/var1:0
    print(sess.run(var2))   # [ 1.]
a_variable_scope/var1:0
[ 1.]
a_variable_scope/var1:0
[ 1.]

**【结论】:**var1被var2重用了

with tf.variable_scope("a_variable_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    myscope.reuse_variables()
    var2 = tf.get_variable(name='var2', shape=[1], dtype=tf.float32, initializer=initializer)    
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # a_variable_scope/var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_variable_scope/var1:0
    print(sess.run(var2))   # [ 1.]
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

ValueError: Variable a_variable_scope/var2 does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

【结论】:

虽然var2经过重用了,但是其name是var1的,也就是(a_variable_scope/var1:0),而不是(a_variable_scope/var2:0),所以一旦重用则会因为没有这个地址而报错!同时,重用操作“myscope.reuse_variables()”在with范围内都是生效的,所以导致如果想如之前一般新建一个变量都会报错,如下:
with tf.variable_scope("a_variable_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    myscope.reuse_variables()
    var2 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)    
    var7= tf.get_variable(name='var7', shape=[1], dtype=tf.float32, initializer=initializer)    
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # a_variable_scope/var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_variable_scope/var1:0
    print(sess.run(var2))   # [ 1.]
    print(var7.name)        # a_variable_scope/var1:0
    print(sess.run(var7))   # [ 1.]
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

ValueError: Variable a_variable_scope/var7 does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

【结论】:

在上面var1被var2重用,这个是正确的,但是紧接着想重新新建一个就会立马报错的,说明这个重用操作“myscope.reuse_variables()”在with范围内都是生效的。如果name_scope下使用reuse_variables()则会报错。
with tf.name_scope("a_name_scope") as myscope:
    initializer = tf.constant_initializer(value=1)
    myscope.reuse_variables()
    var1 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer)



with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)
AttributeError: 'str' object has no attribute 'reuse_variables'

2.3 name_scope()对variable的影响

with tf.name_scope("a_name_scope") as myscope:    
    var2 = tf.Variable(name='var2', initial_value=[2], dtype=tf.float32)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_name_scope/var2:0
    print(sess.run(var2))   # [ 2.]
a_variable_scope/var1:0
[ 1.]
a_name_scope_5/var2:0
[ 2.]

【结论】:

很棒!name_scope对variable有效,新增了“范围”名。那这个范围名是否与get_variable一样有唯一性?
with tf.name_scope("a_name_scope") as myscope:    
    var2 = tf.Variable(name='var2', initial_value=[2], dtype=tf.float32)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_name_scope/var2:0
    print(sess.run(var2))   # [ 2.]
a_variable_scope/var1:0
[ 1.]
a_name_scope_6/var2:0
[ 2.]

【结论】:

从上面结果看,唯一性仍旧保证了,原因是自动的将var2.name从(a_name_scope_1/var2:0)变为了(a_name_scope_2/var2:0).这里使用了“变为”这个词实际是错误的,因为根本不是变为,而是新建了一个name 为(a_name_scope_2/var2:0)的变量,这个变量和前面的那个变量的名都为var2但是name属性却是不同的。

2.4 variable_scope对variable的影响

with tf.variable_scope("my_variable_scope") as myscope:    
    var2 = tf.Variable(name='var2', initial_value=[initializer.value], dtype=tf.float32)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_name_scope/var2:0
    print(sess.run(var2))   # [ 2.]
a_variable_scope/var1:0
[ 1.]
my_variable_scope/var2:0
[ 1.]

【结论】:

variable_scope对variable有效,而且从下面的运行结果看,唯一性可以得到保证,新建了一个新的变量,这点和name_scope一致。
with tf.variable_scope("my_variable_scope") as myscope:    
    var2 = tf.Variable(name='var2', initial_value=[initializer.value], dtype=tf.float32)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(var1.name)        # var1:0
    print(sess.run(var1))   # [ 1.]
    print(var2.name)        # a_name_scope/var2:0
    print(sess.run(var2))   # [ 2.]
a_variable_scope/var1:0
[ 1.]
my_variable_scope_1/var2:0
[ 1.]

总结:

[1]. name_scope 对 get_variable新建变量的name属性无影响;对variable新建变量的name属性增加了“范围”标识。

[2]. variable_scope对get_variable新建变量的name属性和variable新建变量的name属性都增加了“范围”标识。

[3]. get_variable新建变量如果遇见重复的name则会因为重复而报错。

[4]. variable新建的变量如果遇见重复的name则会自动修改前缀,以避免重复出现。

WARNING:tensorflow:From /root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term 2025-07-26 19:47:00.316548: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1 2025-07-26 19:47:00.379323: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: pciBusID: 0000:39:00.0 name: NVIDIA GeForce RTX 4090 computeCapability: 8.9 coreClock: 2.52GHz coreCount: 128 deviceMemorySize: 23.55GiB deviceMemoryBandwidth: 938.86GiB/s 2025-07-26 19:47:00.379583: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory 2025-07-26 19:47:00.379632: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10'; dlerror: libcublas.so.10: cannot open shared object file: No such file or directory 2025-07-26 19:47:00.380958: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10 2025-07-26 19:47:00.381316: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10 2025-07-26 19:47:00.381386: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10'; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory 2025-07-26 19:47:00.381440: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10'; dlerror: libcusparse.so.10: cannot open shared object file: No such file or directory 2025-07-26 19:47:00.381492: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory 2025-07-26 19:47:00.381501: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2025-07-26 19:47:00.381919: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2025-07-26 19:47:00.396214: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2000000000 Hz 2025-07-26 19:47:00.405365: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f45c0000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2025-07-26 19:47:00.405415: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 2025-07-26 19:47:00.409166: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix: 2025-07-26 19:47:00.409199: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108] WARNING:tensorflow:From /root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/layers/layers.py:1089: Layer.apply (from tensorflow.python.keras.engine.base_layer_v1) is deprecated and will be removed in a future version. Instructions for updating: Please use `layer.__call__` method instead. loaded ./checkpoint/decom_net_train/model.ckpt loaded ./checkpoint/illumination_adjust_net_train/model.ckpt No restoration pre model! (480, 640, 3) (680, 720, 3) (415, 370, 3) Start evalating! 0 Traceback (most recent call last): File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1365, in _do_call return fn(*args) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1350, in _run_fn target_list, run_metadata) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1443, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value Restoration_net/de_conv6_1/biases [[{{node Restoration_net/de_conv6_1/biases/read}}]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "evaluate.py", line 92, in <module> restoration_r = sess.run(output_r, feed_dict={input_low_r: decom_r_low, input_low_i: decom_i_low}) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 958, in run run_metadata_ptr) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1181, in _run feed_dict_tensor, options, run_metadata) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1359, in _do_run run_metadata) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1384, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value Restoration_net/de_conv6_1/biases [[node Restoration_net/de_conv6_1/biases/read (defined at /root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/variables.py:256) ]] Original stack trace for 'Restoration_net/de_conv6_1/biases/read': File "evaluate.py", line 28, in <module> output_r = Restoration_net(input_low_r, input_low_i) File "/root/Python/KinD-master/KinD-master/model.py", line 70, in Restoration_net conv6=slim.conv2d(up6, 256,[3,3], rate=1, activation_fn=lrelu,scope='de_conv6_1') File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args return func(*args, **current_args) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/layers/layers.py", line 1191, in convolution2d conv_dims=2) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args return func(*args, **current_args) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/layers/layers.py", line 1089, in convolution outputs = layer.apply(inputs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func return func(*args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_v1.py", line 1695, in apply return self.__call__(inputs, *args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 547, in __call__ outputs = super(Layer, self).__call__(inputs, *args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_v1.py", line 758, in __call__ self._maybe_build(inputs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_v1.py", line 2131, in _maybe_build self.build(input_shapes) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/keras/layers/convolutional.py", line 172, in build dtype=self.dtype) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 460, in add_weight **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_v1.py", line 447, in add_weight caching_device=caching_device) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py", line 743, in _add_variable_with_custom_getter **kwargs_for_getter) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 1573, in get_variable aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 1316, in get_variable aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 551, in get_variable return custom_getter(**custom_getter_kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/layers/layers.py", line 1793, in layer_variable_getter return _model_variable_getter(getter, *args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/layers/layers.py", line 1784, in _model_variable_getter aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args return func(*args, **current_args) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/variables.py", line 328, in model_variable aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args return func(*args, **current_args) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tf_slim/ops/variables.py", line 256, in variable aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 520, in _true_getter aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 939, in _get_single_variable aggregation=aggregation) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 259, in __call__ return cls._variable_v1_call(*args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 220, in _variable_v1_call shape=shape) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 198, in <lambda> previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 2614, in default_variable_creator shape=shape) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 263, in __call__ return super(VariableMetaclass, cls).__call__(*args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 1666, in __init__ shape=shape) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 1854, in _init_from_args self._snapshot = array_ops.identity(self._variable, name="read") File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py", line 180, in wrapper return target(*args, **kwargs) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 282, in identity ret = gen_array_ops.identity(input, name=name) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 3901, in identity "Identity", input=input, name=name) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 744, in _apply_op_helper attrs=attr_protos, op_def=op_def) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3327, in _create_op_internal op_def=op_def) File "/root/Python/conda_lit/kind/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1791, in __init__ self._traceback = tf_stack.extract_stack()
最新发布
07-27
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值