onnx_example.py 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# ******************************************************************************
# Copyright 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************

import onnx

onnx_protobuf = onnx.load('/path/to/model/cntk_ResNet20_CIFAR10/model.onnx')
20

21
# Convert a serialized ONNX model to an ngraph model
22 23
from ngraph_onnx.onnx_importer.importer import import_onnx_model
ng_model = import_onnx_model(onnx_protobuf)[0]
24

25

26 27
# Using an ngraph runtime (CPU backend), create a callable computation
import ngraph as ng
28
runtime = ng.runtime(backend_name='CPU')
29
resnet = runtime.computation(ng_model['output'], *ng_model['inputs'])
30

31 32 33
# Load or create an image
import numpy as np
picture = np.ones([1, 3, 32, 32])
34

35 36
# Run ResNet inference on picture
resnet(picture)
37