Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initMNN.expr: PyType_Ready PyMNNVarType failed #1991

Closed
Klawens opened this issue Jul 12, 2022 · 15 comments
Closed

initMNN.expr: PyType_Ready PyMNNVarType failed #1991

Klawens opened this issue Jul 12, 2022 · 15 comments

Comments

@Klawens
Copy link

Klawens commented Jul 12, 2022

An error occurred when running an mnn model inference demo below:

import numpy as np
import MNN
import cv2
import time
class Pose():
    def __init__(self, model_path, joint_num=17, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]):
        self.model_path = model_path
        self.joint_num = joint_num
        self.mean = np.array(mean).reshape(1, -1, 1, 1)
        selaf.std = np.array(std).reshape(1, -1, 1, 1)
        self.interpreter = MNN.Interpreter.createSession({ 'numThread': 1})

    def preprocess(self, img):
        input_shape = img.shape
        assert len(input_shape) == 4, 'expect shape like (1, H, W, C)'
        img = (np.transpose(img, (0, 3, 1, 2)) / 255. -self.mean) / self.std
        return img.astype(np.float32)

    def inference(self, img):
        input_shape = img.shape
        assert len(input_shape) == 4, 'expect shape like (1, C, H, W)'

        input_tensor = self.interpreter.getSessionInput(self.model_sess)

        tmp_input = MNN.Tensor(
                input_shape,
                MNN.Halide_Type_Float,
                img.astype(np.float32),
                MNN.Tensor_DimensionType_Caffe)
        input_tensor.copyFrom(tmp_input)

        self.interpreter.runSession(self.model_sess)
        output_tensor = self.interpreter.getSessionOutputAll(self.model_sess)

        joint_coord = np.array(output_tensor['1022'].getData())

        return joint_coord

    def post_process(self, coords, bbox):
        w = bbox[2] - bbox[0]
        h = bbox[3] - bbox[1]
        target_coords = coords * np.array([w, h])
        target_coords += np.array([bbox[0], bbox[1]])

        return target_coords

    def predict(self, img):
        img = self.preprocess(img)
        # print(img.shape)
        joint_coord = self.inference(img)
        # joint_coord = self.post_process(joint_coord)
        return joint_coord
img = cv2.imread('test.jpg')
img = cv2.resize(img, (256, 256))
inputs = img[None,:]
mnn_model = Pose('tmp-sim.mnn')
for x in range(5):
    s = time.time()
    for i in range(100):
        mnn_model.predict(inputs)
    print(f'elapse {(time.time() - s)*10:.4f} ms')

Log:

Traceback (most recent call last):
  File "MNN_inference.py", line 2, in <module>
    import MNN
  File "/home/lsc/anaconda3/envs/mmpose/lib/python3.8/site-packages/MNN/__init__.py", line 4, in <module>
    from _mnncengine import *
Exception: initMNN.expr: PyType_Ready PyMNNVarType failed
@yyfcc17
Copy link
Collaborator

yyfcc17 commented Jul 12, 2022

version?updated?

@Klawens
Copy link
Author

Klawens commented Jul 12, 2022

version?updated?

2.0.0, latest version

@yyfcc17
Copy link
Collaborator

yyfcc17 commented Jul 12, 2022

cannot reproduce with Python 3.8.13, change python version may solve this problem

@Klawens
Copy link
Author

Klawens commented Jul 12, 2022

cannot reproduce with Python 3.8.13, change python version may solve this problem

It's weird, my 3.8.13 doesn't work but 3.7 works fine

@Vincent630
Copy link

that not the wirdest situation,i got two virtual environment ,which both used python3.8.13,but one of the environment report this error that exactly same with yours,but the other environment run script with mnn sucessully.

@bobo0810
Copy link

The same problem occurs in Python 3.8.8

@Klawens
Copy link
Author

Klawens commented Jul 21, 2022

that not the wirdest situation,i got two virtual environment ,which both used python3.8.13,but one of the environment report this error that exactly same with yours,but the other environment run script with mnn sucessully.

same

@Li-Lai
Copy link

Li-Lai commented Aug 26, 2022

The same problem occurs in Python 3.8.3.

@Loovelj
Copy link

Loovelj commented Sep 1, 2022

The same problem occurs in Python 3.8.5

@wangzhaode
Copy link
Collaborator

@Loovelj @Li-Lai @Klawens @bobo0810 请问你们Linux还是Mac?

@bobo0810
Copy link

bobo0810 commented Sep 1, 2022

@Loovelj @Li-Lai @Klawens @bobo0810 请问你们Linux还是Mac?

linux

@Klawens
Copy link
Author

Klawens commented Sep 1, 2022

@Loovelj @Li-Lai @Klawens @bobo0810 请问你们Linux还是Mac?

Linux, ubuntu 18.04

@www516717402
Copy link

Also get this error in py3.9.12+MNN2.0.0

@Lebhoryi
Copy link

The same problem occurs in Python 3.8.10.
MNN install by xxx.whl

@wangzhaode
Copy link
Collaborator

导致这个问题的原因是numpy版本不正确导致无法初始化,可以卸载并重新安装numpy来解决;
该问题会在下次发布是修复;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants