遇到的情况是在linux_aarch64下编译的程序(使用tensorflow pb文件做预测),在执行时报错:
Traceback (most recent call last):
......
File "google/protobuf/message.py", line 199, in ParseFromString
File "google/protobuf/internal/python_message.py", line 1145, in MergeFromString
File "google/protobuf/internal/python_message.py", line 1212, in InternalParse
File "google/protobuf/internal/decoder.py", line 731, in DecodeRepeatedField
google.protobuf.message.DecodeError: Truncated message.
[32503] Failed to execute script
奇怪的是源码运行是ok,但编译后的程序执行报错。
经检查是读取pb时出错,例如:graph_def.ParseFromString(f.read())
再看错误具体原因:DecodeRepeatedField
decode...看来可能是字符集的坑。
怀疑是文件读取后异常,大概率是字符集问题,查看并尝试修改系统字符集
通过locale命令看到系统字符集是zh_CN.UTF-8
修改为 en_US.UTF-8后,执行一切正常。
LANG=en_US.UTF-8