How do I install MNN on a Raspberry Pi 3 to make it work?
OS Raspbian
I have already used 3 instructions for installation, 2 of them are official from github. 1 of them did not work at all, and the other 2 as a result of running one ready-made project (for which MNN is installed) give the following error:
AtrributeError: module 'MNN' has no attribute 'Interpreter'
.
Although according to the documentation, it is. That is, the library is not installed correctly.
Code snippet where the error occurs:
def inference():
input_size = [int(v.strip()) for v in args.input_size.split(",")]
priors = define_img_size(input_size)
result_path = args.results_path
imgs_path = args.imgs_path
if not os.path.exists(result_path):
os.makedirs(result_path)
listdir = os.listdir(imgs_path)
for file_path in listdir:
img_path = os.path.join(imgs_path, file_path)
image_ori = cv2.imread(img_path)
interpreter = MNN.Interpreter(args.model_path)
session = interpreter.createSession()
input_tensor = interpreter.getSessionInput(session)
image = cv2.cvtColor(image_ori, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, tuple(input_size))
image = image.astype(float)
image = (image - image_mean) / image_std
image = image.transpose((2, 0, 1))
tmp_input = MNN.Tensor((1, 3, input_size[1], input_size[0]), MNN.Halide_Type_Float, image, MNN.Tensor_DimensionType_Caffe)
input_tensor.copyFrom(tmp_input)
time_time = time.time()
interpreter.runSession(session)
scores = interpreter.getSessionOutput(session, "scores").getData()
boxes = interpreter.getSessionOutput(session, "boxes").getData()
boxes = np.expand_dims(np.reshape(boxes, (-1, 4)), axis=0)
scores = np.expand_dims(np.reshape(scores, (-1, 2)), axis=0)
print("inference time: {} s".format(round(time.time() - time_time, 4)))
boxes = box_utils.convert_locations_to_boxes(boxes, priors, center_variance, size_variance)
boxes = box_utils.center_form_to_corner_form(boxes)
boxes, labels, probs = predict(image_ori.shape[1], image_ori.shape[0], scores, boxes, args.threshold)
for i in range(boxes.shape[0]):
box = boxes[i, :]
cv2.rectangle(image_ori, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 2)
cv2.imwrite(os.path.join(result_path, file_path), image_ori)
print("result_pic is written to {}".format(os.path.join(result_path, file_path)))
cv2.imshow("UltraFace_mnn_py", image_ori)
cv2.waitKey(-1)
cv2.destroyAllWindows()
0