I am writing an application in Python which should be auto started after system booting.
My device is RPi 3B+ running headless Raspbian Stretch.
I had successfully autorun an app which used NCS 1 with Movidius API. I was using systemd service for the task without any problems.
Unlike the old NCS 1 API, the OpenVINO environment has to been initialized before running the app. I tried to use systemd services to run `/opt/intel/openvino/bin/setupvars.sh` but got no luck.
I also tried to include all the path generated by `/opt/intel/openvino/bin/setupvars.sh` in my Python app by `sys.path.append()`. It passed the `import openvino` part but failed at `import openvino.inference_engine`. The error message was like the following:
import openvino.inference_engine File "/opt/intel/openvino/python/python3.5/openvino/inference_engine/__init__.py", line 1, in <module> from .ie_api import * ImportError: libinference_engine.so: cannot open shared object file: No such file or directory
Is it possible to initialize OpenVINO and then run its applications automatically after booting?
Hi Tenn, Hian-Kun,
In addition to Shuba's comment, another alternative you can try is to initialize the OpenVINO environment variables using and execute your Python application using a bash script. I have tried this myself using the benchmark_app.py Python sample and seems to work fine on RPi 3 Model B+ for Raspbian Stretch. The steps below assume you have OpenVINO installed and you have verified the installation.
This is how I've done it but I'd strongly suggest to take a look at the resource Shuba shared, so you get more insight on how to implement a system service. Some steps require root privileges which is why sudo is given. Also for this system service some tools/files need to be installed and downloaded to the device, so that this particular system service works. You may decide if you'd like to try it or just use it as reference for your requirements. Hope you find this helpful.
1. Install tools for benchmark_app.py and download necessary files:
sudo pip install progress cd ~/ wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R1/models_bin/face-detection-adas-0001/FP16/face-... wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R1/models_bin/face-detection-adas-0001/FP16/face-... wget https://pixabay.com/images/download/human-740259_640.jpg
2. Create bash script; initialize environment variables and execute Python script:
#!/bin/bash source /opt/intel/openvino/bin/setupvars.sh /usr/bin/python3 /opt/intel/openvino/deployment_tools/inference_engine/samples/python_samples/benchmark_app/benchmark_app.py -i /home/pi/human-740259_640.jpg -m /home/pi/face-detection-adas-0001.xml -d MYRIAD
3. Change file permissions and ownership to script:
chmod u+x ~/openvino-benchmark-app-script
4. Create service file under /etc/systemd/system with contents as shown below:
sudo vi /etc/systemd/system/openvino-benchmark-app.service
[Unit] Description=Init OpenVINO env and run python benchmark_app After=network.target [Service] ExecStart=/home/pi/openvino-benchmark-app-script WorkingDirectory=/home/pi StandardOutput=inherit StandardError=inherit Restart=on-failure User=pi [Install] WantedBy=multi-user.target
5. Enable service to start at boot and start system service:
sudo systemctl enable openvino-benchmark-app.service sudo systemctl start openvino-benchmark-app.service
6. To check system service status:
sudo systemctl status openvino-benchmark-app.service
7. To disable service during boot time, stop service first and then disable it:
sudo systemctl stop openvino-benchmark-app.service sudo systemctl disable openvino-benchmark-app.service
So many thanks to your informative answers and sorry for my late reply.
I've figured out the solution after the day I posted the question. Just as what Luis mentioned, I need to put the initialization and the Python running commands in the same bash script, then let systemctl service run the script. Everything works like a charm.
In my previous (and failed) approach, I wrongly let systemctl service run the initialization and the Python programs one by one. And it won't do anything right.