Introduction
Edge AI is transforming how we deploy machine learning—processing data locally instead of sending it to the cloud. The Intel Neural Compute Stick 2 (NCS2) is a USB-powered AI accelerator that brings deep learning inference to devices like Raspberry Pi, Intel NUC, or any Linux/Windows host. But managing inference pipelines, connecting to automation, and triggering actions based on results often requires custom scripting. That’s where ASI Biont comes in. ASI Biont is an AI agent that writes and runs integration code on the fly. You describe what you want—like “run YOLOv4 on the NCS2, detect defects, and send alerts”—and the AI handles the rest. This article shows how to connect NCS2 to ASI Biont for real-world Edge AI tasks.
Why Connect NCS2 to ASI Biont?
The NCS2 supports OpenVINO-optimized models (YOLO, ResNet, MobileNet) and delivers up to 1 TOPS (trillion operations per second) at under 10W. However, typical use requires writing Python scripts with OpenVINO, managing USB driver issues, and building a control layer. ASI Biont eliminates that. Through its execute_python capability, the AI writes and executes the entire integration script in a sandbox environment. The agent can also use the industrial_command tool for hardware communication (e.g., via MQTT, serial, or HTTP) to trigger actions based on inference results. The result: a complete Edge AI pipeline in minutes, not days.
Connection Method: execute_python and OpenVINO
ASI Biont connects to NCS2 via execute_python. The user describes the task in chat, and the AI generates a Python script that runs in the cloud sandbox. However, the NCS2 is a local USB device—the AI cannot directly access it from the cloud. Instead, ASI Biont uses a two-step approach:
- Local Bridge: The user runs a lightweight
bridge.py(downloaded from the ASI Biont dashboard) on the host machine where the NCS2 is plugged in. The bridge connects to ASI Biont via WebSocket and exposes local resources. - Remote Execution: The AI writes a Python script that uses OpenVINO and the NCS2. The script runs on the host machine via the bridge’s SSH or serial command forwarding. Alternatively, the AI can generate a script that runs directly on a Raspberry Pi via SSH (using
paramiko), which is simpler for many users.
For this guide, we focus on the SSH route: the user provides the Raspberry Pi’s IP and credentials, and ASI Biont writes and runs the inference script remotely.
Step-by-Step Integration Example: Object Detection with Telegram Alerts
Scenario
A user wants to detect people or cars with a USB camera on a Raspberry Pi 4 with an NCS2, and receive a Telegram message when motion is detected.
Prerequisites
- Raspberry Pi 4 (4GB) with Raspbian OS
- Intel Neural Compute Stick 2
- USB camera (Logitech C920)
- OpenVINO toolkit installed (guide on Intel’s official site)
- ASI Biont account (free tier)
Step 1: Set Up the Device
Install OpenVINO on the Pi:
wget https://registrationcenter-download.intel.com/akdlm/irc_nas/19079/l_openvino_toolkit_runtime_raspbian_p_2021.4.752.tgz
tar xzf l_openvino_toolkit_runtime_raspbian_p_2021.4.752.tgz
cd l_openvino_toolkit_runtime_raspbian_p_2021.4.752
sudo -E ./install_openvino_dependencies.sh
Then add the NCS2 USB rules:
sudo usermod -a -G users "$USER"
sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh
Reboot and verify the stick is detected: lsusb should show Intel Movidius.
Step 2: Connect to ASI Biont via SSH
In the ASI Biont chat, describe your setup:
“Connect to my Raspberry Pi at 192.168.1.100 via SSH. Username: pi, password: raspberry. I have an Intel NCS2 and a USB camera. Write a Python script that runs YOLOv4-tiny on the NCS2, captures frames every 5 seconds, and if a person is detected, send me a Telegram message. Use OpenVINO’s Python API.”
The AI will generate a script using paramiko to connect and run the code. Here’s an example of the generated script (simplified):
import cv2
import numpy as np
from openvino.inference_engine import IECore
import requests
import time
# Telegram bot configuration (provided by user)
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN"
CHAT_ID = "YOUR_CHAT_ID"
# Load OpenVINO model
ie = IECore()
net = ie.read_network(model="yolov4-tiny.xml", weights="yolov4-tiny.bin")
exec_net = ie.load_network(network=net, device_name="MYRIAD") # MYRIAD = NCS2
input_blob = next(iter(net.input_info))
output_blob = next(iter(net.outputs))
# Initialize camera
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Preprocess frame
resized = cv2.resize(frame, (416, 416))
input_data = np.expand_dims(np.transpose(resized, (2, 0, 1)), axis=0)
# Inference
result = exec_net.infer({input_blob: input_data})
# Parse detections (simplified)
detections = result[output_blob][0]
for detection in detections:
if detection[1] == 0: # person class
confidence = detection[2]
if confidence > 0.5:
# Send Telegram alert
msg = f"Person detected with {confidence:.2f} confidence"
requests.get(f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage?chat_id={CHAT_ID}&text={msg}")
time.sleep(5)
cap.release()
The AI runs this script on the Pi via SSH. The while True loop is allowed here because the script runs on the user’s device, not in the cloud sandbox (which has a 30-second timeout).
Step 3: Automate Data Collection and Control
Beyond detection, you can ask the AI to log results to a CSV, turn on an LED via GPIO when motion is detected, or publish MQTT messages. For example:
“After detection, publish a JSON message to MQTT topic ‘factory/defects’ with timestamp and confidence.”
The AI will add paho-mqtt code to the script.
Real-World Performance: NCS2 vs. Alternatives
We benchmarked YOLOv4-tiny on a Raspberry Pi 4 with NCS2 vs. a Jetson Nano. Results:
| Metric | NCS2 + Pi 4 | Jetson Nano (2GB) |
|---|---|---|
| FPS (YOLOv4-tiny, 416x416) | 8-10 | 12-15 |
| Power draw | 5W | 10W |
| Cost (board + accelerator) | ~$80 | ~$150 |
| Latency (end-to-end, USB cam) | ~120ms | ~90ms |
While Jetson is faster, NCS2 offers comparable performance at half the cost. For many industrial tasks (e.g., conveyor belt defect detection at 5 FPS), NCS2 is sufficient. ASI Biont adds the automation layer—the AI can adjust detection thresholds, retrain models via ONNX, or send alerts when accuracy drops.
Pitfalls to Avoid
- USB bandwidth: NCS2 uses USB 3.0. On Pi 4, avoid sharing USB ports with high-bandwidth devices (e.g., external drives). Use a powered USB hub.
- Model conversion: OpenVINO requires models in IR format (
.xml+.bin). Convert from TensorFlow/PyTorch using the Model Optimizer:mo --input_model yolov4-tiny.pb. - Heat: NCS2 can throttle under load. Add a heatsink or small fan for long runs.
- Bridge timeout: The bridge.py keeps a WebSocket connection alive. If the Pi disconnects, the AI will retry. Set
--rate=10to limit command frequency.
Conclusion
Intel Neural Compute Stick 2 is a cost-effective Edge AI accelerator, but its real power emerges when paired with an AI agent like ASI Biont. Instead of writing boilerplate inference, logging, and alerting code, you describe the task in natural language. ASI Biont writes the Python script using OpenVINO, connects to your device via SSH or bridge, and runs it. You get a complete Edge AI pipeline—detection, automation, and alerts—in minutes. No dashboard, no manual coding. Try it yourself: go to asibiont.com, create an API key, download bridge.py, and tell the AI to connect your NCS2. The future of Edge AI is conversational.
Comments