前の投稿でOpenVINO用に変換したモデルを、OpenVINOの推論エンジンIneference Engineに取り込みます。
以下のコードFeedToIE.pyを実行します。
import os
from openvino.inference_engine import IENetwork, IECore
import argparse
def get_args():
'''
Gets the arguments from the command line.
'''
parser = argparse.ArgumentParser("Load an IR into the Inference Engine")
# -- Create the descriptions for the commands
m_desc = "The location of the model XML file"
# -- Create the arguments
parser.add_argument("-m", help=m_desc)
args = parser.parse_args()
return args
def load_to_IE(model_xml):
### Load the Inference Engine API
plugin = IECore()
### Load IR files into their related class
model_bin = os.path.splitext(model_xml)[0] + ".bin"
net = IENetwork(model=model_xml, weights=model_bin)
### Get the supported layers of the network
supported_layers = plugin.query_network(network=net, device_name="CPU")
### Check for any unsupported layers, and let the user
### know if anything is missing. Exit the program, if so.
unsupported_layers = [l for l in net.layers.keys() if l not in supported_layers]
if len(unsupported_layers) != 0:
print("Unsupported layers found: {}".format(unsupported_layers))
print("Check whether extensions are available to add to IECore.")
exit(1)
### Load the network into the Inference Engine
plugin.load_network(net, "CPU")
print("IR successfully loaded into Inference Engine.")
return
def main():
args = get_args()
load_to_IE(args.m)
if __name__ == "__main__":
main()
を実行すると、
$ python FeedToIE.py -m /home/hajime/git/nd131-openvino-fundamentals-project-starter/convertModels/nvidia_ssd.xml
/home/hajime/anaconda3/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.6 of module 'openvino.inference_engine.ie_api' does not match runtime version 3.7
return f(*args, **kwds)
FeedToIE.py:27: DeprecationWarning: Reading network using constructor is deprecated. Please, use IECore.read_network() method instead
net = IENetwork(model=model_xml, weights=model_bin)
IR successfully loaded into Inference Engine.
として推論エンジンにロードできました。以前は、これが失敗していたのですが、いろいろ調べていたら2019R3と今回インストールした2020R2とでは依存するライブラリに変更があったりと、そのあたりを修正したら動作するようになりました。
これで、PCでテストしてからRasPiで運用という流れができそうです。
この時点で、性能面の心配は残りますが、NVIDIAの高いマシンで学習されたモデルをダウンロードしてきて、それと比べるとチープなRasPi+Intel NCS2で推論実行という流れが確立できたらいいなと考えています。
コメント