Seeed-Studio / sscma-example-esp32

Example of SenseCraft Model Assistant Model deployment related to ESP32
19 stars 12 forks source link

修改demo,不调用摄像头的视频帧,直接对读取的某张图片做推理? #22

Open woshing700 opened 2 months ago

woshing700 commented 2 months ago

input = interpreter->input(0);

camera_fb_t *frame = NULL;

uint16_t h = input->dims->data[1]; uint16_t w = input->dims->data[2]; uint16_t c = input->dims->data[3];

if (c == 1) rgb565_to_gray(input->data.uint8, frame->buf, frame->height, frame->width, h, w, ROTATION_UP);

else if (c == 3) rgb565_to_rgb888(input->data.uint8, frame->buf, frame->height, frame->width, h, w, ROTATION_UP); 不知这个rgb565_to_rgb888()函数是否包含reszie的过程。

woshing700 commented 2 months ago

我按照以上思路做了,但是模型推理得到的结果不尽人意,不知道是不是我的数据读入方式有误

2 `
{"class": "0", "x": 100, "y": 65, "w": 6, "h": 5, "confidence": 19}, {"class": "0", "x": 31, "y": 36, "w": 10, "h": 8, "confidence": 30}, {"class": "0", "x": 17, "y": 66, "w": 8, "h": 4, "confidence": 12},

`

if name == 'main': parser = argparse.ArgumentParser(description='Model generator tool') parser.add_argument('-i', '--input', help='path to image') parser.add_argument('-o', '--output', help='path to image.hpp') args = parser.parse_args()

if args.input is None or args.output is None:
    parser.print_help()
    quit()

image = cv2.imread(args.input)
h,w,c=image.shape

with open(args.output, 'w') as file:
    file.write('#pragma once\n'
               '#include <stdint.h>\n\n'
               f'#define IMAGE_HEIGHT {h}\n'
               f'#define IMAGE_WIDTH {w}\n'
               f'#define IMAGE_CHANNEL {c}\n\n'
               'const static uint8_t image_data[] = {\n')

    image = numpy.reshape(image, (-1,))
    for i, element in enumerate(image[:-1], 1):
        if i == 1:
            file.write('    ')

        file.write(f'{element}, ')

        if i % 32 == 0:
            file.write('\n    ')
    file.write(f'{image[-1]}')
    file.write('};\n')`
LynnL4 commented 2 months ago

Hi, rgb565_to_rgb888 是包含了resize的部分的,你开源看一下的的图像数据是否被归一化了,我们默认的模型都是RGB888(-128, 127)的输入格式,所以,你需要在输入到模型前,做 -128 的操作

woshing700 commented 2 months ago

hi,我调整了部分代码:

LynnL4 commented 2 months ago

Hi,你使用Seeed Xiao ESP32S3进行测试?如果是的话,可以通过以下网页快速部署模型,查看效果,另外,你的模型是自己训练的吗?通过什么方法 https://seeed-studio.github.io/SenseCraft-Web-Toolkit/#/setup/process https://sensecraftma.seeed.cc/deploy/overview

woshing700 commented 2 months ago

hi!我的板子是esp32-s3-DevKitC-1,并不是Xiao ESP32S3。在网页没法部署。关于模型则是使用官方提供的demo---“yolo” https://github.com/Seeed-Studio/sscma-example-esp32/tree/1.0.0/examples/yolo