First, I run the following codes on rk3399 for object detection:
https://gluon-cv.mxnet.io/build/examples_detection/demo_webcam.html
it’s detection speed is about 10fps, just including frame capture, data transform, and inference. NO Disppay.
However, when use the TVM to compile the model for detection, its speed is about 2fps !!
The following is the compile codes:
#--------------------------------------------- Local PC --------------------------------------------------
block = model_zoo.get_model(“ssd_512_mobilenet1.0_voc”, pretrained=True)
dshape = (1, 3, 240, 320)
net, params = relay.frontend.from_mxnet(block, {“data”: dshape})
opt_level = 3
target = tvm.target.create(‘llvm -device=arm_cpu -target=aarch64-linux-gnu’)
with relay.build_config(opt_level=opt_level):
graph, lib, params = relay.build(net, target, params=params)
#----------------------------------------------- RK3399 -------------------------------------------------
slight_smile: ctx = tvm.cpu()
m = graph_runtime.create(loaded_graph, loaded_lib, ctx)
m.load_params(loaded_params)
axes = None
cap = cv2.VideoCapture(0)
cap.set(3, 320)
cap.set(4, 240)
while(True):
start = time.time()
# Capture frame-by-frame
ret, frame = cap.read()
# Image pre-processing
frame = mx.nd.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).astype('uint8')
rgb_nd, frame = gcv.data.transforms.presets.ssd.transform_test(frame, short=240, max_size=480)
# Do inference
tvm_input = tvm.nd.array(rgb_nd.asnumpy(), ctx=ctx)
m.set_input('data', tvm_input)
# execute
m.run()
# get outputs
class_IDs, scores, bounding_boxs = m.get_output(0), m.get_output(1), m.get_output(2)
# Compute the fps
end = time.time()
seconds = end - start
fps = 1 / seconds
print("Estimated frames per second : {0}".format(fps))
# Display result
plt.cla()
axes = gcv.utils.viz.plot_bbox(frame, bounding_boxs.asnumpy()[0], scores.asnumpy()[0], class_IDs.asnumpy()[0], class_names=block.classes, ax=axes)
# plt.draw()
plt.pause(0.001)