ONNX
File size: 1,858 Bytes
ec51737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/bash

ws=$(realpath $(dirname "${BASH_SOURCE[0]}"))
cd $ws

# 允许通过环境变量直接指定 target_hardware,非交互式环境默认使用 AX615
if [ -n "$TARGET_HARDWARE" ]; then
    target_hardware=$TARGET_HARDWARE
elif [ -t 0 ]; then
    options=(AX615 AX650 AX637 M57 "其他(手动输入)")
    PS3="请选择 target_hardware(输入数字): "
    select opt in "${options[@]}"; do
        case $opt in
            AX615|AX637|AX650|M57)
                target_hardware=$opt
                break
                ;;
            "其他(手动输入)")
                read -rp "请输入 target_hardware: " target_hardware
                if [ -n "$target_hardware" ]; then
                    break
                fi
                echo "输入不能为空,请重新选择"
                ;;
            *)
                echo "无效选项,请重新选择"
                ;;
        esac
    done
else
    target_hardware=AX650
fi

echo "使用 target_hardware: $target_hardware"

find $ws -maxdepth 2 -name "*.onnx" | parallel -I {} -j 8 \
  "
  d=\$(realpath \$(dirname {}))
  if [ -f \$d/output/compiled.axmodel ]; then
      echo '[{}] axmodel already exists, skip.';
      exit 0;
  fi
  echo 'start building [{}]...';
  time pulsar2 build \
    --target_hardware $target_hardware \
    --npu_mode NPU1 \
    --input {} \
    --config \$d/config.json \
    --output_dir \$d/output 2>&1 | tee \$d/build.log || \
    { echo 'build [{}] failed, skip.'; exit 0; };
  echo 'build [{}] finish.';
  "

echo ""
echo "=== 模型转出情况 ==="
while IFS= read -r onnx; do
    d=$(realpath $(dirname "$onnx"))
    name=$(basename "$d")
    if [ -f "$d/output/compiled.axmodel" ]; then
        echo "✅ Task '$name'"
    else
        echo "❌ Task '$name'"
    fi
done < <(find $ws -maxdepth 2 -name "*.onnx" | sort)