|
这两天在跟着教程做openpose移植到rknn,模型转换挺顺利的,在x86上模拟时,能够得到正确结果,但是推理时间需要1000多秒。
问题在于,将转换好的模型放到3399pro上以后,在3399pro上推理得到的output全部为0,代码和模型都是一样的,检查了好几遍。两边的rknn-toolkit版本也都是1.6.0,请问一下可能是什么原因导致的啊?
我尝试的是单人openpose检测.以下是转换代码和处理代码
from rknn.api import RKNN
import cv2
import time
import numpy as np
if __name__ == '__main__':
# Create RKNN object
rknn = RKNN()
# pre-process config
print('--> config model')
rknn.config(channel_mean_value='0 0 0 255', reorder_channel='2 1 0')
print('done')
# Load tensorflow model
print('--> Loading model')
ret = rknn.load_caffe(model='openpose-master/openpose-master/models//pose/coco/pose_deploy_linevec.prototxt', proto='caffe',
blobs='openpose-master/openpose-master/models//pose/coco/pose_iter_440000.caffemodel')
if ret != 0:
print('Load model failed!')
exit(ret)
print('done')
# Build model
print('--> Building model')
ret = rknn.build(do_quantization=True, dataset='./dataset.txt', pre_compile=False)
if ret != 0:
print('Build model failed!')
exit(ret)
print('done')
# Export rknn model
print('--> Export RKNN model')
ret = rknn.export_rknn('./0.rknn')
if ret != 0:
print('Export model failed!')
exit(ret)
print('done')
rknn.release()
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
from rknn.api import RKNN
import cv2
import time
import numpy as np
if __name__ == '__main__':
nPoints = 18
POSE_PAIRS = [ [1,0],[1,2],[1,5],[2,3],[3,4],[5,6],[6,7],[1,8],[8,9],[9,10],[1,11],[11,12],[12,13],[0,14],[0,15],[14,16],[15,17]]
# Create RKNN object
rknn = RKNN()
rknn.load_rknn('./0.rknn')
# init runtime environment
print('--> Init runtime environment')
ret = rknn.init_runtime()
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
# input image dimensions for the network
inWidth = 368
inHeight = 368
#hasFrame, frame = cap.read()
if True:
t = time.time()
#hasFrame, frame = cap.read()
#frame = cv2.resize(frame, (inWidth, inHeight), interpolation=cv2.INTER_CUBIC)
frame = cv2.imread('pose.jpg')
#if not hasFrame:
# cv2.waitKey()
# break
frame = cv2.resize(frame,(368,368))
frameCopy = np.copy(frame)
#frameCopyO = np.copy(frame)
frameWidth = frame.shape[1]
frameHeight = frame.shape[0]
threshold = 0.1
t = time.time()
#print("frame shape", frame.shape)
np.set_printoptions(threshold=np.inf)
# Inference
#print('--> Running model')
frameinput = np.transpose(frame, [2, 0, 1])
#np.savetxt("input.txt", [frameinput],fmt='%f',delimiter=',')
print([frameinput])
t = time.time()
[output] = rknn.inference(inputs=[frameinput], data_format="nchw")
print([output])
elapsed = time.time() - t
print('inference image: %.4f seconds.' % (elapsed))
np.set_printoptions(threshold=np.inf)
#print('done')
output = output.reshape(1, 57, 46, 46)
H = output.shape[2]
W = output.shape[3]
# Empty list to store the detected keypoints
points = []
for i in range(nPoints):
# confidence map of corresponding body's part.
probMap = output[0, i, :, :]
# Find global maxima of the probMap.
minVal, prob, minLoc, point = cv2.minMaxLoc(probMap)
# Scale the point to fit on the original image
x = (frameWidth * point[0]) / W
y = (frameHeight * point[1]) / H
if prob > threshold :
cv2.circle(frame, (int(x), int(y)), 8, (0, 255, 255), thickness=-1, lineType=cv2.FILLED)
cv2.putText(frame, "{}".format(i), (int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, lineType=cv2.LINE_AA)
# Add the point to the list if the probability is greater than the threshold
points.append((int(x), int(y)))
else :
points.append(None)
# Draw Skeleton
for pair in POSE_PAIRS:
partA = pair[0]
partB = pair[1]
if points[partA] and points[partB]:
cv2.line(frameCopy, points[partA], points[partB], (0, 255, 255), 2)
cv2.circle(frameCopy, points[partA], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)
Keypoint = 'Output-Keypoints'
#cv2.namedWindow(Keypoint, cv2.WINDOW_NORMAL)
#cv2.imshow(Keypoint, frame)
#cv2.imshow(Keypoint, frameCopy)
cv2.imwrite('o2.jpg',frameCopy)
#cv2.imwrite('Output-Keypoints.jpg', frameCopy)
#cv2.imwrite('Output-Skeleton.jpg', frame)
#print("Total time taken : {:.3f}".format(time.time() - t))
#vid_writer.write(frameCopyO)
#vid_writer.release()
rknn.release()
|
|