A data augmentation package for converting segmentation data to detection data.
Project description
Seg2DetAugment
中文 | English
Overview
Seg2DetAugment is a Python package used for converting semantic segmentation data into object detection data and providing advanced data augmentation functions. Through operations such as rotation and background replacement, this tool generates a detection dataset with rotational invariance and adaptability to complex backgrounds, effectively enhancing the robustness of the model in complex scenarios.
When performing object detection tasks, the background often affects the accuracy of our recognition. For example, the model sometimes misidentifies the background as an object, or makes recognition errors when two objects partially occlude each other. Moreover, convolutional neural networks have limitations in rotational adaptability and lack an explicit rotational invariance mechanism. That is to say, when objects are placed in a rotated position, they usually become difficult to recognize, and the confidence level is low, etc. If you have tried the rotation augmentation methods available on the market, you will find that they all have the bug that the bounding box (bbox) inexplicably becomes larger. This is inevitable. Only when the contour of the object is known can rotation ensure that the bbox remains the circumscribed rectangle. Therefore, it is necessary to propose a dataset augmentation method to provide the model with the performance of an object under different backgrounds and the state of the object at different rotation angles.
Core Advantages
- Enhanced Rotational Invariance: Maintains the accuracy of the bounding box after rotation through contour tracing technology.
- Adaptability to Complex Backgrounds: Supports dynamic background replacement and the superposition of multiple objects.
- Improved Annotation Efficiency: Only a small amount of semantic segmentation annotation is required to generate a large-scale detection dataset.
Typical Application Scenarios
- Multi-angle object detection in industrial quality inspection.
- Adaptation to complex backgrounds in the scenario of garbage classification.
- Recognition of multi-pose targets in remote sensing images.
Installation Method
pip install Seg2DetAugment
Making Dataset
Install Anylabeling.
conda create -n anylabeling python=3.8 anaconda
conda activate anylabeling
CPU:
pip install anylabeling
GPU:
pip install anylabeling-gpu
After the installation is completed, run it using the command.
anylabeling
When you need to execute it next time, you just need to do this.
conda activate anylabeling
anylabeling
Prepare the folder containing the images you want to annotate, and click here to select your image folder.
Then click on this icon of the brain to start the SAM (Segment Anything Model) annotation.
Select a model you want. The model will be automatically downloaded from the internet.
Then click the "+Point" button and just click on the object.
If the calculated boundary curve meets your requirements, click "finish". If there are any issues, you can click on the wrongly marked area with the "-Point" button, and it will automatically recalculate.
Enter the name you want. The names for the same object must be identical.
After completing all the markings, all your labels and images will be saved in the same folder, just like this.
Then, prepare several blank background images like I do. Please try to create some differences among these background images as much as possible.
Quick Start
from Seg2DetAugment import data_augmentation
# Define the category mapping
dics = {
'battery': 0,
'bottle': 1,
# ... Other categories
}
# Run data augmentation
data_augmentation(
dics=dics,
output_folder="output",
path2labels="path/to/labels",
path2imgs="path/to/images",
path2bkgs="path/to/backgrounds",
counts=3, # Number of objects per image
threshold=0.5, # Overlap threshold
num_images=100 # Total number of generated images
)
Output Structure
output/
├── label/
│ ├── 0.txt
│ └── ...
└── img/
├── 0.jpg
└── ...
Parameter Explanation
| Parameter Name | Description | Default Value |
|---|---|---|
dics |
Mapping of category labels | Required |
output_folder |
Path of the output directory | Required |
path2labels |
Path of the input segmentation labels | Required |
path2imgs |
Path of the input original images | Required |
path2bkgs |
Path of the background images | Required |
counts |
Maximum number of objects in a single image | 3 |
threshold |
Overlap detection threshold (IOU) | 0.5 |
num_images |
Total number of generated images | 100 |
Detailed Explanation of threshold
The following is an example to explain the function of threshold.
As shown in the figure, there is actually a strip of radish inside the purple box, but it is completely (100%) occluded by a mineral water bottle and a Fanta bottle. If this dataset is used for training an object detection model, the consequences will be disastrous. Therefore, the function of the threshold is to ensure that at least 50% of the area of each object is visible. That is to say, occlusion is allowed, but the maximum occlusion rate is 50%, not 100%.
Set threshold to the occlusion rate you want. For example, when threshold = 0.5, the generated result will be much more satisfactory.
Licence
This project is open source under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seg2detaugment-0.0.3.tar.gz.
File metadata
- Download URL: seg2detaugment-0.0.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5b7e23f3784871ddb4f0c611d36372a0b7462dc6b9ad8cdd17ff4037a5dad9d
|
|
| MD5 |
06a5f3dc393416f11df785e8aa4a29c9
|
|
| BLAKE2b-256 |
2129258406db81c2222b8fa4597c613a2f60591d2bf9490d53f18f4f41654dc9
|
Provenance
The following attestation bundles were made for seg2detaugment-0.0.3.tar.gz:
Publisher:
python-publish.yml on Huuuuugh/Seg2DetAugment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
seg2detaugment-0.0.3.tar.gz -
Subject digest:
a5b7e23f3784871ddb4f0c611d36372a0b7462dc6b9ad8cdd17ff4037a5dad9d - Sigstore transparency entry: 183194160
- Sigstore integration time:
-
Permalink:
Huuuuugh/Seg2DetAugment@b0c7dfc62148666f4bccb1f8bd2b5c45254d8187 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Huuuuugh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b0c7dfc62148666f4bccb1f8bd2b5c45254d8187 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file seg2detaugment-0.0.3-py3-none-any.whl.
File metadata
- Download URL: seg2detaugment-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c36898989a56a26c7e91747dc8b586262f9f2f6963aea9bbc18f5ba99cb5ad79
|
|
| MD5 |
c583b6d6ae2505ff38e25b4513925d64
|
|
| BLAKE2b-256 |
ba0c592ccfb8de3449a977f11970f2e46cdb53c12c6e9d55a386d27ff205e01c
|
Provenance
The following attestation bundles were made for seg2detaugment-0.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on Huuuuugh/Seg2DetAugment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
seg2detaugment-0.0.3-py3-none-any.whl -
Subject digest:
c36898989a56a26c7e91747dc8b586262f9f2f6963aea9bbc18f5ba99cb5ad79 - Sigstore transparency entry: 183194163
- Sigstore integration time:
-
Permalink:
Huuuuugh/Seg2DetAugment@b0c7dfc62148666f4bccb1f8bd2b5c45254d8187 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Huuuuugh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b0c7dfc62148666f4bccb1f8bd2b5c45254d8187 -
Trigger Event:
workflow_dispatch
-
Statement type: