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

OpenVINO resnet_50_v1 python example with VNNI #1582

Merged
merged 13 commits into from
Aug 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions pyzoo/zoo/examples/vnni/openvino/inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from optparse import OptionParser
import numpy as np

from zoo.pipeline.inference import InferenceModel
from zoo.common.nncontext import init_nncontext
from zoo.feature.image import *
from zoo.pipeline.nnframes import *



def predict(model_path, img_path, partition_num):
model = InferenceModel()
model.load_openvino(model_path,
weight_path=model_path[:model_path.rindex(".")] + ".bin")
sc = init_nncontext("OpenVINO Object Detection Inference Example")
infer_transformer = ChainedPreprocessing([ImageBytesToMat(),
ImageResize(256,256),
ImageCenterCrop(224,224),
ImageMatToTensor(format="NHWC", to_RGB=True)
])
image_set = ImageSet.read(img_path, sc, partition_num).transform(infer_transformer).get_image().collect()
image_set = np.expand_dims(image_set, axis=1)

predictions = model.predict(image_set)

result = np.swapaxes(predictions,0,1)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style.


for r in result:
output = {}
max_index = np.argmax(r)
output["Top-1"] = str(max_index)
print("* Predict result " + str(output))


if __name__ == "__main__":
parser = OptionParser()
parser.add_option("--image", type=str, dest="img_path",
help="The path where the images are stored, "
"can be either a folder or an image path")
parser.add_option("--model", type=str, dest="model_path",
help="Zoo Model Path")
parser.add_option("--partition_num", type=int, dest="partition_num", default=4,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think partition_num is necessary. Because current example is a local example. :)

help="The number of partitions")

(options, args) = parser.parse_args(sys.argv)

predict(options.model_path, options.img_path, options.partition_num)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line at the end of file.