tensorflow错误及解决办法

tf.graph

节点没有数据

tensorflow.python.framework.errors_impl.InvalidArgumentError: Retval[2] does not have value.

通过TensorFlow Retval[0] does not have value启发,怀疑是通过tf.cond构建网络图的时候,一次只走一个分支,导致另一个分支图没有数据,把tf.cond替换后,果然没有错误了。

图过大

GraphDef不能大于2GB
这个错误很多人指向重复的定义tf.constant导致的,我遇到该错误,本质原因也是这个,我使用tf.data.Dataset.from_tensor_slices,该对象也会将数据存到图上,导致图的size过大。

维度不同

Invalid argument: Incompatible shapes: [2560] vs. [2540]

这个问题很烦人,引起问题的原因可能有很多,输入的维度不一致,后续处理不当导致的维度不一致,都有可能,可以结合batch size猜测下问题原因。

模型评估

自定义auc计算

TypeError: Values of eval_metric_ops must be (metric_value, update_op) tuples

这个问题来自我自定义了auc的计算函数,需要添加一个update_op,参考评估过程中实验者的张量流混淆矩阵修改即可。

数据输入

tf.decode_csv

Unquoted fields cannot have quotes/CRLFs inside

这个错误是tf在解析数据时node DecodeCSV字段中包含双引号导致的,可以设置decode_csv的参数use_quote_delim=False来解决。
tf.decode_csv() error: “Unquoted fields cannot have quotes/CRLFs inside”

tfserving

模型加载不全

报有些变量没有初始化,这里是因为模型传送没有完成,tfserving就读取,有部分权重没有读取到。这种情况在模型较大传输速度较慢时可能容易出现。

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.FAILED_PRECONDITION
	details = "Attempting to use uninitialized value dnn/dnn_layer_1/batch_normalization/beta/part_0
	 [[{{node dnn/dnn_layer_1/batch_normalization/beta/part_0/read}}]]"
	debug_error_string = "UNKNOWN:Error received from peer ipv4:10.133.13.16:8500 {grpc_message:"Attempting to use uninitialized value dnn/dnn_layer_1/batch_normalization/beta/part_0\n\t [[{{node dnn/dnn_layer_1/batch_normalization/beta/part_0/read}}]]", grpc_status:9, created_time:"2023-07-20T12:31:15.5256888+00:00"}"

模型签名对不上

模型保存时的签名key没有对应上,对应signature_def_map的key,可以采用默认的tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY="serving_default"

Serving signature key \"serving_default\" not found.

op不存在

这个问题有很多情况,我这里是使用阿里DeepRec保存的模型,SparseApplyAdam是DeepRec加速优化的算子,所以我重新用DeepRec提供的tfserving编译解决问题。

Not found: Op type not registered 'SparseApplyAdam' in binary running on

你可能感兴趣的:(Tensorflow,tensorflow,人工智能,python)