Skip to main content

MaixPy Python3 library

Project description

MaixPy3 Logo

MaixPy3 GitHub forks GitHub stars GitHub watchers

English | 简体中文

MIT PyPI version Python issue

MaixPy3 is a Python3 toolkit based on cpython, which simplifies the development of applications on Linux AI edge devices through Python programming.

TOC

Usage

Display the camera image on the screen.

from maix import display, camera
display.show(camera.capture())

After inputting the image to the model, the result of the forward algorithm is returned.

from PIL import Image
from maix import nn

m = nn.load({
    "param": "/root/models/resnet_awnn.param",
    "bin": "/root/models/resnet_awnn.bin"
  }, opt={
    "model_type":  "awnn",
    "inputs": {
        "input0": (224, 224, 3)
    },
    "outputs": {
        "output0": (1, 1, 1000)
    },
    "first_layer_conv_no_pad": False,
    "mean": [127.5, 127.5, 127.5],
    "norm": [0.00784313725490196, 0.00784313725490196, 0.00784313725490196],
})

img = Image.open("input.jpg")
out = m.forward(img, quantize=True)
print(out.shape)
out = nn.F.softmax(out)
print(out.max(), out.argmax())

Some examples of accessing hardware peripherals.

  • GPIO
import time
from maix import gpio
PH_BASE = 224 # "PH"
gpiochip1 = gpio.chip("gpiochip1")
led = gpiochip1.get_line((PH_BASE + 14)) # "PH14"
config = gpio.line_request()
config.request_type = gpio.line_request.DIRECTION_OUTPUT
led.request(config)

while led:
    led.set_value(0)
    time.sleep(0.1)
    led.set_value(1)
    time.sleep(0.1)
  • PWM
import time
from maix import pwm

with pwm.PWM(6) as pwm6:
  pwm6.period = 1000000
  pwm6.duty_cycle = 10000
  pwm6.enable = True
  while True:
    for i in range(50, 1, -10):
      pwm6.duty_cycle = i * 10000
      time.sleep(0.1)
    for i in range(1, 50, +10):
      pwm6.duty_cycle = i * 10000
      time.sleep(0.1)
  • I2C
from maix import i2c
i2c = i2c.I2CDevice('/dev/i2c-2', 0x26)
i2c.write(0x1, b'\xAA')
print(i2c.read(0x1, 1))
  • SPI
from maix import spi
spi = spi.SpiDev()
spi.open(1, 0) # '/dev/spidev1.0'

spi.bits_per_word = 8
spi.max_speed_hz = 1
spi.mode = 0b11

import time

while True:
  time.sleep(0.1)
  to_send = [0x01, 0x02, 0x01]
  print(spi.xfer2(to_send, 800000)) # 800Khz
  • UART
from maix import serial

with serial.Serial("/dev/ttyS1",115200) as ser:
  ser.write(b"Hello Wrold !!!\n")
  ser.setDTR(True)
  ser.setRTS(True)
  tmp = ser.readline()
  print(tmp)
  ser.write(tmp)
  ser.setDTR(False)
  ser.setRTS(False)
  • EVENT
from maix import evdev
from select import select
dev = evdev.InputDevice('/dev/input/event9')

while True:
  select([dev], [], [])
  for event in dev.read():
    print(event.code, event.value)

See the documentation for more information

Jupyter

Install rpyc_ikernel kernel in jupyter notebook & lab to get an IDE that can remotely call Python code, videos, and image streaming.

Click here to view the effect usage_display_hook.ipynb. Note that jupyter runs on your computer.

Progress

Platform Status Example config Memory usage
linux x86_64 working general general unlimited
maix_v83x working maix_v83x maix_v83x 11M+
maix_r329 working maix_r329 maix_r329 unknown
RPi_XXXX maybe NULL
Windows build fail

The development progress is in no particular order.

Build

Under linux x86_64, use python3 setup.py build to complete the general package construction.

For other platforms, take the version of maix_v83x as an example, match the Python3 + cross-compilation chain of the corresponding platform(toolchain_v83x_linux_x86), and run python3.8 setup.py build maix_v83x to complete the construction of the target platform package.

Welcome to provide configurations of different platforms to MaixPy3/envs/ to adapt to the MaixPy3 environment.

If you need .whl pre-compiled package, please change build to bdist_wheel.

Develop

Tested glibc >= 27 on Ubuntu20.04 & manjaro20.03.

Each catalog function of the project.

  • docs [store some general development documents]
  • envs [store compilation configurations for different platforms]
  • examples [store examples or applications on different platforms]
  • ext_modules [store project modules that need to be compiled]
  • maix [Provide maix entry Python module]
  • tests [Provide tox common test items]
  • setup.py [MaixPy3 project compilation entry]

If you want to submit the configuration of other platforms, please refer to the following:

_maix_modules = [
    libi2c_module,
]

_maix_data_files = [
    ('/maix', get_srcs(ext_so, ['so' 'ko'])),
]

_maix_py_modules = [
    "numpy",
]

If you want to submit some Python and C modules that need to be compiled, it is recommended to use the sub-repository to import, refer to the following:

If you want to submit some useful Python tools or sample code, refer to the following:

Thanks

All this comes from the power of open source. Thanks to them, they are listed in no particular order.

The open source repositories that may be cited in the future are also grateful to them.

You are welcome to recommend the open source projects you need. If you find any missing projects, please let me know immediately.

License

Copyright (c) Sipeed Corporation. All rights reserved.

Licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maixpy3-0.3.4.tar.gz (13.3 MB view details)

Uploaded Source

Built Distributions

maixpy3-0.3.4-cp39-cp39-manylinux2014_aarch64.whl (20.5 MB view details)

Uploaded CPython 3.9

maixpy3-0.3.4-cp38-cp38-linux_armv7l.whl (3.6 MB view details)

Uploaded CPython 3.8

File details

Details for the file maixpy3-0.3.4.tar.gz.

File metadata

  • Download URL: maixpy3-0.3.4.tar.gz
  • Upload date:
  • Size: 13.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for maixpy3-0.3.4.tar.gz
Algorithm Hash digest
SHA256 55bde047097f4797c0ddf94e66d2a36ba7ad033454d58c650b62467b5dd86f61
MD5 64d412f04e38f55eb8801733ca252fd9
BLAKE2b-256 216a3d44fd97a8187e7fd01a071d995d3e9d2b7a088daf1747e843b2488e2e8b

See more details on using hashes here.

File details

Details for the file maixpy3-0.3.4-cp39-cp39-manylinux2014_aarch64.whl.

File metadata

  • Download URL: maixpy3-0.3.4-cp39-cp39-manylinux2014_aarch64.whl
  • Upload date:
  • Size: 20.5 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for maixpy3-0.3.4-cp39-cp39-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a46cd518e218e00d6daf763ff2f930cd9a68d91e9faa7c3042b8478ec0796644
MD5 5d5ca765fe17010eeaf1536862f8f0ae
BLAKE2b-256 2fd9604e51af982f01f1ee83ed95394ae21c0cdcfaa2c2fe992aec576b796884

See more details on using hashes here.

File details

Details for the file maixpy3-0.3.4-cp38-cp38-linux_armv7l.whl.

File metadata

  • Download URL: maixpy3-0.3.4-cp38-cp38-linux_armv7l.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for maixpy3-0.3.4-cp38-cp38-linux_armv7l.whl
Algorithm Hash digest
SHA256 20c94fe8f10998275271616bfce4d4be654e1901ec65805f7700c6c0191cc2a1
MD5 94779e7df74998e7229fb232ba39e93c
BLAKE2b-256 6e9cb18dede41aeaeaf99faec48c92512ce9ca6c11ea03e27ecb2feb58e15fa7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page