测试环境为 Tensorflow2.9.3 + DTK23.04.1,对一个简单的tensorflow程序进行打包:
import os
import tensorflow
import tensorflow.compat.v1 as tf
import numpy as np
import cv2
from matplotlib import pyplot as plt
import glob
class CarplateMask(object):
INPUT_NAME = 'input:0'
YOLO_NAME = 'output:0'
def __init__(self, frozen_graph):
self.graph = tf.Graph()
graph_def = tf.GraphDef()
with tf.gfile.GFile(frozen_graph, 'rb') as fid:
serialized_graph = fid.read()
graph_def.ParseFromString(serialized_graph)
with self.graph.as_default():
tf.import_graph_def(graph_def, name='')
self.sess = tf.Session(graph=self.graph)
def run(self, image):
preds = self.sess.run([self.YOLO_NAME], feed_dict={self.INPUT_NAME: image})
return preds
if __name__ == "__main__":
import time
model = CarplateMask('/home/yolov5.tensorflow/carplate20230627.pb')
for file in glob.glob('/home/yolov5.tensorflow/imgs/*.jpg')[:]:
print("start")
image_ori = cv2.imread(file)
image = image_ori.copy()
image = cv2.resize(image,(640, 640))
start_time = time.time()
pred = model.run(np.expand_dims(image/255, 0))[0]
elapsed_time = time.time() - start_time
print("end, elapsed: ",elapsed_time)
直接执行python程序可以正常执行,进行pyinstaller detect.py后,执行 ./dist/detect/detect 文件显示设备初始话错误:

pyinstaller进行打包时,会将很多库打包进 ./dist/{project}/_internal/ 内,本例中重复打包了DTK runtime动态库 libgalaxyhip.so.5 ,导致重复链接。删除 ./dist/detect/_internal/libgalaxyhip.so.5 后,执行恢复正常。
暂无数据
暂无数据