# A Simple Pipeline to Train PyTorch FasterRCNN Model
Train PyTorch FasterRCNN models easily on any custom dataset. Choose between official PyTorch models trained on COCO dataset, or choose any backbone from Torchvision classification models, or even write your own custom backbones.
***You can run a Faster RCNN model with Mini Darknet backbone and Mini Detection Head at more than 150 FPS on an RTX 3080***.
![](readme_images/gif_1.gif)
## Get Started
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1oFxPpBeE8SzSQq7BTUv28IIqQeiHHLdj?usp=sharing) [![Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://www.kaggle.com/code/sovitrath/custom-faster-rcnn-training-kaggle/notebook)
* [Find blog posts/tutorials on DebuggerCafe](#Tutorials)
## [Check All Updates Here](https://github.com/sovit-123/fasterrcnn-pytorch-training-pipeline/blob/main/docs/updates.md)
**Latest Update**
* Filter classes to visualize during inference using the `--classes` command line argument with space separated class indices from the dataset YAML file.
For example, to visualize only persons in COCO dataset, use, `python inference.py --classes 1 <rest of the command>`
To visualize person and car, use, `python inference.py --classes 1 3 <rest of the command>`
* Added Deep SORT Real-Time tracking to `inference_video.py` and `onnx_video_inference.py`. Using `--track` command with the usual inference command. Support for **MobileNet** Re-ID for now.
## Custom Model Naming Conventions
***For this repository:***
* **Small head refers to 512 representation size in the Faster RCNN head and predictor.**
* **Tiny head refers to 256 representation size in the Faster RCNN head and predictor.**
* **Nano head refers to 128 representation size in the Faster RCNN head and predictor.**
## [Check All Available Model Flags](#A-List-of-All-Model-Flags-to-Use-With-the-Training-Script)
## Go To
* [Setup on Ubuntu](#Setup-for-Ubuntu)
* [Setup on Windows](#Setup-on-Windows)
* [Train on Custom Dataset](#Train-on-Custom-Dataset)
* [Inference](#Inference)
* [Evaluation](#Evaluation)
* [Available Models](#A-List-of-All-Model-Flags-to-Use-With-the-Training-Script)
* [Tutorials](#Tutorials)
## Setup on Ubuntu
1. Clone the repository.
```bash
git clone https://github.com/sovit-123/fastercnn-pytorch-training-pipeline.git
```
2. Install requirements.
1. **Method 1**: If you have CUDA and cuDNN set up already, do this in your environment of choice.
```bash
pip install -r requirements.txt
```
2. **Method 2**: If you want to install PyTorch with CUDA Toolkit in your environment of choice.
```bash
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
```
OR
```bash
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
```
OR install the version with CUDA support as per your choice from **[here](https://pytorch.org/get-started/locally/)**.
Then install the remaining **[requirements](https://github.com/sovit-123/fasterrcnn-pytorch-training-pipeline/blob/main/requirements.txt)**.
## Setup on Windows
1. **First you need to install Microsoft Visual Studio from [here](https://my.visualstudio.com/Downloads?q=Visual%20Studio%202017)**. Sing In/Sing Up by clicking on **[this link](https://my.visualstudio.com/Downloads?q=Visual%20Studio%202017)** and download the **Visual Studio Community 2017** edition.
![](readme_images/vs-2017-annotated.jpg)
Install with all the default chosen settings. It should be around 6 GB. Mainly, we need the C++ Build Tools.
2. Then install the proper **`pycocotools`** for Windows.
```bash
pip install git+https://github.com/gautamchitnis/cocoapi.git@cocodataset-master#subdirectory=PythonAPI
```
3. Clone the repository.
```bash
git clone https://github.com/sovit-123/fastercnn-pytorch-training-pipeline.git
```
4. Install PyTorch with CUDA support.
```bash
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
```
OR
```bash
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
```
OR install the version with CUDA support as per your choice from **[here](https://pytorch.org/get-started/locally/)**.
Then install the remaining **[requirements](https://github.com/sovit-123/pytorch-efficientdet-api/blob/main/requirements.txt)** except for `pycocotools`.
## Train on Custom Dataset
Taking an exmaple of the [smoke dataset](https://www.kaggle.com/didiruh/smoke-pascal-voc) from Kaggle. Let's say that the dataset is in the `data/smoke_pascal_voc` directory in the following format. And the `smoke.yaml` is in the `data_configs` directory. Assuming, we store the smoke data in the `data` directory
```bash
├── data
│ ├── smoke_pascal_voc
│ │ ├── archive
│ │ │ ├── train
│ │ │ └── valid
│ └── README.md
├── data_configs
│ └── smoke.yaml
├── models
│ ├── create_fasterrcnn_model.py
│ ...
│ └── __init__.py
├── outputs
│ ├── inference
│ └── training
│ ...
├── readme_images
│ ...
├── torch_utils
│ ├── coco_eval.py
│ ...
├── utils
│ ├── annotations.py
│ ...
├── datasets.py
├── inference.py
├── inference_video.py
├── __init__.py
├── README.md
├── requirements.txt
└── train.py
```
The content of the `smoke.yaml` should be the following:
```yaml
# Images and labels direcotry should be relative to train.py
TRAIN_DIR_IMAGES: ../../xml_od_data/smoke_pascal_voc/archive/train/images
TRAIN_DIR_LABELS: ../../xml_od_data/smoke_pascal_voc/archive/train/annotations
# VALID_DIR should be relative to train.py
VALID_DIR_IMAGES: ../../xml_od_data/smoke_pascal_voc/archive/valid/images
VALID_DIR_LABELS: ../../xml_od_data/smoke_pascal_voc/archive/valid/annotations
# Class names.
CLASSES: [
'__background__',
'smoke'
]
# Number of classes (object classes + 1 for background class in Faster RCNN).
NC: 2
# Whether to save the predictions of the validation set while training.
SAVE_VALID_PREDICTION_IMAGES: True
```
***Note that*** *the data and annotations can be in the same directory as well. In that case, the TRAIN_DIR_IMAGES and TRAIN_DIR_LABELS will save the same path. Similarly for VALID images and labels. The `datasets.py` will take care of that*.
Next, to start the training, you can use the following command.
**Command format:**
```bash
python train.py --data <path to the data config YAML file> --epochs 100 --model <model name (defaults to fasterrcnn_resnet50)> --name <folder name inside output/training/> --batch 16
```
**In this case, the exact command would be:**
```bash
python train.py --data data_configs/smoke.yaml --epochs 100 --model fasterrcnn_resnet50_fpn --name smoke_training --batch 16
```
**The terimal output should be similar to the following:**
```
Number of training samples: 665
Number of validation samples: 72
3,191,405 total parameters.
3,191,405 training parameters.
Epoch 0: adjusting learning rate of group 0 to 1.0000e-03.
Epoch: [0] [ 0/84] eta: 0:02:17 lr: 0.000013 loss: 1.6518 (1.6518) time: 1.6422 data: 0.2176 max mem: 1525
Epoch: [0] [83/84] eta: 0:00:00 lr: 0.001000 loss: 1.6540 (1.8020) time: 0.0769 data: 0.0077 max mem: 1548
Epoch: [0] Total time: 0:00:08 (0.0984 s / it)
creating index...
index created!
Test: [0/9] eta: 0:00:02 model_time: 0.0928 (0.0928) evaluator_time: 0.0245 (0.0245) time: 0.2972 data: 0.1534 max mem: 1548
Test: [8/9]
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
https://blog.csdn.net/lidashent/article/details/134058091?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22134058091%22%2C%22source%22%3A%22lidashent%22%7D和这个相匹配,使用方式是在推理py中测试效果
资源推荐
资源详情
资源评论
收起资源包目录
王者血条图像识别fasterrcnn-mobilenetv3-large-fpn模型权重文件和相关工程文件 (195个子文件)
events.out.tfevents.1698260823.3PXDTCGE0Q2EPCC.41072.0 1KB
events.out.tfevents.1698260896.3PXDTCGE0Q2EPCC.41072.1 899B
events.out.tfevents.1698260896.3PXDTCGE0Q2EPCC.41072.2 899B
gif_1.gif 1.2MB
.gitignore 215B
custom_faster_rcnn_training_colab.ipynb 1.75MB
custom_faster_rcnn_training_kaggle.ipynb 1.49MB
visualizations.ipynb 666KB
image_10_1.jpg 92KB
image_13_1.jpg 92KB
image_11_1.jpg 91KB
image_9_1.jpg 90KB
image_6_1.jpg 90KB
image_3_1.jpg 90KB
image_12_1.jpg 90KB
image_2_1.jpg 89KB
image_5_1.jpg 89KB
image_4_1.jpg 89KB
image_8_1.jpg 88KB
image_0_1.jpg 87KB
image_14_1.jpg 87KB
image_15_1.jpg 86KB
image_7_1.jpg 86KB
image_1_1.jpg 85KB
image_1.jpg 78KB
vs-2017-annotated.jpg 39KB
aa.jpg 39KB
image_2.jpg 30KB
wandb-metadata.json 1KB
wandb-metadata.json 1KB
wandb-metadata.json 1KB
wandb-metadata.json 1KB
wandb-summary.json 26B
wandb-summary.json 26B
wandb-summary.json 26B
LICENSE 1KB
debug-internal.log 679KB
debug-internal.log 16KB
debug-internal.log 16KB
debug-internal.log 16KB
debug-cli.Administrator.log 5KB
debug.log 3KB
debug.log 3KB
debug.log 3KB
debug.log 3KB
README.md 16KB
README.md 2KB
updates.md 2KB
README.md 1KB
upcoming_updates.md 909B
README.md 122B
smokTest1.mp4 5.91MB
video_1.mp4 883KB
predictions_394_4057c1d577a08b387bb9.png 1.53MB
predictions_315_1bbe38991c149e34a710.png 1.53MB
predictions_631_125cde9a38c94cdc635f.png 1.53MB
predictions_78_74a8cfeec113d9872792.png 1.53MB
predictions_236_554946ef803375164a28.png 1.53MB
predictions_552_31fd056be11f45ad32d1.png 1.53MB
predictions_473_27973096636e0683b2e0.png 1.53MB
predictions_157_fed481c311eb03603c42.png 1.53MB
bb.png 567KB
train_loss_iter.png 71KB
vs-2017.png 41KB
train_loss_cls.png 36KB
train_loss_epoch.png 32KB
train_loss_bbox_reg.png 32KB
train_loss_rpn_bbox.png 29KB
train_loss_obj.png 24KB
last_model.pth 144.52MB
last_model_state.pth 72.5MB
best_model.pth 72.5MB
layers.py 32KB
train.py 19KB
datasets.py 15KB
fasterrcnn_vitdet_tiny.py 13KB
fasterrcnn_vitdet.py 13KB
general.py 12KB
inference_video1.py 9KB
inference_video.py 9KB
inference1.py 9KB
coco_utils.py 9KB
utils.py 8KB
inference.py 8KB
eval.py 8KB
onnx_inference_video.py 7KB
create_fasterrcnn_model.py 7KB
fasterrcnn_mini_darknet_nano_head.py 7KB
logging.py 7KB
onnx_inference_image.py 6KB
coco_eval.py 6KB
annotations.py 6KB
engine.py 6KB
fasterrcnn_darknet.py 5KB
fasterrcnn_nano.py 5KB
fasterrcnn_mini_darknet.py 5KB
fasterrcnn_custom_resnet.py 4KB
fasterrcnn_mini_squeezenet1_1_tiny_head.py 4KB
fasterrcnn_mini_squeezenet1_1_small_head.py 4KB
fasterrcnn_mbv3_small_nano_head.py 4KB
共 195 条
- 1
- 2
资源评论
lidashent
- 粉丝: 1499
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- fdgsfdgfdsgsf
- 基于CodeMirror5实现的mybatis+sql提示扩展功能,主要是用于在线设计开发场景中的动态sql部分.zip
- 计算机毕业设计-aSP.NET某中学学生成绩管理系统的设计(源代码+)-毕设源码实例.zip
- springboot集成mybatis动态sql.zip
- mybatis中的动态sql, 涉及 where trim set if foreach等
- 简单- 快递运输(Java & JS & Python & C).html
- mybatis框架 更改ems系统,使用动态sql等.zip
- 易语言工具条下拉菜单实现
- Mybatis动态SQL高级映射.zip
- 源码esp8266开发板机智云机智云智能灯
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功