# ResNet50
**Repository Path**: xdltek/ResNet50
## Basic Information
- **Project Name**: ResNet50
- **Description**: Efficient image classification pipeline optimized for RPP-based inference systems
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-07-10
- **Last Updated**: 2026-07-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ResNet50 Inference Demo on RPP
Language: [English](#english) | [中文](#chinese)
This repository is a customer-facing C++ demo for running ResNet50 image classification on the RPP accelerator platform. The host program runs on CPU and uses OpenRT/RppRT to execute the model on RPP.
## Quick Start
Build and prepare the default model:
```bash
scripts/build.sh
```
Run:
```bash
scripts/run.sh --demo rgb
```
Benchmark:
```bash
scripts/benchmark.sh --demo rgb --loop 20
```
## Repository Layout
- `CMakeLists.txt`: root build entry for `resnet_utils`, `rpp_inference`, `rpp_resnet_preprocess`, `resnet_core`, and `resnet_rgb_image_demo`.
- `weights/`: local model directory; model files are ignored by Git and `.gitkeep` keeps the directory.
- `assets/`: sample RGB image copied into `build/assets`.
- `demos/rgb_image/`: RGB/BGR image demo with warmup, measured loops, and timing output.
- `docs/`: public documentation entry and API index.
- `rpp/inference/`: reusable RppRT inference engine wrapper.
- `rpp/preprocess/`: ResNet50 image preprocessing on RPP.
- `scripts/`: standard build, run, and benchmark entries.
- `src/resnet/`: ResNet50 pipeline, CPU top-k post-processing, and ImageNet labels.
- `src/utils/`: shared OpenRT helpers, logging, parser utilities, and buffer management.
- `3rd_party/`: bundled third-party headers.
## Requirements
- CMake 3.16.3 or newer.
- C++17-capable compiler.
- OpenCV `core`, `imgproc`, and `imgcodecs`.
- OpenRT/RppRT installed under `/usr/local/rpp`.
## Build
```bash
scripts/build.sh
```
Use `scripts/build.sh --skip-model` when the default model has already been prepared or network access is unavailable.
## Run
```bash
scripts/run.sh --demo rgb --loop 1
```
For direct binary execution:
```bash
build/bin/resnet_rgb_image_demo -o weights/resnet50.onnx -i assets/reflex_camera.jpeg -l 1
```
If `-i` is not provided to the binary, the demo uses `../assets/reflex_camera.jpeg` relative to `build/bin`.
## Arguments
- `-o`, `--onnx`: ONNX model path. Default: `../../weights/resnet50.onnx`.
- `-i`, `--image`: input image path. Default: `../assets/reflex_camera.jpeg`.
- `-l`, `--loop`: measured loop count after one warmup pass. Default: `1`.
- `-v`, `--verbose`: enable verbose inference logging.
## Output
- Prints selected model and input image paths.
- Prints ImageNet top-k classification results.
- Prints average Input H2D and Output D2H transfer times separately.
- Prints preprocess, inference, CPU postprocess, and end-to-end latency.
- End-to-end latency excludes H2D and D2H transfer time.
- No rendered image file is produced.
## Key Source Files
- `demos/rgb_image/main.cpp`: CLI, warmup, measured loop, and summary output.
- `src/resnet/resnet_pipeline.cpp`: reusable ResNet50 RGB input pipeline.
- `src/resnet/resnet_postprocessor.cpp`: output validation and top-k label reporting.
- `src/resnet/labels.cpp`: ImageNet label accessor.
- `src/resnet/imagenet_labels.h`: built-in ImageNet label list.
- `rpp/preprocess/rpp_resnet_preprocessor.cpp`: H2D staging, resize, normalization, and NCHW packing.
- `rpp/inference/rpp_infer_engine.cpp`: RppRT model build, binding, execute, and output copy workflow.
- `src/utils/rpp_buffer_manager.h`: host/device buffer management.
## Execution Workflow
```text
Parse CLI arguments
|
v
Load RGB/BGR image with OpenCV
|
v
Initialize ResNet50 pipeline and RPP inference engine
|
v
Warmup once
|
v
Measured loop:
H2D -> preprocess -> inference -> D2H -> postprocess
|
v
Print top-k classes and timing summary
```
## Reuse
- Reuse `ResNetPipeline::runRgb()` for host `cv::Mat` inputs.
- Reuse `rpp/inference/` for compatible ONNX inference flows.
- Reuse `rpp/preprocess/` for ResNet50-style RGB/BGR preprocessing.
- Replace `src/resnet/imagenet_labels.h` if your model uses a different label set.
---
# ResNet50 RPP 推理 Demo
语言:[English](#english) | [中文](#chinese)
本仓库是面向客户验证和移植的 C++ Demo,用于在 RPP 加速平台上运行 ResNet50 图像分类。Host 程序运行在 CPU 上,通过 OpenRT/RppRT 驱动 RPP 执行模型推理。
## 快速开始
构建并准备默认模型:
```bash
scripts/build.sh
```
运行:
```bash
scripts/run.sh --demo rgb
```
性能测量:
```bash
scripts/benchmark.sh --demo rgb --loop 20
```
## 仓库结构
- `CMakeLists.txt`:构建 `resnet_utils`、`rpp_inference`、`rpp_resnet_preprocess`、`resnet_core` 和 `resnet_rgb_image_demo`。
- `weights/`:本地模型目录,模型文件被 Git 忽略,`.gitkeep` 用于保留目录。
- `assets/`:默认 RGB 样例图片。
- `demos/rgb_image/`:RGB/BGR 图片 demo,包含 warmup、测量 loop 和耗时输出。
- `docs/`:公开文档入口和 API 索引。
- `rpp/inference/`:可复用 RppRT 推理 engine 封装。
- `rpp/preprocess/`:ResNet50 图像前处理 RPP 实现。
- `scripts/`:标准构建、运行和 benchmark 入口。
- `src/resnet/`:ResNet50 pipeline、CPU top-k 后处理和 ImageNet 标签。
- `src/utils/`:OpenRT 公共工具、日志、参数解析和 buffer 管理。
- `3rd_party/`:随仓库提供的第三方头文件。
## 环境要求
- CMake 3.16.3 或更高版本。
- 支持 C++17 的编译器。
- OpenCV `core`、`imgproc`、`imgcodecs`。
- OpenRT/RppRT 安装在 `/usr/local/rpp`。
## 构建
```bash
scripts/build.sh
```
默认模型已准备好或网络不可用时,可使用 `scripts/build.sh --skip-model`。
## 运行
```bash
scripts/run.sh --demo rgb --loop 1
```
直接执行二进制:
```bash
build/bin/resnet_rgb_image_demo -o weights/resnet50.onnx -i assets/reflex_camera.jpeg -l 1
```
如果不向二进制传 `-i`,demo 使用相对 `build/bin` 的 `../assets/reflex_camera.jpeg`。
## 参数
- `-o`, `--onnx`:ONNX 模型路径,默认 `../../weights/resnet50.onnx`。
- `-i`, `--image`:输入图片路径,默认 `../assets/reflex_camera.jpeg`。
- `-l`, `--loop`:warmup 后的测量 loop 次数,默认 `1`。
- `-v`, `--verbose`:开启详细推理日志。
## 输出
- 打印模型路径和输入图片路径。
- 打印 ImageNet top-k 分类结果。
- 单独打印 Input H2D 和 Output D2H 传输耗时。
- 打印前处理、推理、CPU 后处理和端到端耗时。
- 端到端耗时按前处理加推理统计,不包含 H2D、D2H 和 CPU 后处理耗时。
- 当前分类 demo 不生成渲染图片。
## 关键源码
- `demos/rgb_image/main.cpp`:命令行、warmup、测量 loop 和汇总输出。
- `src/resnet/resnet_pipeline.cpp`:可复用 ResNet50 RGB 输入 pipeline。
- `src/resnet/resnet_postprocessor.cpp`:输出校验和 top-k 标签报告。
- `src/resnet/labels.cpp`:ImageNet 标签访问接口。
- `src/resnet/imagenet_labels.h`:内置 ImageNet 标签列表。
- `rpp/preprocess/rpp_resnet_preprocessor.cpp`:H2D staging、resize、normalize 和 NCHW 打包。
- `rpp/inference/rpp_infer_engine.cpp`:RppRT 模型构建、binding、execute 和输出回传。
- `src/utils/rpp_buffer_manager.h`:Host/device buffer 管理。
## 执行流程
```text
解析命令行参数
|
v
使用 OpenCV 加载 RGB/BGR 图片
|
v
初始化 ResNet50 pipeline 和 RPP inference engine
|
v
执行一次 warmup
|
v
测量 loop:
H2D -> 前处理 -> 推理 -> D2H -> 后处理
|
v
打印 top-k 分类结果和耗时汇总
```
## 复用建议
- 复用 `ResNetPipeline::runRgb()` 处理 host `cv::Mat` 输入。
- 复用 `rpp/inference/` 承载兼容 ONNX 推理流程。
- 复用 `rpp/preprocess/` 承载 ResNet50 风格 RGB/BGR 前处理。
- 如果模型标签不同,替换 `src/resnet/imagenet_labels.h`。