João Vitor Yukio Bordin Yamashita
Published © CC BY-ND

How to train a custom ResNet18 model for Maix-II Dock board

How to train a custom ResNet18 model for Maix-II board using transfer learning in PyTorch and convert the model to AWNN format for inference

IntermediateWork in progress5 hours580
How to train a custom ResNet18 model for Maix-II Dock board

Things used in this project

Hardware components

Seeed Studio Sipeed MAIX-II
×1

Story

Read more

Schematics

Maix-II Dock

Code

Model weights

Python
Model weights for loading in colab
No preview (download only).

inference

Python
script to run the model
from maix import nn
from PIL import Image, ImageDraw
from maix import camera, display

model = {
    "param":"/root/models/cat_dog/20220223_000824_awnn_cat_dog_model_int8.param",                    
    "bin": "/root/models/cat_dog/20220223_000824_awnn_cat_dog_model_int8.bin"
}
camera.config(size=(224, 224))
options = {
    "model_type":  "awnn",
    "inputs": {
        "input0": (224, 224, 3)
    },
    "outputs": {
        "output0": (1, 1, 2)
    },
    "first_layer_conv_no_pad": False,
    "mean": [127.5, 127.5, 127.5],
    "norm": [0.00784313725490196, 0.00784313725490196, 0.00784313725490196],
}
print("-- load model:", model)
m = nn.load(model, opt=options)

labels = ['cat', 'dog']

while 1:
    img = camera.capture()
    if not img:
        time.sleep(0.02)
        continue
    out = m.forward(img, quantize=True)
    out = nn.F.softmax(out)
    msg = "{:.2f}: {}".format(out.max(), labels[out.argmax()])
    print(msg)
    draw = ImageDraw.Draw(img)
    draw.text((0, 0), msg, fill=(255, 0, 0))
    display.show(img)

Credits

João Vitor Yukio Bordin Yamashita
3 projects • 4 followers
Contact

Comments

Please log in or sign up to comment.