将Tensorflow模型转换为ONNX格式会引发以下错误:

时间:2020-09-15 03:34:16

标签: python tensorflow onnx

我正在使用TensorFlow在python中使用经过训练的模型。并且我需要将tensorflow格式更改为ONNX,但是当我使用此命令时:

(python -m tf2onnx.convert --graphdef。\ saved_model.pb-输出冻结的.onnx --fold_const --opset 8-输入input_node:0-输出output_node:0)

然后在cmd中,出现此错误:

tensorflow.python.framework.errors_impl.FailedPreconditionError:尝试使用未初始化的值Variable_1 [[{{node _retval_Variable_1_0_3}}]]

我知道此错误意味着我正在使用一个未初始化的变量,但实际上我无法理解它是什么变量,即使我从变量中得到了一个列表,如下所示: (此外,训练模型时没有出现任何错误。)

  '''
  W_conv1                      RefVariable       <tf.Variable 'Variable:0'<...>1, 32) 
  dtype=float32_ref>
   W_conv2                      RefVariable       <tf.Variable 'Variable_2:<...>2, 64) 
  dtype=float32_ref>
   W_conv3                      RefVariable       <tf.Variable 'Variable_4:<...>, 128) 
   dtype=float32_ref>
   W_conv4                      RefVariable       <tf.Variable 'Variable_6:<...>, 256) 
   dtype=float32_ref>
   W_fc1                        RefVariable       <tf.Variable 'Variable_8:<...> 9216) 
  dtype=float32_ref>
  W_fc2                        RefVariable       <tf.Variable 'Variable_10<...>16, 1) 
 dtype=float32_ref>
  absolute_import              _Feature          _Feature((2, 5, 0, 'alpha<...>0, 0, 
 'alpha', 0), 16384)
  b_conv1                      RefVariable       <tf.Variable 'Variable_1:<...>=(32,) 
  dtype=float32_ref>
 b_conv2                      RefVariable       <tf.Variable 'Variable_3:<...>=(64,) 
 dtype=float32_ref>
 b_conv3                      RefVariable       <tf.Variable 'Variable_5:<...>(128,) 
 dtype=float32_ref>
 b_conv4                      RefVariable       <tf.Variable 'Variable_7:<...>(256,) 
 dtype=float32_ref>
 b_fc1                        RefVariable       <tf.Variable 'Variable_9:<...>9216,) 
 dtype=float32_ref>
 b_fc2                        RefVariable       <tf.Variable 'Variable_11<...>e=(1,) 
 dtype=float32_ref>
  '''

0 个答案:

没有答案