element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Ralph Yamamoto's Blog Sipeed Maixduino - MaixPy Image Classification
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 4 Oct 2019 3:13 AM Date Created
  • Views 4645 views
  • Likes 4 likes
  • Comments 1 comment
  • object detection
  • maixpy
  • maixduino
Related
Recommended

Sipeed Maixduino - MaixPy Image Classification

ralphjy
ralphjy
4 Oct 2019

There are a few different tool flows that are available to program the Maixduino.  I previously used the Arduino IDE which allows reuse of existing Arduino libraries for common peripherals.

 

It appears that much of the Neural Network programming for the K210 KPU (knowledge processing unit) has been done using MaixPy (microPython).  So, I'm going to look at a tool flow that allows me to upload the MaixPy firmware and the network models and the Python programs.

 

The memory utilization appears to be the tricky part of the setup.  The Maix-1 processor module on the Maixduino has 16MB of flash memory and 8MB of RAM plus the 4GB SD card.  I still have lots to figure out, but it appears that real-time processing is constrained by the RAM size and maximum network model size is constrained by the flash memory size.  I haven't used microPython before but apparently the flash memory is mounted as the directory '/flash' and the SD card is mounted as '/sd'.  A boot.py file is executed upon boot and /sd/boot.py has priority over /flash/boot.py.

 

Here is an excerpt from the spec:

image

 

The kflash utility is used to upload the MaixPy firmware and the network models (or other binary files).  The examples that I came across all are using the flash memory.  I'll need to figure out the limitations of using the SD storage.

 

Below is the kflash GUI.  The MaixPy binary file is loaded at address 0x0000.  The other binaries are loaded at an offset addresses beyond the end of the MaixPy binary.  Here I am loading the "full" version of the MaixPy binary which allows for running remotely from an IDE.  Unfortunately, I discovered that the size of this binary would not allow me to run the neural network examples.  I ended up loading the "minimum" version and not using the IDE.

 

image

 

The version of MaixPy that was pre-loaded on the board was v0.1.1 and I updated it to the latest stable release v0.3.2.

image

 

The next utility required was the uPyLoader which enables file transfers between my Windows file system (on the left) and the Maixduino file system (on the right).  This tool also allows for remotely executing Python programs.  And it has a terminal capability for command line execution.

image

 

Image Classifier

The neural network example that I decided to try is a yolo2 image classifier that has been trained with 20 different classes.  I uploaded the 20class.kmodel at offset 0x500000 and then transferred and executed the 20class.py program.  The program captures frames from the camera and displays the image and bounding box with the class and frame rate superimposed.  It is nice that using the provided libraries that the code to run the model is very compact.

 

20class.py

import sensor,image,lcd,time
import KPU as kpu

lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1)
sensor.run(1)
clock = time.clock()
classes = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
task = kpu.load(0x500000) 
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
while(True):
    clock.tick()
    img = sensor.snapshot()
    code = kpu.run_yolo2(task, img)
    print(clock.fps())
    if code:
        for i in code:
            a=img.draw_rectangle(i.rect())
            a = lcd.display(img)
            for i in code:
                lcd.draw_string(i.x(), i.y(), classes[i.classid()], lcd.RED, lcd.WHITE)
                lcd.draw_string(i.x(), i.y()+12, '%f1.3'%i.value(), lcd.RED, lcd.WHITE)
    else:
        a = lcd.display(img)
a = kpu.deinit(task)

 

I recorded a short video of the Maixduino classifying objects.  Unfortunately, I still have not figured out how to get a decent recording from these small LCD displays so the images are not very good.  I used a photo of a woman and a dog to test the classifier.  You can see that if the woman's full face is not in the frame that she is mis-classified as a dog or a cat instead of a person.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Here are some frames from the video.  Barely legible.  The frame rates are between 0.5 to 1 FPS which is not great but acceptable.

image

image

image

image

 

I definitely need to print myself a case before going forward because the unit is too difficult to use with a loose camera and display.  And I need to learn how to train and configure my own models so that I can customize the unit for the specific objects that I want to detect.  Maybe also add facial recognition.

  • Sign in to reply
  • bherbruck
    bherbruck over 5 years ago

    did you figure out how to train a new model? I got a yolo model trained up with mobilenet but i have to use 224x224 resolution and it gets cropped to the upper left corner and warped at 1x1 aspect ratio

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube