This article introduces dry goods: SOLOv2 training your own data set nanny level tutorial with code!
Dry stuff: SOLOv2 training your own data set nanny level tutorial with code!
Full text dry goods more, suggested collection to see, by the way a like!
This article focuses on how to train your own data sets using SOLOv2. Someone has been able to transfer SOLOv2 to TensorRT for industrial deployment before this. So how to train your own data set is a pre-issue, since training data set is needed by many people, this article will show you how to implement step by step, and we will also put a code link at the bottom of the article. If you find it useful, you are welcome to share, retweet, and follow our official account!
Please note that this article is not based on the official MMDetection version! Please download our fork(linked at the end of the article) version to do this.
To summarize the new additions included in our release:
- Training of custom data sets
- SOLOv2 – Lite version
- Backbone can be replaced
- Support ONNX export
- TensorRT acceleration (internal)
SOLOv2 is awesome
Recently I saw the release of version 2.0 of PaddlePaddle Detection and I saw the effects of SOlOv2 in the below and it was really nice
But I don’t use many paddles. I think the pits are not too shallow, so I wanted to use the PyTorch for this set.
Actually, I think we did a pretty good job:
We can not only frame, but also mask, this colorful and colorful really beautiful. Note that the figure above is pure C++ reasoning and can be accelerated using TensorRT. In other words, we’ve got the training and deployment set up.
An overview of the framework
We are not using the official Solov2 MMDetection version, which is too old, but based on MMDetection1.0. Although we have upgraded a version according to the 2.0 upgrade method, it is not very easy to use. This time, I switched to Detectron2.
The rest of the tutorial will be based on Detectron2.
How do I prepare my own data set
The data set format we use is Coco. Because this data format is used more often, it is also well supported in Dectron2. If your data is already in COCO format, great, you just need to visualize it.
Here’s an Amway tool for you: Alfret-py. This is a great collection of open source deep learning tools that are easy to install:
pip install alfred-py
Copy the code
We can then visualize your Coco data using the Alfred command.
How do you do that?
alfred data cocoview -j annotations.json -i images/
Copy the code
Pass in your JSON and the image’s root directory, and the visualization is done. If you don’t believe it, you can directly try to visualize coco data.
This tool is also useful for validating your data format! It’s also convenient for us to check the data
Shouldn’t this be a great tool to share with the people around you? It’s like a silver bullet in a pinch.
There are many other features of this library that you can explore slowly. The tool also allows you to convert between different data sets! For example, coco to YOLO, VOC to YOLO and so on, all in one line command complete! No code to write!
If your data is all right, we’ll move on.
Our instance data set
I’ll just give you our own data set for a moment. We’ve already had success on coco. It’s best to train on a data set of your own. The data set we use is a simple classification of microcontrollers, which is mainly divided into:
CLASS_NAMES = ["Arduino", 'ESP8266', 'Heltec', 'Raspberry']
Copy the code
Something like this:
This data set is open source, you can go to Kaggle or Google, microcontroller power segmentation.
Register your own data set
In D2, the best way to train your dataset is to register your dataset into D2. So you can call your category from anywhere. Our usual approach is to make a copy of train_net.py in the tools folder.
Also make this change:
CLASS_NAMES = ["Arduino".'ESP8266'.'Heltec'.'Raspberry']
DATASET_ROOT = './data/microship'
ANN_ROOT = os.path.join(DATASET_ROOT, 'annotations')
TRAIN_PATH = os.path.join(DATASET_ROOT, 'train')
VAL_PATH = os.path.join(DATASET_ROOT, 'test')
TRAIN_JSON = os.path.join(ANN_ROOT, 'train.json')
VAL_JSON = os.path.join(ANN_ROOT, 'test.json')
PREDEFINED_SPLITS_DATASET = {
"microship_train": (TRAIN_PATH, TRAIN_JSON),
"microship_val": (VAL_PATH, VAL_JSON),
}
def plain_register_dataset() :
# training set
DatasetCatalog.register(
"microship_train".lambda: load_coco_json(TRAIN_JSON, TRAIN_PATH))
MetadataCatalog.get("microship_train").set(thing_classes=CLASS_NAMES,
evaluator_type='coco',
json_file=TRAIN_JSON,
image_root=TRAIN_PATH)
DatasetCatalog.register(
"microship_val".lambda: load_coco_json(VAL_JSON, VAL_PATH))
MetadataCatalog.get("microship_val").set(thing_classes=CLASS_NAMES,
evaluator_type='coco',
json_file=VAL_JSON,
image_root=VAL_PATH)
plain_register_dataset()
Copy the code
Simply make these specifications:
- The name of your category;
- Your annotations, data storage path, points
train
andval
.
Then register your dataset name.
Finally, under configs, within this configuration:
MODEL:
META_ARCHITECTURE: "SOLOv2"
MASK_ON: True
BACKBONE:
NAME: "build_resnet_fpn_backbone"
RESNETS:
OUT_FEATURES: ["res2"."res3"."res4"."res5"]
FPN:
IN_FEATURES: ["res2"."res3"."res4"."res5"]
DATASETS:
TRAIN: ("microship_train",)
TEST: ("microship_val",)
SOLVER:
IMS_PER_BATCH: 4
BASE_LR: 0.01
WARMUP_FACTOR: 0.01
WARMUP_ITERS: 1000
STEPS: (60000, 80000)
MAX_ITER: 90000
INPUT:
MIN_SIZE_TRAIN: (640, 672. 704. 736. 768. 800)
MASK_FORMAT: "bitmask"
VERSION: 2
Copy the code
Just write the name of your dataset.
One thing to note here:
- If you are single card training, here’s the
BASE_LR
I want to divide by 8; - Because the default is 8 cards
Personally, I suggest that if it is a very large data set, or use 8 card Xulian will converge faster.
How to Initiate training
Training is initiated with one command:
python3 tools/train_microship.py --config-file configs/SOLOv2/microship_dataset/R50_lite_3x.yaml
Copy the code
Just pass this config in.
Oh, and don’t forget to make sure the data set you’re registering is soft-linked correctly.
Well, this dry goods to share here, need code can be obtained here:
Manaai. Cn/aicodes_det…