tensorflow_notes icon indicating copy to clipboard operation
tensorflow_notes copied to clipboard

ValueError: Variable fcn_8s/vgg_16/conv1/conv1_1/weights already exists, disallowed

Open amiltonwong opened this issue 8 years ago • 7 comments

Hi, @warmspringwinds ,

I followed the steps from README.md. And start to run the first cell from fully_convolutional_networks.ipynb . However I got the following ValueError, could you suggest me how to fix this error? (my environment: TF 0.12.1, python 2.7.13)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-4efcd9f3827b> in <module>()
     47 pred, fcn_16s_variables_mapping = FCN_8s(image_batch_tensor=image_batch_tensor,
     48                                           number_of_classes=number_of_classes,
---> 49                                           is_training=False)
     50 
     51 # The op for initializing the variables.

/data/code/Dan_segment/tf-image-segmentation/tf_image_segmentation/utils/inference.pyc in new_network_definition(*args, **kwargs)
     51         kwargs['image_batch_tensor'] = resized_images_batch
     52 
---> 53         all_outputs = network_definition(*args, **kwargs)
     54 
     55         all_outputs = list(all_outputs)

/data/code/Dan_segment/tf-image-segmentation/tf_image_segmentation/models/fcn_8s.pyc in FCN_8s(image_batch_tensor, number_of_classes, is_training)
     77                                                        is_training=is_training,
     78                                                        spatial_squeeze=False,
---> 79                                                        fc_conv_padding='SAME')
     80 
     81 

/data/code/Dan_segment/models/slim/nets/vgg.pyc in vgg_16(inputs, num_classes, is_training, dropout_keep_prob, spatial_squeeze, scope, fc_conv_padding)
    164     with slim.arg_scope([slim.conv2d, slim.fully_connected, slim.max_pool2d],
    165                         outputs_collections=end_points_collection):
--> 166       net = slim.repeat(inputs, 2, slim.conv2d, 64, [3, 3], scope='conv1')
    167       net = slim.max_pool2d(net, [2, 2], scope='pool1')
    168       net = slim.repeat(net, 2, slim.conv2d, 128, [3, 3], scope='conv2')

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.pyc in repeat(inputs, repetitions, layer, *args, **kwargs)
   1668     for i in range(repetitions):
   1669       kwargs['scope'] = scope + '_' + str(i+1)
-> 1670       outputs = layer(outputs, *args, **kwargs)
   1671     return outputs
   1672 

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.pyc in func_with_args(*args, **kwargs)
    175       current_args = current_scope[key_func].copy()
    176       current_args.update(kwargs)
--> 177     return func(*args, **current_args)
    178   _add_op(func)
    179   setattr(func_with_args, '_key_op', _key_op(func))

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.pyc in convolution(inputs, num_outputs, kernel_size, stride, padding, data_format, rate, activation_fn, normalizer_fn, normalizer_params, weights_initializer, weights_regularizer, biases_initializer, biases_regularizer, reuse, variables_collections, outputs_collections, trainable, scope)
    838                                        regularizer=weights_regularizer,
    839                                        collections=weights_collections,
--> 840                                        trainable=trainable)
    841     outputs = nn.convolution(input=inputs,
    842                              filter=weights,

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.pyc in func_with_args(*args, **kwargs)
    175       current_args = current_scope[key_func].copy()
    176       current_args.update(kwargs)
--> 177     return func(*args, **current_args)
    178   _add_op(func)
    179   setattr(func_with_args, '_key_op', _key_op(func))

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/variables.pyc in model_variable(name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, device)
    242                   initializer=initializer, regularizer=regularizer,
    243                   trainable=trainable, collections=collections,
--> 244                   caching_device=caching_device, device=device)
    245 
    246 

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.pyc in func_with_args(*args, **kwargs)
    175       current_args = current_scope[key_func].copy()
    176       current_args.update(kwargs)
--> 177     return func(*args, **current_args)
    178   _add_op(func)
    179   setattr(func_with_args, '_key_op', _key_op(func))

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/variables.pyc in variable(name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, device)
    206                                        trainable=trainable,
    207                                        collections=collections,
--> 208                                        caching_device=caching_device)
    209 
    210 

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.pyc in get_variable(name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, partitioner, validate_shape, custom_getter)
   1022       collections=collections, caching_device=caching_device,
   1023       partitioner=partitioner, validate_shape=validate_shape,
-> 1024       custom_getter=custom_getter)
   1025 
   1026 

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.pyc in get_variable(self, var_store, name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, partitioner, validate_shape, custom_getter)
    848           collections=collections, caching_device=caching_device,
    849           partitioner=partitioner, validate_shape=validate_shape,
--> 850           custom_getter=custom_getter)
    851 
    852   def _get_partitioned_variable(self,

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.pyc in get_variable(self, name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape, custom_getter)
    344           reuse=reuse, trainable=trainable, collections=collections,
    345           caching_device=caching_device, partitioner=partitioner,
--> 346           validate_shape=validate_shape)
    347 
    348   def _get_partitioned_variable(

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.pyc in _true_getter(name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape)
    329           initializer=initializer, regularizer=regularizer, reuse=reuse,
    330           trainable=trainable, collections=collections,
--> 331           caching_device=caching_device, validate_shape=validate_shape)
    332 
    333     if custom_getter is not None:

/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.pyc in _get_single_variable(self, name, shape, dtype, initializer, regularizer, partition_info, reuse, trainable, collections, caching_device, validate_shape)
    630                          " Did you mean to set reuse=True in VarScope? "
    631                          "Originally defined at:\n\n%s" % (
--> 632                              name, "".join(traceback.format_list(tb))))
    633       found_var = self._vars[name]
    634       if not shape.is_compatible_with(found_var.get_shape()):

ValueError: Variable fcn_8s/vgg_16/conv1/conv1_1/weights already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:

  File "/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 208, in variable
    caching_device=caching_device)
  File "/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 177, in func_with_args
    return func(*args, **current_args)
  File "/root/anaconda2/envs/python_2.7_tf_0.12/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 244, in model_variable
    caching_device=caching_device, device=device)

amiltonwong avatar Feb 03 '17 03:02 amiltonwong

I got the same error. Does anyone know how to solve it?

xilaili avatar Feb 26 '17 06:02 xilaili

@amiltonwong @xilaili

Thank you for your issue.

I guess there might be two reasons for that:

  1. You didn't change the global variables according to your setup here:
sys.path.append("tf-image-segmentation/")
sys.path.append("/home/dpakhom1/workspace/my_models/slim/")

fcn_16s_checkpoint_path = '/home/dpakhom1/tf_projects/segmentation/model_fcn8s_final.ckpt'

os.environ["CUDA_VISIBLE_DEVICES"] = '1'
  1. Or you try to run the same cell twice. Restart the notebook or restart the kernel of the current notebook.

Let me know if it helps

warmspringwinds avatar Feb 27 '17 16:02 warmspringwinds

Hi @warmspringwinds, I also followed the instructions on the repository and got an error.

Is this global variable setup correct? I cloned tf-image-segmentation and models/slim into my workspace, then:

sys.path.append("/Users/username/Desktop/FCN Segmentation/tf-image-segmentation/") sys.path.append("/Users/username/Desktop/FCN Segmentation/models/slim")

fcn_16s_checkpoint_path = '/Users/username/Desktop/FCN Segmentation/FCN Checkpoints/model_fcn8s_final.ckpt'

os.environ["CUDA_VISIBLE_DEVICES"] = '0'

I am getting this error: name 'adapt_network_for_any_size_input' is not defined

Global variables are not pointing correctly the files fcn_8s.py, inference.py and pascal_voc.py.

Hope you can review this problem I'm having. Thank you.

parlange avatar Mar 21 '17 04:03 parlange

Hi, @warmspringwinds i get this error after carefully running as explained.

AttributeError Traceback (most recent call last) in () 6 pred, fcn_16s_variables_mapping = FCN_8s(image_batch_tensor=image_batch_tensor, 7 number_of_classes=number_of_classes, ----> 8 is_training=False)

AttributeError: 'module' object has no attribute 'pack'

But i am using TF1.1.0. So, this could be a version problem?

ghost avatar Jun 10 '17 17:06 ghost

Hi,@warmspringwinds. I get this error:"logits and labels must be same size: logits_size=[168960,2] labels_size=[187500,2]".

Hope you can review this problem I'm having. Thank you!!!!!

mangwaier avatar Jul 12 '17 07:07 mangwaier

@sharib-ms yes it a version problem:

Analogously to tf.pack and tf.unpack, we're renamed TensorArray.pack and TensorArray.unpack to TensorArray.stack and TensorArray.unstack. However, TensorArray.pack and TensorArray.unpack cannot be detected lexically since they are indirectly related to the tf namespace e.g. foo = tf.TensorArray(); foo.unpack()

All information is found: https://www.tensorflow.org/install/migration

You can change it to tf.stack and it should work.

CataRay avatar Aug 25 '17 15:08 CataRay

maybe you ran the code once , try to restart the kernel,it would clear the weights you have set before

ycynyu007 avatar May 10 '18 01:05 ycynyu007