- dynamic computation graph (beta)
- add supports (/express)
- add tests
- add benchmarks with it (/benchmark/exprModels)
- Python
- MNN engine and tools were submitted to pip
- available on Windows/macOS/Linux
- Engine/Converter
- add supports for each op benchmarking
- refactor optimizer by separating steps
- CPU
- add supports for Conv3D, Pool3D, ELU, ReverseSequence
- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
- add half transform in CPU
- add broadcast supports for binary
- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
- add sub, real div supports for binary
- add supports for unary
- optimize Conv2D, Reshape
- Vulkan
- add max supports for eltwise
- Metal
- fix metallib missing problem
- Train/Quantization
- use express to refactor training codes
2019-09-26 21:02:07 +08:00
|
|
|
# Copyright @ 2019 Alibaba. All rights reserved.
|
|
|
|
# Created by ruhuan on 2019.09.09
|
|
|
|
""" python demo usage about MNN API """
|
|
|
|
from __future__ import print_function
|
|
|
|
import numpy as np
|
|
|
|
import MNN
|
|
|
|
import cv2
|
|
|
|
def inference():
|
|
|
|
""" inference mobilenet_v1 using a specific picture """
|
|
|
|
interpreter = MNN.Interpreter("mobilenet_v1.mnn")
|
|
|
|
session = interpreter.createSession()
|
|
|
|
input_tensor = interpreter.getSessionInput(session)
|
|
|
|
image = cv2.imread('ILSVRC2012_val_00049999.JPEG')
|
|
|
|
#cv2 read as bgr format
|
|
|
|
image = image[..., ::-1]
|
|
|
|
#change to rgb format
|
|
|
|
image = cv2.resize(image, (224, 224))
|
|
|
|
#resize to mobile_net tensor size
|
|
|
|
image = image - (103.94, 116.78, 123.68)
|
|
|
|
image = image * (0.017, 0.017, 0.017)
|
|
|
|
#preprocess it
|
|
|
|
image = image.transpose((2, 0, 1))
|
2020-06-15 14:56:22 +08:00
|
|
|
#change numpy data type as np.float32 to match tensor's format
|
|
|
|
image = image.astype(np.float32)
|
- dynamic computation graph (beta)
- add supports (/express)
- add tests
- add benchmarks with it (/benchmark/exprModels)
- Python
- MNN engine and tools were submitted to pip
- available on Windows/macOS/Linux
- Engine/Converter
- add supports for each op benchmarking
- refactor optimizer by separating steps
- CPU
- add supports for Conv3D, Pool3D, ELU, ReverseSequence
- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
- add half transform in CPU
- add broadcast supports for binary
- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
- add sub, real div supports for binary
- add supports for unary
- optimize Conv2D, Reshape
- Vulkan
- add max supports for eltwise
- Metal
- fix metallib missing problem
- Train/Quantization
- use express to refactor training codes
2019-09-26 21:02:07 +08:00
|
|
|
#cv2 read shape is NHWC, Tensor's need is NCHW,transpose it
|
|
|
|
tmp_input = MNN.Tensor((1, 3, 224, 224), MNN.Halide_Type_Float,\
|
|
|
|
image, MNN.Tensor_DimensionType_Caffe)
|
|
|
|
input_tensor.copyFrom(tmp_input)
|
|
|
|
interpreter.runSession(session)
|
|
|
|
output_tensor = interpreter.getSessionOutput(session)
|
2020-06-15 14:56:22 +08:00
|
|
|
#constuct a tmp tensor and copy/convert in case output_tensor is nc4hw4
|
|
|
|
tmp_output = MNN.Tensor((1, 1001), MNN.Halide_Type_Float, np.ones([1, 1001]).astype(np.float32), MNN.Tensor_DimensionType_Caffe)
|
|
|
|
output_tensor.copyToHostTensor(tmp_output)
|
- dynamic computation graph (beta)
- add supports (/express)
- add tests
- add benchmarks with it (/benchmark/exprModels)
- Python
- MNN engine and tools were submitted to pip
- available on Windows/macOS/Linux
- Engine/Converter
- add supports for each op benchmarking
- refactor optimizer by separating steps
- CPU
- add supports for Conv3D, Pool3D, ELU, ReverseSequence
- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
- add half transform in CPU
- add broadcast supports for binary
- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
- add sub, real div supports for binary
- add supports for unary
- optimize Conv2D, Reshape
- Vulkan
- add max supports for eltwise
- Metal
- fix metallib missing problem
- Train/Quantization
- use express to refactor training codes
2019-09-26 21:02:07 +08:00
|
|
|
print("expect 983")
|
2020-06-15 14:56:22 +08:00
|
|
|
print("output belong to class: {}".format(np.argmax(tmp_output.getData())))
|
- dynamic computation graph (beta)
- add supports (/express)
- add tests
- add benchmarks with it (/benchmark/exprModels)
- Python
- MNN engine and tools were submitted to pip
- available on Windows/macOS/Linux
- Engine/Converter
- add supports for each op benchmarking
- refactor optimizer by separating steps
- CPU
- add supports for Conv3D, Pool3D, ELU, ReverseSequence
- fix ArgMax, Permute, Scale, BinaryOp, Slice, SliceTf
- OpenCL
- add half transform in CPU
- add broadcast supports for binary
- optimize Conv2D, Reshape, Eltwise, Gemm, etc.
- OpenGL
- add sub, real div supports for binary
- add supports for unary
- optimize Conv2D, Reshape
- Vulkan
- add max supports for eltwise
- Metal
- fix metallib missing problem
- Train/Quantization
- use express to refactor training codes
2019-09-26 21:02:07 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
inference()
|