Skip to content

Commit ab8801a

Browse files
author
nullptr
committed
chore: fix rtmdet export shape, update docs
commit e55152f Author: nullptr <nullptr@localhost> Date: Wed Dec 25 10:05:08 2024 +0000 refactor: rtmdet forward shape commit a88f7f1 Author: nullptr <nullptr@localhost> Date: Wed Dec 25 08:21:20 2024 +0000 docs: update contents commit f291538 Author: nullptr <nullptr@localhost> Date: Wed Dec 25 08:21:10 2024 +0000 docs: update contents
1 parent 3f5274d commit ab8801a

File tree

5 files changed

+252
-12
lines changed

5 files changed

+252
-12
lines changed

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<div align="center">
2+
<img width="20%" src="https://files.seeedstudio.com/sscma/docs/images/SSCMA-Hero.png"/>
3+
4+
<h1>
5+
SenseCraft Model Assistant by Seeed Studio
6+
</h1>
7+
8+
[![docs-build](https://github.com/Seeed-Studio/ModelAssistant/actions/workflows/docs-build.yml/badge.svg)](https://github.com/Seeed-Studio/ModelAssistant/actions/workflows/docs-build.yml)
9+
![GitHub Release](https://img.shields.io/github/v/release/Seeed-Studio/ModelAssistant)
10+
[![license](https://img.shields.io/github/license/Seeed-Studio/ModelAssistant.svg)](https://github.com/Seeed-Studio/ModelAssistant/blob/main/LICENSE)
11+
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/Seeed-Studio/ModelAssistant.svg)](http://isitmaintained.com/project/Seeed-Studio/ModelAssistant "Average time to resolve an issue")
12+
[![Percentage of issues still open](http://isitmaintained.com/badge/open/Seeed-Studio/ModelAssistant.svg)](http://isitmaintained.com/project/Seeed-Studio/ModelAssistant "Percentage of issues still open")
13+
14+
<h3>
15+
<a href="https://sensecraftma.seeed.cc"> Documentation </a> |
16+
<a href="https://sensecraftma.seeed.cc/introduction/installation"> Installation </a> |
17+
<a href="https://github.com/Seeed-Studio/ModelAssistant/tree/main/notebooks"> Colab </a> |
18+
<a href="https://github.com/Seeed-Studio/sscma-model-zoo"> Model Zoo </a> |
19+
<a href="https://seeed-studio.github.io/SenseCraft-Web-Toolkit"> Deploy </a> -
20+
<a href="README_zh-CN.md"> 简体中文 </a>
21+
</h3>
22+
23+
</div>
24+
25+
## Introduction
26+
27+
**S**eeed **S**ense**C**raft **M**odel **A**ssistant is an open-source project focused on providing state-of-the-art AI algorithms for embedded devices. It is designed to help developers and makers to easily deploy various AI models on low-cost hardwares, such as microcontrollers and single-board computers (SBCs).
28+
29+
<div align="center">
30+
31+
<img width="98%" src="https://files.seeedstudio.com/sscma/docs/images/SSCMA-Deploy.gif"/>
32+
33+
</div>
34+
35+
**Real-world deploy examples on MCUs with less than 0.3 Watts power consumption.*
36+
37+
### 🤝 User-friendly
38+
39+
SSCMA provides a user-friendly platform that allows users to easily perform training on collected data, and to better understand the performance of algorithms through visualizations generated during the training process.
40+
41+
### 🔋 Models with low computing power and high performance
42+
43+
SSCMA focuses on end-side AI algorithm research, and the algorithm models can be deployed on microprocessors, similar to [ESP32](https://www.espressif.com.cn/en/products/socs/esp32), some [Arduino](https://arduino.cc) development boards, and even in embedded SBCs such as [Raspberry Pi](https://www.raspberrypi.org).
44+
45+
### 🗂️ Supports multiple formats for model export
46+
47+
[TensorFlow Lite](https://www.tensorflow.org/lite) is mainly used in microcontrollers, while [ONNX](https://onnx.ai) is mainly used in devices with Embedded Linux. There are some special formats such as [TensorRT](https://developer.nvidia.com/tensorrt), [OpenVINO](https://docs.openvino.ai) which are already well supported by OpenMMLab. SSCMA has added TFLite model export for microcontrollers, which can be directly converted to [TensorRT](https://developer.nvidia.com/tensorrt), [UF2](https://github.com/microsoft/uf2) format and drag-and-drop into the device for deployment.
48+
49+
## Features
50+
51+
We have optimized excellent algorithms from [OpenMMLab](https://github.com/open-mmlab) for real-world scenarios and made implementation more user-friendly, achieving faster and more accurate inference. Currently we support the following directions of algorithms:
52+
53+
### 🔍 Anomaly Detection
54+
55+
In the real world, anomalous data is often difficult to identify, and even if it can be identified, it requires a very high cost. The anomaly detection algorithm collects normal data in a low-cost way, and anything outside normal data is considered anomalous.
56+
57+
### 👁️ Computer Vision
58+
59+
Here we provide a number of computer vision algorithms such as **object detection, image classification, image segmentation and pose estimation**. However, these algorithms cannot run on low-cost hardwares. SSCMA optimizes these computer vision algorithms to achieve good running speed and accuracy in low-end devices.
60+
61+
### ⏱️ Scenario Specific
62+
63+
SSCMA provides customized scenarios for specific production environments, such as identification of analog instruments, traditional digital meters, and audio classification. We will continue to add more algorithms for specified scenarios in the future.
64+
65+
## What's New
66+
67+
SSCMA is always committed to providing the cutting-edge AI algorithms for best performance and accuracy, along with the community feedbacks, we keeps updating and optimizing the algorithms to meet the actual needs of users, here are some of the latest updates:
68+
69+
### 🔥 RTMDet, VAE, QAT
70+
71+
We have added the RTMDet algorithm for real-time multi-object detection, VAE for anomaly detection, and QAT for quantization-aware training. These algorithms are optimized for low-cost hardwares and can be deployed on microcontrollers.
72+
73+
![RTMDet COCO Benchmark](docs/images/rtmdet_coco_eval.png)
74+
75+
We also optimized the training process for these algorithms, now the training process is much more faster than before.
76+
77+
### YOLOv8, YOLOv8 Pose, Nvidia Tao Models and ByteTrack
78+
79+
With [SSCMA-Micro](https://github.com/Seeed-Studio/SSCMA-Micro), now you can deploy the latest [YOLOv8](https://github.com/ultralytics/ultralytics), YOLOv8 Pose, [Nvidia TAO Models](https://docs.nvidia.com/tao/tao-toolkit/text/model_zoo/cv_models/index.html) on microcontrollers. we also added the [ByteTrack](https://github.com/ifzhang/ByteTrack) algorithm to enable real-time object tracking on low-cost hardwares.
80+
81+
<div align="center"><img width="98%" src="https://files.seeedstudio.com/sscma/docs/images/SSCMA-WebCam-Tracking.gif"/></div>
82+
83+
### Swift YOLO
84+
85+
We implemented a lightweight object detection algorithm called Swift YOLO, which is designed to run on low-cost hardware with limited computing power. The visualization tool, model training and export command-line interface has refactored now.
86+
87+
<div align="center"><img width="98%" src="https://files.seeedstudio.com/sscma/docs/static/esp32/images/person_detection.png"/></div>
88+
89+
### Meter Recognition
90+
91+
Meter is a common instrument in our daily life and industrial production, such as analog meters, digital meters, etc. SSCMA provides meter recognition algorithms that can be used to identify the readings of various meters.
92+
93+
<div align="center"><img width="98%" src="https://files.seeedstudio.com/sscma/docs/static/grove/images/pfld_meter.gif"/></div>
94+
95+
## The SSCMA Toolchains
96+
97+
SSCMA provides a complete toolchain for users to easily deploy AI models on low-cost hardwares, including:
98+
99+
- [SSCMA-Model-Zoo](https://sensecraft.seeed.cc/ai/#/model) SSCMA Model Zoo provides a series of pre-trained models for different application scenarios for you to use. The source code for this web is [hosted here](https://github.com/Seeed-Studio/sscma-model-zoo).
100+
- [SSCMA-Web-Toolkit, which is now renamed to SenseCraft AI](https://sensecraft.seeed.cc/ai/#/home) A web-based tool that makes trainning and deploying machine learning models (with a focus on vision models by now) fast, easy, and accessible to everyone.
101+
- [SSCMA-Micro](https://github.com/Seeed-Studio/SSCMA-Micro) A cross-platform framework that deploys and applies SSCMA models to microcontrol devices.
102+
- [Seeed-Arduino-SSCMA](https://github.com/Seeed-Studio/Seeed_Arduino_SSCMA) Arduino library for devices supporting the SSCMA-Micro firmware.
103+
- [Python-SSCMA](https://github.com/Seeed-Studio/python-sscma) A Python library for interacting with microcontrollers using SSCMA-Micro, and for higher-level deep learning applications.
104+
105+
## Acknowledgement
106+
107+
SSCMA is a united effort of many developers and contributors, we would like to thank the following projects and organizations for their contributions which SSCMA referenced to implement:
108+
109+
- [OpenMMLab](https://openmmlab.com/)
110+
- [ONNX](https://github.com/onnx/onnx)
111+
- [NCNN](https://github.com/Tencent/ncnn)
112+
- [TinyNN](https://github.com/alibaba/TinyNeuralNetwork)
113+
114+
## License
115+
116+
This project is released under the [Apache 2.0 license](LICENSE).

README_zh-CN.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<div align="center">
2+
<img width="20%" src="https://files.seeedstudio.com/sscma/docs/images/SSCMA-Hero.png"/>
3+
4+
<h1>
5+
SenseCraft Model Assistant by Seeed Studio
6+
</h1>
7+
8+
[![docs-build](https://github.com/Seeed-Studio/ModelAssistant/actions/workflows/docs-build.yml/badge.svg)](https://github.com/Seeed-Studio/ModelAssistant/actions/workflows/docs-build.yml)
9+
![GitHub Release](https://img.shields.io/github/v/release/Seeed-Studio/ModelAssistant)
10+
[![license](https://img.shields.io/github/license/Seeed-Studio/ModelAssistant.svg)](https://github.com/Seeed-Studio/ModelAssistant/blob/main/LICENSE)
11+
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/Seeed-Studio/ModelAssistant.svg)](http://isitmaintained.com/project/Seeed-Studio/ModelAssistant "Average time to resolve an issue")
12+
[![Percentage of issues still open](http://isitmaintained.com/badge/open/Seeed-Studio/ModelAssistant.svg)](http://isitmaintained.com/project/Seeed-Studio/ModelAssistant "Percentage of issues still open")
13+
14+
<h3>
15+
<a href="https://sensecraftma.seeed.cc"> 文档 </a> |
16+
<a href="https://sensecraftma.seeed.cc/introduction/installation"> 安装 </a> |
17+
<a href="https://github.com/Seeed-Studio/ModelAssistant/tree/main/notebooks"> Colab </a> |
18+
<a href="https://github.com/Seeed-Studio/sscma-model-zoo"> 模型仓库 </a> |
19+
<a href="https://seeed-studio.github.io/SenseCraft-Web-Toolkit"> 部署 </a> -
20+
<a href="README.md"> English </a>
21+
</h3>
22+
23+
</div>
24+
25+
## 简介
26+
27+
**S**eeed **S**ense**C**raft **M**odel **A**ssistant 是一个专注于为嵌入式设备提供最先进的人工智能算法的开源项目。它旨在帮助开发人员和制造商轻松部署各种人工智能模型到低成本硬件上,如微控制器和单板计算机(SBCs)。
28+
29+
<div align="center">
30+
31+
<img width="98%" src="https://files.seeedstudio.com/sscma/docs/images/SSCMA-Deploy.gif"/>
32+
33+
</div>
34+
35+
**在功耗低于 0.3 瓦的微控制器上的真实部署示例。*
36+
37+
### 🤝 用户友好
38+
39+
SenseCraft 模型助手提供了一个用户友好的平台,方便用户使用收集的数据进行训练,并通过训练过程中生成的可视化结果更好地了解算法的性能。
40+
41+
### 🔋 低计算功耗、高性能的模型
42+
43+
SenseCraft 模型助手专注于边缘端人工智能算法研究,算法模型可以部署在微处理器上,类似于 [ESP32](https://www.espressif.com.cn/en/products/socs/esp32)、一些 [Arduino](https://arduino.cc) 开发板,甚至在嵌入式 SBCs(如 [Raspberry Pi](https://www.raspberrypi.org) )上。
44+
45+
### 🗂️ 支持多种模型导出格式
46+
47+
[TensorFlow Lite](https://www.tensorflow.org/lite) 主要用于微控制器,而 [ONNX](https://onnx.ai) 主要用于嵌入式Linux设备。还有一些特殊格式,如 [TensorRT](https://developer.nvidia.com/tensorrt)[OpenVINO](https://docs.openvino.ai),这些格式已经得到 OpenMMLab 的良好支持。SenseCraft 模型助手添加了 TFLite 模型导出功能,可直接转换为 [TensorRT](https://developer.nvidia.com/tensorrt)[UF2](https://github.com/microsoft/uf2) 格式,并可拖放到设备上进行部署。
48+
49+
## 功能
50+
51+
我们已经从 [OpenMMLab](https://github.com/open-mmlab) 优化了出色的算法,针对实际场景进行了改进,并使实现更加用户友好,实现了更快、更准确的推理。目前我们支持以下算法方向:
52+
53+
### 🔍 异常检测
54+
55+
在现实世界中,异常数据通常难以识别,即使能够识别出来,也需要很高的成本。异常检测算法以低成本的方式收集正常数据,认为任何超出正常数据范围的数据都是异常的。
56+
57+
### 👁️ 计算机视觉
58+
59+
我们提供了许多计算机视觉算法,例如目标检测、图像分类、图像分割和姿态估计。但是,这些算法无法在低成本硬件上运行。SenseCraft 模型助手优化了这些计算机视觉算法,实现了较好的运行速度和准确性。
60+
61+
### ⏱️ 场景特定
62+
63+
SenseCraft 模型助手为特定的生产环境提供了定制化场景,例如模拟仪器、传统数字仪表和音频分类的识别。我们将继续在未来添加更多的指定场景算法。
64+
65+
## 新特性
66+
67+
SSCMA 一直致力于为用户提供最先进的人工智能算法,以获得最佳性能和准确性。我们根据社区反馈不断更新和优化算法,以满足用户的实际需求。以下是一些最新的更新内容:
68+
69+
### 🔥 RTMDet, VAE, QAT
70+
71+
我们增加了 RTMDet 算法用于实时多目标检测,VAE 用于异常检测,以及 QAT 用于量化感知训练。这些算法针对低成本硬件进行了优化,并且可以部署在微控制器上。
72+
73+
![RTMDet COCO 基准测试](docs/images/rtmdet_coco_eval.png)
74+
75+
我们还对这些算法的训练过程进行了优化,现在训练过程比以前快得多。
76+
77+
### YOLOv8、YOLOv8 Pose、Nvidia Tao Models 和 ByteTrack
78+
79+
通过 [SSCMA-Micro](https://github.com/Seeed-Studio/SSCMA-Micro),现在您可以在微控制器上部署最新的 [YOLOv8](https://github.com/ultralytics/ultralytics)、YOLOv8 Pose 和 [Nvidia TAO Models](https://docs.nvidia.com/tao/tao-toolkit/text/model_zoo/cv_models/index.html)。我们还添加了 [ByteTrack](https://github.com/ifzhang/ByteTrack) 算法,以在低成本硬件上实现实时物体跟踪。
80+
81+
<div align="center"><img width="98%" src="https://files.seeedstudio.com/sscma/docs/images/SSCMA-WebCam-Tracking.gif"/></div>
82+
83+
### Swift YOLO
84+
85+
我们实现了一个轻量级的目标检测算法,称为 Swift YOLO,它专为在计算能力有限的低成本硬件上运行而设计。可视化工具、模型训练和导出命令行界面现已重构。
86+
87+
<div align="center"><img width="98%" src="https://files.seeedstudio.com/sscma/docs/static/esp32/images/person_detection.png"/></div>
88+
89+
### 仪表识别
90+
91+
仪表是我们日常生活和工业生产中常见的仪器,例如模拟仪表、数字仪表等。SSCMA 提供了可以用来识别各种仪表读数的仪表识别算法。
92+
93+
<div align="center"><img width="98%" src="https://files.seeedstudio.com/sscma/docs/static/grove/images/pfld_meter.gif"/></div>
94+
95+
## SSCMA 工具链
96+
97+
SSCMA 提供了完整的工具链,让用户可以轻松地在低成本硬件上部署 AI 模型,包括:
98+
99+
- [SSCMA-Model-Zoo](https://github.com/Seeed-Studio/sscma-model-zoo) SSCMA 模型库为您提供了一系列针对不同应用场景的预训练模型。
100+
- [SSCMA-Micro](https://github.com/Seeed-Studio/SSCMA-Micro) 一个跨平台的框架,用于在微控制器设备上部署和应用 SSCMA 模型。
101+
- [Seeed-Arduino-SSCMA](https://github.com/Seeed-Studio/Seeed_Arduino_SSCMA) 支持 SSCMA-Micro 固件的 Arduino 库。
102+
- [SSCMA-Web-Toolkit](https://seeed-studio.github.io/SenseCraft-Web-Toolkit) 一个基于 Web 的工具,用于更新设备固件、SSCMA 模型和参数。
103+
- [Python-SSCMA](https://github.com/Seeed-Studio/python-sscma) 用于与微控制器进行交互的 Python 库,使用 SSCMA-Micro,并用于更高级别的深度学习应用。
104+
105+
## 致谢
106+
107+
SSCMA 是许多开发人员和贡献者的共同努力,感谢以下项目和组织对 SSCMA 的实现提供了参考和贡献:
108+
109+
- [OpenMMLab](https://openmmlab.com/)
110+
- [ONNX](https://github.com/onnx/onnx)
111+
- [NCNN](https://github.com/Tencent/ncnn)
112+
- [TinyNN](https://github.com/alibaba/TinyNeuralNetwork)
113+
114+
## 许可证
115+
116+
本项目在 [Apache 2.0 开源许可证](LICENSE) 下发布。

docs/images/rtmdet_coco_eval.png

169 KB
Loading

sscma/models/detectors/rtmdet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
2+
from typing import List, Tuple, Union
23
import torch
4+
from torch import Tensor
35

46
from mmengine.dist import get_world_size
57
from mmengine.logging import print_log
68

9+
from sscma.structures import SampleList
710
from sscma.utils.typing_utils import ConfigType, OptConfigType, OptMultiConfig
811
from .single_stage import SingleStageDetector
912

sscma/models/heads/rtmdet_head.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22
from typing import List, Optional, Tuple, Union, Sequence
33
import copy
4+
import math
45
import torch
56
import torch.nn as nn
67
from torch import Tensor
@@ -213,6 +214,7 @@ def forward(self, feats: Tuple[Tensor, ...]) -> tuple:
213214

214215
cls_scores = []
215216
bbox_preds = []
217+
216218
for idx, x in enumerate(feats):
217219
cls_feat = x
218220
reg_feat = x
@@ -225,13 +227,15 @@ def forward(self, feats: Tuple[Tensor, ...]) -> tuple:
225227
reg_feat = reg_layer(reg_feat)
226228

227229
reg_dist = self.rtm_reg[idx](reg_feat)
228-
# cls_scores.append(cls_score.permute(0,2,3,1).reshape(1,-1,self.num_classes))
229-
# bbox_preds.append(reg_dist.permute(0,2,3,1).reshape(1,-1,4))
230-
cls_scores.append(cls_score)
231-
bbox_preds.append(reg_dist)
230+
cls_scores.append(cls_score.permute(0,2,3,1).reshape(1,-1,self.num_classes))
231+
bbox_preds.append(reg_dist.permute(0,2,3,1).reshape(1,-1,4))
232+
# cls_scores.append(cls_score)
233+
# bbox_preds.append(reg_dist)#32,6,6,2
232234
return tuple(cls_scores), tuple(bbox_preds)
233235

234236

237+
238+
235239
class YOLOv5Head(BaseDenseHead):
236240
"""YOLOv5Head head used in `YOLOv5`.
237241
@@ -444,7 +448,7 @@ def predict_by_feat(
444448
cfg.multi_label = multi_label
445449

446450
num_imgs = len(batch_img_metas)
447-
featmap_sizes = [cls_score.shape[2:] for cls_score in cls_scores]
451+
featmap_sizes = [[int(math.sqrt(featmap.shape[1] // num_imgs))] * 2 for featmap in cls_scores]
448452

449453
# If the shape does not change, use the previous mlvl_priors
450454
if featmap_sizes != self.featmap_sizes:
@@ -456,18 +460,18 @@ def predict_by_feat(
456460

457461
mlvl_strides = [
458462
flatten_priors.new_full(
459-
(featmap_size.numel() * self.num_base_priors,), stride
463+
(featmap_size[0] * featmap_size[1] * self.num_base_priors,), stride
460464
)
461465
for featmap_size, stride in zip(featmap_sizes, self.featmap_strides)
462466
]
463467
flatten_stride = torch.cat(mlvl_strides)
464468

465469
flatten_cls_scores = [
466-
cls_score.permute(0, 2, 3, 1).reshape(num_imgs, -1, self.num_classes)
470+
cls_score.reshape(num_imgs, -1, self.num_classes)
467471
for cls_score in cls_scores
468472
]
469473
flatten_bbox_preds = [
470-
bbox_pred.permute(0, 2, 3, 1).reshape(num_imgs, -1, 4)
474+
bbox_pred.reshape(num_imgs, -1, 4)
471475
for bbox_pred in bbox_preds
472476
]
473477

@@ -1157,7 +1161,7 @@ def loss_by_feat(
11571161
dict[str, Tensor]: A dictionary of loss components.
11581162
"""
11591163
num_imgs = len(batch_img_metas)
1160-
featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
1164+
featmap_sizes = [[int(math.sqrt(featmap.shape[1] // num_imgs))] * 2 for featmap in cls_scores]
11611165
assert len(featmap_sizes) == self.prior_generator.num_levels
11621166

11631167
gt_info = gt_instances_preprocess(batch_gt_instances, num_imgs)
@@ -1177,7 +1181,7 @@ def loss_by_feat(
11771181

11781182
flatten_cls_scores = torch.cat(
11791183
[
1180-
cls_score.permute(0, 2, 3, 1).reshape(
1184+
cls_score.reshape(
11811185
num_imgs, -1, self.cls_out_channels
11821186
)
11831187
for cls_score in cls_scores
@@ -1187,11 +1191,12 @@ def loss_by_feat(
11871191

11881192
flatten_bboxes = torch.cat(
11891193
[
1190-
bbox_pred.permute(0, 2, 3, 1).reshape(num_imgs, -1, 4)
1194+
bbox_pred.reshape(num_imgs, -1, 4)
11911195
for bbox_pred in bbox_preds
11921196
],
11931197
1,
1194-
)
1198+
).contiguous()
1199+
11951200
flatten_bboxes = flatten_bboxes * self.flatten_priors_train[..., -1, None]
11961201
flatten_bboxes = distance2bbox(
11971202
self.flatten_priors_train[..., :2], flatten_bboxes

0 commit comments

Comments
 (0)