ValueError: Variable vgg

xiaoxiao2025-04-26  9

参考链接:

https://stackoverflow.com/questions/44978210/valueerror-variable-vgg-16-conv1-conv1-1-weights-already-exists-disallowed

https://bbs.csdn.net/topics/392277761

问题描述:

在windows端使用Flask+Apache+WSGI+tf-faster-rcnn+winform,所有环境配置好后,重启Apache开始检测,第一次检测时,检测结果正常输出,第二检测时就开始报500错误,查看Apache错误日志,如下:

[Mon Oct 29 14:20:17.120980 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] totalNum 0\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] [2018-10-29 14:20:23,511] ERROR in app: Exception on /postdata [POST]\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] Traceback (most recent call last):\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\flask\\app.py", line 2292, in wsgi_app\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] response = self.full_dispatch_request()\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\flask\\app.py", line 1815, in full_dispatch_request\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] rv = self.handle_user_exception(e)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\flask\\app.py", line 1718, in handle_user_exception\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] reraise(exc_type, exc_value, tb)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\flask\\_compat.py", line 35, in reraise\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] raise value\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\flask\\app.py", line 1813, in full_dispatch_request\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] rv = self.dispatch_request()\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\flask\\app.py", line 1799, in dispatch_request\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return self.view_functions[rule.endpoint](**req.view_args)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "D:/Faster-RCNN-TensorFlow-Python3.5-Cell\\ssh_demo.py", line 192, in postdata\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] net.create_architecture(sess, "TEST", 20, tag='default', anchor_scales=[8, 16, 32])\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "D:/Faster-RCNN-TensorFlow-Python3.5-Cell\\lib\\nets\\network.py", line 298, in create_architecture\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] rois, cls_prob, bbox_pred = self.build_network(sess, training)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "D:/Faster-RCNN-TensorFlow-Python3.5-Cell\\lib\\nets\\vgg16.py", line 29, in build_network\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] net = self.build_head(is_training)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "D:/Faster-RCNN-TensorFlow-Python3.5-Cell\\lib\\nets\\vgg16.py", line 92, in build_head\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] net = slim.repeat(self._image, 2, slim.conv2d, 64, [3, 3], trainable=False, scope='conv1')\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\layers\\python\\layers\\layers.py", line 2612, in repeat\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] outputs = layer(outputs, *args, **kwargs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\framework\\python\\ops\\arg_scope.py", line 182, in func_with_args\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return func(*args, **current_args)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\layers\\python\\layers\\layers.py", line 1154, in convolution2d\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] conv_dims=2)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\framework\\python\\ops\\arg_scope.py", line 182, in func_with_args\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return func(*args, **current_args)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\layers\\python\\layers\\layers.py", line 1057, in convolution\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] outputs = layer.apply(inputs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\keras\\engine\\base_layer.py", line 828, in apply\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return self.__call__(inputs, *args, **kwargs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\layers\\base.py", line 364, in __call__\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] outputs = super(Layer, self).__call__(inputs, *args, **kwargs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\keras\\engine\\base_layer.py", line 759, in __call__\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] self.build(input_shapes)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\keras\\layers\\convolutional.py", line 161, in build\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] dtype=self.dtype)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\layers\\base.py", line 278, in add_weight\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] getter=vs.get_variable)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\keras\\engine\\base_layer.py", line 586, in add_weight\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\training\\checkpointable\\base.py", line 591, in _add_variable_with_custom_getter\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] **kwargs_for_getter)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\ops\\variable_scope.py", line 1484, in get_variable\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\ops\\variable_scope.py", line 1234, in get_variable\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\ops\\variable_scope.py", line 521, in get_variable\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return custom_getter(**custom_getter_kwargs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\layers\\python\\layers\\layers.py", line 1749, in layer_variable_getter\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return _model_variable_getter(getter, *args, **kwargs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\layers\\python\\layers\\layers.py", line 1740, in _model_variable_getter\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\framework\\python\\ops\\arg_scope.py", line 182, in func_with_args\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return func(*args, **current_args)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\framework\\python\\ops\\variables.py", line 350, in model_variable\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\framework\\python\\ops\\arg_scope.py", line 182, in func_with_args\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return func(*args, **current_args)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\contrib\\framework\\python\\ops\\variables.py", line 277, in variable\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\ops\\variable_scope.py", line 492, in _true_getter\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] aggregation=aggregation)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\ops\\variable_scope.py", line 859, in _get_single_variable\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] name, "".join(traceback.format_list(tb))))\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] ValueError: Variable vgg_16/conv1/conv1_1/weights already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] \r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py", line 1768, in __init__\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] self._traceback = tf_stack.extract_stack()\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py", line 3272, in create_op\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] op_def=op_def)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] File "c:\\anaconda3\\envs\\tensorflow\\lib\\site-packages\\tensorflow\\python\\util\\deprecation.py", line 488, in new_func\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] return func(*args, **kwargs)\r [Mon Oct 29 14:20:23.511438 2018] [wsgi:error] [pid 5168:tid 1588] [client 113.247.57.193:18118] \r

滑到底部可以看到有一个明显的错误提示: ValueError: Variable vgg_16/conv1/conv1_1/weights already exists, disallowed.

经查找问题得知大概问题的原因是两次检测不能使用tensorflow旧的变量,解决办法是在重置图表,输入以下语句:

tf.reset_default_graph()

例如我就加在了开始检测的位置:

最后问题完全解决!

转载请注明原文地址: https://www.6miu.com/read-5029162.html

最新回复(0)