Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[0.4.0] release
Browse files Browse the repository at this point in the history
  • Loading branch information
junhuanchen committed Jan 12, 2022
1 parent 888feeb commit d47350b
Show file tree
Hide file tree
Showing 27 changed files with 434 additions and 475 deletions.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
prune .git

recursive-include ext_modules/libmaix/components/libmaix/include *.h
recursive-include ext_modules/libmaix/components/maix_cv_image/include *.h
recursive-include ext_modules/libmaix/components/libmaix/lib/arch/desktop/ *
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ Install [rpyc_ikernel](https://github.com/sipeed/rpyc_ikernel) kernel in jupyter

| **Platform** | **Status** | **Config** | **Progress** |
| -------------- | ---------- | ----------- | ------------ |
| linux_pc & RPi_2B | working | [linux_desktop](./envs/linux_desktop.py) | 50%
| linux_pc & RPi_2B | working | [linux_desktop](./envs/linux_desktop.py) | 70%
| maix_v83x | working | [maix_v83x](./envs/maix_v83x.py) | 90%
| maix_r329 | working | [maix_r329](./envs/maix_r329.py) | 70%
| maix_r329 | working | [maix_r329](./envs/maix_r329.py) | 80%

Estimated Workload

- 30% Python3.7↑ & toolchain environment adaptation Pillow spidev evdev gpiod pyserial zbarlight numpy

- 20% base library adaptation camera display image nn speech

- 10% Peripheral library adapted to gpio spi i2c zbar pwm event

- 40% AI application adaptation resnet yolo classifier FaceRecognize

> The development progress is in no particular order.
Expand Down
12 changes: 7 additions & 5 deletions docs/develop_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,27 @@ auto run test_xxxx.py

your x86

- python setup.py build
- python3 setup.py bdist_wheel

your v83x

- source /opt/v83x_linux_x86_python3.8_toolchain/envsetup.sh

- python3.8 setup.py build maix_v83x
- python3.8 setup.py bdist_wheel maix_v83x

- adb shell "pip install /root/maixpy3-0.3.5-cp38-cp38-linux_armv7l.whl --upgrade"

- python3.8 setup.py clean --all bdist_wheel maix_v83x && adb push ./dist/maixpy3-0.3.5-cp38-cp38-linux_armv7l.whl /root/ && adb shell "pip install /root/maixpy3-0.3.5-cp38-cp38-linux_armv7l.whl --upgrade"
- python3.8 setup.py clean --all bdist_wheel maix_v83x && adb push ./dist/maixpy3-0.3.8-cp38-cp38-linux_armv7l.whl /root/ && adb shell "pip install /root/maixpy3-0.3.8-cp38-cp38-linux_armv7l.whl --upgrade"

your r329

- source /opt/r329_linux_x86_python3.9_toolchain/envsetup.sh

- python3.9 setup.py clean --all bdist_wheel maix_r329 && scp ./dist/maixpy3-0.3.5-cp39*.whl root@192.168.0.5:~/
- python3.8 setup.py bdist_wheel maix_r329

- python3.9 setup.py clean --all bdist_wheel maix_r329 && scp ./dist/maixpy3-0.3.6-cp39*.whl root@192.168.0.17:~/

- pip uninstall maixpy3 -y && pip install ~/maixpy3-0.3.5-cp39*.whl
- pip uninstall maixpy3 -y && pip install ~/maixpy3-0.3.6-cp39*.whl

> pypi upload manylinux2014_aarch64
Expand Down
15 changes: 9 additions & 6 deletions envs/linux_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

_maix_image_module = Pybind11Extension(
name = "_maix_image",
include_dirs=[ '/usr/include/opencv4/',
include_dirs=[ '/usr/include/opencv4/', '/usr/local/include/opencv4/',
get_incs(
'ext_modules/libmaix/components/libmaix/include'),
get_incs(
Expand All @@ -44,7 +44,8 @@
],
library_dirs=[
"/usr/lib/",
"/usr/lib/x86_64-linux-gnu/"
"/usr/lib/x86_64-linux-gnu/",
"/usr/local/lib64/",
],
extra_link_args=[
],
Expand All @@ -53,7 +54,7 @@

_maix_camera_module = Pybind11Extension(
name = '_maix_camera',
include_dirs=[ '/usr/include/opencv4/',
include_dirs=[ '/usr/include/opencv4/', '/usr/local/include/opencv4/',
get_incs(
'ext_modules/libmaix/components/libmaix/include'),
get_incs(
Expand All @@ -79,7 +80,8 @@
],
library_dirs=[
"/usr/lib/",
"/usr/lib/x86_64-linux-gnu/"
"/usr/lib/x86_64-linux-gnu/",
"/usr/local/lib64/",
],
extra_link_args=[
],
Expand All @@ -88,7 +90,7 @@

_maix_display_module = Pybind11Extension(
name = "_maix_display",
include_dirs=[ '/usr/include/opencv4/',
include_dirs=[ '/usr/include/opencv4/', '/usr/local/include/opencv4/',
get_incs(
'ext_modules/libmaix/components/libmaix/include'),
get_incs(
Expand All @@ -114,7 +116,8 @@
],
library_dirs=[
"/usr/lib/",
"/usr/lib/x86_64-linux-gnu/"
"/usr/lib/x86_64-linux-gnu/",
"/usr/local/lib64/",
],
extra_link_args=[
],
Expand Down
13 changes: 7 additions & 6 deletions envs/maix_r329.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@
max_nn_srcs = get_srcs('ext_modules/_maix_nn/src')
max_nn_srcs.extend(get_srcs('ext_modules/libmaix/components/libmaix/src'))
max_nn_srcs.remove("ext_modules/libmaix/components/libmaix/src/libmaix.c")
max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_app.c")
max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_app_classifier.c")
max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_app_FaceRecognize.c")
max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_decoder_yolo2.c")
max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_decoder.c")
# max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_app.c")
# max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_app_classifier.c")
# max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_app_FaceRecognize.c")
# max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_decoder_yolo2.c")
# max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn_decoder.c")
# max_nn_srcs.remove("ext_modules/_maix_nn/src/py_maix_nn.c")
_maix_nn_module = Extension('_maix_nn', include_dirs=['ext_modules/_maix_nn/include', 'ext_modules/libmaix/components/libmaix/include'],
sources=max_nn_srcs,
libraries=[
"maix_utils", "maix_nn",
"maix_utils", "maix_nn", "maix_nn_decoder", "maix_nn_app"
],
library_dirs=[ ext_so, ],
# extra_link_args = [ "-Wl,-z,origin", "-Wl,-rpath='$ORIGIN/maix'" ]
Expand Down Expand Up @@ -150,6 +150,7 @@
]

_maix_py_modules = [
"numpy",
"Pillow",
"rpyc",
"gpiod",
Expand Down
1 change: 1 addition & 0 deletions envs/maix_v83x.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
]

_maix_py_modules = [
"numpy",
"Pillow",
"rpyc",
"gpiod",
Expand Down
8 changes: 5 additions & 3 deletions ext_modules/_maix_camera/_camera_pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PYBIND11_MODULE(_maix_camera, m)
.doc() = "_maix_Camera";

pybind11::class_<_camera>(m, "Camera")
.def(py::init<int, int, int>(), py::arg("w") = 240, py::arg("h") = 240, py::arg("dev_id") = 0)
.def(py::init<int, int, int, int, int>(), py::arg("w") = 240, py::arg("h") = 240, py::arg("dev_id") = 0, py::arg("m") = 0, py::arg("f") = 0)
.def_readwrite("width", &_camera::width)
.def_readwrite("height", &_camera::height)
.def("read", &_camera::read)
Expand Down Expand Up @@ -67,7 +67,7 @@ void v_init(_camera *tp)
libmaix_camera_module_init();
libmaix_image_module_init();
tp->rgb_img = NULL;
tp->cam = libmaix_cam_create(tp->dev_id, tp->width, tp->height, 0, 0);
tp->cam = libmaix_cam_create(tp->dev_id, tp->width, tp->height, tp->m, tp->f);
if (NULL != tp->cam)
{
int ret = tp->cam->start_capture(tp->cam);
Expand All @@ -91,11 +91,13 @@ void v_init(_camera *tp)
#endif // VirtualCamera
}

_camera::_camera(int w, int h, int dev_id)
_camera::_camera(int w, int h, int dev_id, int m, int f)
{
this->width = w;
this->height = h;
this->dev_id = dev_id;
this->m = m;
this->f = f;
v_init(this);
}

Expand Down
26 changes: 2 additions & 24 deletions ext_modules/_maix_camera/include/_maix_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,16 @@ class _camera
{
private:
public:
int width, height, dev_id;
// width operator=(const int num) //如果使用的话,可能需要重载赋值运算符
// {
// if(num < 640 || num > 480)
// }
_camera(int w, int h, int dev_id);
int width, height, dev_id, m, f;
_camera(int w, int h, int dev_id, int m, int f);
~_camera();
pybind11::list read();
void close();
void __enter__();
void __exit__();

libmaix_cam_t *cam;
libmaix_cam_t *cam1;
libmaix_image_t *rgb_img;


// #ifdef R329Camera
// public:
// libmaix_cam_t *cam;
// uint8_t *img_buff;

// #endif

// #ifdef V83xCamera
// public:
// libmaix_cam_t *cam;
// libmaix_image_t *yuv_img;
// libmaix_image_t *rgb_img;

// #endif

};


Expand Down
12 changes: 9 additions & 3 deletions ext_modules/_maix_image/_maix_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::string maix_image::str__()
{
std::string info_str;
std::stringstream ss;
ss << "<_maix_image.Image \"width\":" << this->_maix_image_width
ss << "<_maix_image.Image " << this->_img << " \" width\":" << this->_maix_image_width
<< ", \"height\":" << this->_maix_image_height
<< ", \"type\"=" << this->_maix_image_type
<< ", \"size\":" << this->_maix_image_size
Expand Down Expand Up @@ -345,13 +345,19 @@ py::object maix_image::_to_py(std::string im)
}
}
#endif
return py::none();
}

void maix_image::_clear()
void maix_image::_delete()
{
this->v_close();
}

maix_image &maix_image::_clear()
{
uint8_t* img_p_t = (uint8_t*)this->_img->data;
memset(img_p_t, 0, this->_maix_image_size);
return *this;
}
void maix_image::_load_freetype(std::string path)
{
libmaix_cv_image_load_freetype(path.c_str());
Expand Down
3 changes: 2 additions & 1 deletion ext_modules/_maix_image/include/maix_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class maix_image : virtual public any_image, public maix_version, public maix_cu
maix_image &_load(py::object data, std::vector<int> size, std::string mode);
maix_image &_open_file(std::string path);
py::object _to_py(std::string im);
void _clear();
void _delete();
maix_image &_clear();
void _load_freetype(std::string path);
py::tuple _get_string_size(std::string str, double scale, int thickness);
maix_image &_resize(int w, int h, int func);
Expand Down
1 change: 1 addition & 0 deletions ext_modules/_maix_image/py_maix_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ PYBIND11_MODULE(_maix_image, mo)
.def("open", &maix_image::_open_file)
.def("copy", &maix_image::_to_py, py::arg("img") = "maix_image")
.def("clear", &maix_image::_clear)
.def("delete", &maix_image::_delete)
.def("load_freetype", &maix_image::_load_freetype, py::arg("path"))
.def("get_string_size", &maix_image::_get_string_size, py::arg("str"), py::arg("scale") = 1.0, py::arg("thickness") = 1)
.def("save", &maix_image::_save, py::arg("path"), py::arg("format") = "jpeg")
Expand Down
3 changes: 2 additions & 1 deletion ext_modules/_maix_nn/example/load_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
while True:
img = camera.capture()
out = m.forward(img.tobytes(), quantize=True)

print(out.shape)
out2 = nn.F.softmax(out)
msg = "{:.2f}: {}".format(out2.max(), labels[out.argmax()])
print(msg)
img.draw_string(0,0,msg,scale = 0.5 , color = (183,127,221))
display.show(img)
52 changes: 32 additions & 20 deletions ext_modules/_maix_nn/example/yolo2_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@



from maix import nn
from PIL import Image, ImageDraw, ImageFont
from maix import display, camera
from maix import nn, display, camera , image
import time
from maix.nn import decoder
import numpy as np

def draw_rectangle_with_title(draw, box, disp_str, bg_color=(255, 0, 0, 255), font_color=(255, 255, 255, 255)):
# draw = ImageDraw.Draw(img)
font = ImageFont.load_default()
def draw_rectangle_with_title(img, box, disp_str, bg_color=(255, 0, 0, 255), font_color=(255, 255, 255, 255)):
# # draw = ImageDraw.Draw(img)
# font_w, font_h = font.getsize(disp_str)
# draw.rectangle((box[0], box[1], box[0] + box[2], box[1] + box[3]), fill=None, outline=bg_color, width=2)
# draw.rectangle((box[0], box[1] - font_h, box[0] + font_w, box[1]), fill=bg_color)
# draw.text((box[0], box[1] - font_h), disp_str, fill=font_color, font=font)

font_w, font_h = font.getsize(disp_str)
draw.rectangle((box[0], box[1], box[0] + box[2], box[1] + box[3]), fill=None, outline=bg_color, width=2)
draw.rectangle((box[0], box[1] - font_h, box[0] + font_w, box[1]), fill=bg_color)
draw.text((box[0], box[1] - font_h), disp_str, fill=font_color, font=font)
# tmp.draw_rectangle(i["x"], i["y"], i["x"] + i["w"],
# i["y"] + i["h"], color=(255, 0, 0), thickness=1)
img.draw_rectangle(box[0], box[1], box[0] + box[2], box[1] + box[3],color=(255, 0, 0), thickness=1)
img.draw_string(box[0], box[1]+ box[3] ,disp_str, scale=0.5,color=(0, 0, 255), thickness=1)



camera.config(size=(224, 224))


model = {
# "param": "/root/models/yolo2_face_awnn.param",
# "bin": "/root/models/yolo2_face_awnn.bin"
"bin":"/root/dections/yolo2.bin"
"param": "/home/model/face/yolo2_face_awnn.param",
"bin": "/home/model/face/yolo2_face_awnn.bin"
# "bin":"./aipu_onnx_cards_224_35.bin"
}

options = {
"model_type": "normal",
"model_type": "awnn",
"inputs": {
"input0": (224, 224, 3)
},
Expand All @@ -48,33 +50,43 @@ def draw_rectangle_with_title(draw, box, disp_str, bg_color=(255, 0, 0, 255), fo
print("-- read image ok")


# labels = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "mouse", "microbit", "ruler", "cat", "peer", "ship", "apple", "car", "pan", "dog", "umbrella", "airplane", "clock", "grape", "cup", "left", "right", "front", "stop", "back"]
# anchors = [2.44, 2.25, 5.03, 4.91, 3.5, 3.53, 4.16, 3.94, 2.97, 2.84]

labels = ["person"]
anchors = [1.19, 1.98, 2.79, 4.59, 4.53, 8.92, 8.06, 5.29, 10.32, 10.65]

yolo2_decoder = decoder.Yolo2(len(labels), anchors, net_in_size=(w, h), net_out_size=(7, 7))




camera.config((224, 224))
while 1:
img = camera.capture()
if not img:
time.sleep(0.01)
continue
t = time.time()
out = m.forward(img.tobytes(), quantize=True, layout="hwc")

out = m.forward(img.tobytes(), quantize=True)
print("-- forward: ", time.time() - t )


t = time.time()
boxes, probs = yolo2_decoder.run(out, nms=0.3, threshold=0.5, img_size=(240, 240))
boxes, probs = yolo2_decoder.run(out, nms=0.5, threshold=0.5, img_size=(224,224))
print("-- decode: ", time.time() - t )

t = time.time()
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)
draw_rectangle_with_title(display.get_draw(), box, disp_str)
draw_rectangle_with_title(img, box, disp_str)
print("-- draw: ", time.time() - t )

t = time.time()
display.show()
display.show(img)
print("-- show: ", time.time() - t )


Loading

0 comments on commit d47350b

Please sign in to comment.