当前位置:网站首页>Openvino2022 dev tools installation and use

Openvino2022 dev tools installation and use

2022-06-24 20:17:00 Opencv school

Click on the blue words above to follow us

WeChat official account :OpenCV School Focus on getting more computer vision and deep learning knowledge

introduction

OpenVINO2022 After the release , Make a clear division of the functions of previous versions , Which still passes exe The way to install the program is runtime Inference package , Support ONNX、IR、PADDLE Wait for model reading and reasoning . But model optimization transformation 、 Other functions, such as the model library download function, are divided into one called Dev Tool Part of . This part can be passed through pip Way to install directly , Then direct the line through the command line , Complete the model transformation , Download and other operations , Compared with previous versions, the usability has been greatly improved ! Make a comparison as follows :

Dev Tools Installation and use

Dev Tools Easy to install , You can choose to install directly through the command line of the official script , The only thing to note is the choice of model framework support , I chose ONNX/Pytorch Format conversion support , The installed command line is as follows :

pip install openvino-dev[onnx,pytorch]==2022.1.0

After executing this command line, the installation is completed , As long as the network is not connected, the installation can be successful !

installation is complete , Change one ONNX The format model is IR Format (xml/bin) file , With Pytorch Of ResNet18 For example , First convert to ONNX, The code is as follows :

model = models.resnet18(pretrained=True) model.eval() model.cpu()
 dummy_input1 = torch.randn(1, 3, 224, 224) torch.onnx.export(model, (dummy_input1), "resnet_model.onnx", verbose=True)

Then run the command line directly to convert IR Format file , The screenshot is as follows :

Model download

installation is complete Dev Tools after , Download model , Just execute the command line : Examples are as follows :

omz_downloader --name person-detection-0200

Means downloading the model  person-detection-0200  It is a lightweight face detection model .

omz_downloader  Supported parameters :

--all Means to download all models , Don't do this !--name  Download one or more models with the specified names , Recommended !--precisions  Represents the downloaded model accuracy parameters , Support FP32/FP18/INT8

Python SDK Use

Before comparison Python Version of SDK, It works a lot , The most obvious feeling is that there is no need to read input and output , Then a bunch of settings , For a single I / O network , The call is especially simple and convenient ! It's easier for developers to get started ! I have successfully converted one above pytorch The image classification model is IR Format , You can use it now , be based on OpenVINO2022 The latest version Python SDK Deployment call , The implementation code is as follows :

#  Load tag data 
with open('imagenet_classes.txt') as f:
    labels = [line.strip() for line in f.readlines()]


def resnet_demo():
    ie = Core()
    # model = ie.read_model(model="resnet_model.onnx")
    model = ie.read_model(model="resnet_model.xml")
    compiled_model = ie.compile_model(model=model, device_name="CPU")

    output_layer = compiled_model.output(0)

    means = np.zeros((224, 224, 3), dtype=np.float32)
    means[: ,:] = (0.485, 0.456, 0.406)
    dev = np.zeros((224, 224, 3), dtype=np.float32)
    dev[: ,:] = (0.229, 0.224, 0.225)

    image = cv.imread("D:/images/space_shuttle.jpg")
    rgb = cv.cvtColor(image, code=cv.COLOR_BGR2RGB)

    # resize to MobileNet image shape
    input_image = cv.resize(src=rgb, dsize=(224, 224))
    blob_img = np.float32(input_image) / 255.0
    input_x = (blob_img - means) / dev
    input_x = input_x.transpose((2, 0, 1))
    input_x = np.expand_dims(input_x, 0)
    print(input_x.shape)

    result_infer = compiled_model([input_x])[output_layer]
    result_index = np.argmax(result_infer)
    cv.putText(image, labels[result_index], (20, 50), cv.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255), 2)

    cv.imshow("OpenVINO2022 + Pythorch ResNet18", image)
    cv.waitKey(0)
    cv.destroyAllWindows()


if __name__ == "__main__":
    resnet_demo()

Scan the code to check OpenCV+OpenVIO+Pytorch Systematic learning roadmap

  Recommended reading  

CV The full stack developer said - From traditional algorithm to deep learning, how to practice

2022 Pit depth learning , I choose Pytorch frame !

Pytorch Easily achieve classic visual tasks

Tutorial recommendation | Pytorch frame CV Development - From introduction to practice

OpenCV4 C++ Study Essential basic grammar knowledge 3

OpenCV4 C++ Study Essential basic grammar knowledge 2

OpenCV4.5.4 Face detection + Five o'clock landmark New functional testing

OpenCV4.5.4 Detailed explanation of face recognition and code demonstration

OpenCV Of binary image analysis Blob Analyze and find the circle

OpenCV4.5.x DNN + YOLOv5 C++ Reasoning

OpenCV4.5.4 Direct support for YOLOv5 6.1 Version model reasoning

OpenVINO2021.4+YOLOX Target detection model deployment test

Than YOLOv5 Not bad YOLOX coming , Official support OpenVINO Reasoning

原网站

版权声明
本文为[Opencv school]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241900534292.html