-
Notifications
You must be signed in to change notification settings - Fork 729
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
Changes from 1 commit
467c0cf
b5c7c25
e975ac6
782c75f
df55a76
beddf0d
ea85c9a
17eb177
b4681d1
4fa2682
e4e9cda
64293d7
e0d1986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sys | ||
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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
help="The number of partitions") | ||
|
||
(options, args) = parser.parse_args(sys.argv) | ||
|
||
predict(options.model_path, options.img_path, options.partition_num) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a blank line at the end of file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add copyright https://github.com/intel-analytics/analytics-zoo/blob/master/pyzoo/zoo/examples/openvino/predict.py#L1