keras FailedPreconditionError:找到2个根错误,(0)前置条件失败:尝试使用未初始化的值Variable_179

jmp7cifd  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(184)

我从https://github.com/FengleiFan/QAE中获取代码,并更改了数据集。我用tensorflow 1.x版本在google colab上执行代码,但我得到了我无法解决的错误。
下面提到的代码是二次自动编码器的架构。而不是Conv2D,他们使用二次卷积函数。
def CTcnn(shape=(SIZE,SIZE,1)):

  1. x_input = Input(shape=(SIZE,SIZE,1))
  2. encode_conv1 = Quad_conv_layer_same(x_input,shape=[3,3,1,15])
  3. encode_conv2 = Quad_conv_layer_same(encode_conv1,shape=[3,3,15,15])
  4. encode_conv3 = Quad_conv_layer_same(encode_conv2,shape=[3,3,15,15])
  5. encode_conv4 = Quad_conv_layer_same(encode_conv3,shape=[3,3,15,15])
  6. encode_conv5 = Quad_conv_layer_valid(encode_conv4,shape=[3,3,15,15])
  7. decode_conv4 = tf.nn.relu(Quad_deconv_layer_valid_linear(encode_conv5,shape=[3, 3,15,15],outputshape=tf.shape(encode_conv4))+encode_conv4)
  8. decode_conv3 = Quad_deconv_layer_same(decode_conv4,shape=[3, 3,15,15],outputshape=tf.shape(encode_conv3))
  9. decode_conv2 = tf.nn.relu(Quad_deconv_layer_same_linear(decode_conv3,shape=[3, 3,15,15],outputshape=tf.shape(encode_conv2))+encode_conv2)
  10. decode_conv1 = Quad_deconv_layer_same(decode_conv2,shape=[3, 3,15,15],outputshape=tf.shape(encode_conv1))
  11. x_output = tf.nn.relu(Quad_deconv_layer_same_linear(decode_conv1,shape=[3, 3,1,15],outputshape=tf.shape(x_input))+x_input)
  12. model=tf.keras.Model(inputs=x_input, outputs=x_output, name='CTcnn')
  13. return model
  14. **model = CTcnn(shape=(SIZE,SIZE,1))** #getting error in this line
  15. model.compile(optimizer='adam', loss='mean_squared_error')
  16. model.summary()

以下是完整的错误:

  1. FailedPreconditionError Traceback (most recent call last)
  2. <ipython-input-49-07fdc66cd455> in <module>()
  3. ----> 1 model = CTcnn(shape=(SIZE,SIZE,1))
  4. 2 model.compile(optimizer='adam', loss='mean_squared_error')
  5. 3 model.summary()
  6. <ipython-input-48-503bfc463612> in CTcnn(shape)
  7. 16 x_output = tf.nn.relu(Quad_deconv_layer_same_linear(decode_conv1,shape=[3, 3,1,15],outputshape=tf.shape(x_input))+x_input)
  8. 17
  9. ---> 18 model=tf.keras.Model(inputs=x_input, outputs=x_output, name='CTcnn')
  10. 19 return model
  11. 20
  12. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/training.py in __init__(self, *args, **kwargs)
  13. 145
  14. 146 def __init__(self, *args, **kwargs):
  15. --> 147 super(Model, self).__init__(*args, **kwargs)
  16. 148 _keras_api_gauge.get_cell('model').set(True)
  17. 149 # initializing _distribution_strategy here since it is possible to call
  18. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/network.py in __init__(self, *args, **kwargs)
  19. 162 'inputs' in kwargs and 'outputs' in kwargs):
  20. 163 # Graph network
  21. --> 164 self._init_graph_network(*args, **kwargs)
  22. 165 else:
  23. 166 # Subclassed network
  24. /tensorflow-1.15.2/python3.6/tensorflow_core/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
  25. 455 self._self_setattr_tracking = False # pylint: disable=protected-access
  26. 456 try:
  27. --> 457 result = method(self, *args, **kwargs)
  28. 458 finally:
  29. 459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
  30. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/network.py in _init_graph_network(self, inputs, outputs, name, **kwargs)
  31. 265
  32. 266 if any(not hasattr(tensor, '_keras_history') for tensor in self.outputs):
  33. --> 267 base_layer_utils.create_keras_history(self._nested_outputs)
  34. 268
  35. 269 self._base_init(name=name, **kwargs)
  36. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/base_layer_utils.py in create_keras_history(tensors)
  37. 182 keras_tensors: The Tensors found that came from a Keras Layer.
  38. 183 """
  39. --> 184 _, created_layers = _create_keras_history_helper(tensors, set(), [])
  40. 185 return created_layers
  41. 186
  42. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/base_layer_utils.py in _create_keras_history_helper(tensors, processed_ops, created_layers)
  43. 229 constants[i] = backend.function([], op_input)([])
  44. 230 processed_ops, created_layers = _create_keras_history_helper(
  45. --> 231 layer_inputs, processed_ops, created_layers)
  46. 232 name = op.name
  47. 233 node_def = op.node_def.SerializeToString()
  48. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/base_layer_utils.py in _create_keras_history_helper(tensors, processed_ops, created_layers)
  49. 229 constants[i] = backend.function([], op_input)([])
  50. 230 processed_ops, created_layers = _create_keras_history_helper(
  51. --> 231 layer_inputs, processed_ops, created_layers)
  52. 232 name = op.name
  53. 233 node_def = op.node_def.SerializeToString()
  54. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/engine/base_layer_utils.py in _create_keras_history_helper(tensors, processed_ops, created_layers)
  55. 227 else:
  56. 228 with ops.init_scope():
  57. --> 229 constants[i] = backend.function([], op_input)([])
  58. 230 processed_ops, created_layers = _create_keras_history_helper(
  59. 231 layer_inputs, processed_ops, created_layers)
  60. /tensorflow-1.15.2/python3.6/tensorflow_core/python/keras/backend.py in __call__(self, inputs)
  61. 3474
  62. 3475 fetched = self._callable_fn(*array_vals,
  63. -> 3476 run_metadata=self.run_metadata)
  64. 3477 self._call_fetch_callbacks(fetched[-len(self._fetches):])
  65. 3478 output_structure = nest.pack_sequence_as(
  66. /tensorflow-1.15.2/python3.6/tensorflow_core/python/client/session.py in __call__(self, *args, **kwargs)
  67. 1470 ret = tf_session.TF_SessionRunCallable(self._session._session,
  68. 1471 self._handle, args,
  69. -> 1472 run_metadata_ptr)
  70. 1473 if run_metadata:
  71. 1474 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
  72. FailedPreconditionError: 2 root error(s) found.
  73. (0) Failed precondition: Attempting to use uninitialized value Variable_179
  74. [[{{node Variable_179/read}}]]
  75. [[Variable_179/read/_1]]
  76. (1) Failed precondition: Attempting to use uninitialized value Variable_179
  77. [[{{node Variable_179/read}}]]
  78. 0 successful operations.
  79. 0 derived errors ignored.

有什么办法可以补救吗?

92vpleto

92vpleto1#

我遇到了类似的问题。我所做的就是重新启动内核,清除所有输出的xmlyter笔记本电脑,它的工作。这可能只是一个提示,以帮助别人在那里。

相关问题