Maix-II-Dock 是一款边缘级 AIOT 开发板, 基于全志V831芯片,支持常规 Linux 开发, 能够进行硬件AI加速,并且拥有Sipeed 提供的完整的软件生态。
全志 V831芯片, 单核 Cortex-A7 800MHz,64MiB 片内 DDR2 内存, 可以当作Linux 的SOC使用,拥有0.2Tops 算力。
购买了官方启动卡的可以略过此步骤。
在烧录前请先完成以下准备:
烧录工具 PhoenixCard
系统镜像
镜像文件中后缀带有maixhub为MaixPy3专用,且带有Maixhub app
后缀带有maixpy3为MaixPy3专用,且不带有Maixhub app
下文所有描述均基于v831-m2dock-maixhub-0.5.2-20220726镜像
TF卡格式化工具 SD Card Formatter(可选)
adb SDK
#一些常用指令
adb devices #查看可用设备
adb shell #进入终端
adb pull <设备里的文件路径> [电脑上的目录] #从设备下载
adb push <电脑上的文件路径> <设备里的目录> #从电脑上传
MobaXterm 终端管理工具
当以上操作均成功完成之后,打开电脑上的开发板对应的u盘,找到wpa_supplicant.conf文件,更改network字典中的键值对的值,其中ssid为WIFI名称,psk为WIFI密码。如果没能连接,则无法完成之后的无线图传。
home文件夹下,yolo2_20class_awnn.py即为目标检测例程程序,加入无线图传相关代码,就可以通过http://localhost:18811在线查看检测结果,最后的代码见下,如果没有相关例程,可以去官方模型库查找,需要自己训练也可以进行在线训练。
from maix import nn, camera, image, display, mjpg, utils
from maix.nn import decoder
import time
#配置图传的IP、端口和传输序列
queue = mjpg.Queue(maxsize=8)
mjpg.MjpgServerThread(
"0.0.0.0", 18811, mjpg.BytesImageHandlerFactory(q=queue)).start()
#设置模型位置
model = {
"param": "/home/model/yolo2_20class_awnn.param",
"bin": "/home/model/yolo2_20class_awnn.bin"
}
options = {
"model_type": "awnn",
"inputs": {
"input0": (224, 224, 3)
},
"outputs": {
"output0": (7, 7, (1+4+20)*5)
},
"mean": [127.5, 127.5, 127.5],
"norm": [0.0078125, 0.0078125, 0.0078125],
}
#20类分类
labels = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
anchors = [5.4, 5.38, 1.65, 2.09, 0.8, 1.83, 2.45, 4.14, 0.46, 0.8]
m = nn.load(model, opt=options)
yolo2_decoder = decoder.Yolo2(len(labels), anchors, net_in_size=(options["inputs"]["input0"][0], options["inputs"]["input0"][1]), net_out_size=(7, 7))
while True:
img = camera.capture()
AI_img = img.copy().resize(224, 224)
out = m.forward(AI_img.tobytes(), quantize=True, layout="hwc")
boxes, probs = yolo2_decoder.run(out, nms=0.3, threshold=0.3, img_size=(options["inputs"]["input0"][0], options["inputs"]["input0"][1]))
if len(boxes):
for i, box in enumerate(boxes):
class_id = probs[i][0]
prob = probs[i][1][class_id]
disp_str = "{}:{:.2f}%".format(labels[class_id], prob*100)
img.draw_rectangle(box[0], box[1], box[0] + box[2], box[1] + box[3], color = (0, 255, 0), thickness=2)
x = box[0]
y = box[1] - 20
if y < 0:
y = 0
img.draw_string(x, y, disp_str, 1.5, color = (255, 0, 0), thickness=2)
#设定显示格式,推流
jpg = utils.rgb2jpg(img.convert("RGB").tobytes(), img.width, img.height)
queue.put(mjpg.BytesImage(jpg))
display.show(img)
最后从检测的效果看,该模型仍有较大提升空间。