seg_mask_modifs
Description
A package for easy generation of binary semantic mask of different labels using multiple models easily. Moreover, supports operations on the mask created for image editing.
Curent models and labels supported:
- Deeplabv3 with pascal labels
- Maskrcnn with coco labels
- Bisnet with face labels
Usage
Installation
pip:
pip install seg-mask-modifs
pip install opencv-contrib-python>=4.5.4.60
# if you install opencv-python then inpainting won't work
Cloning repo then install requirements:
pip install -r requirements.txt
Documentation
The documentation of the different classes and functions is available here
Usage
Download models
The models can be downloaded seperately or all of then can be downloaded at once.
from seg_mask_modifs import download_models
download_models.download_all() # download all models with default names which is highly recommended.
download_models.maskrcnn_coco(save_path='models/maskrcnn_restnet50_fpn.pt') # download maskrcnn model with coco labels
download_models.deeplab_pascal() # download deeplab model
download_models.face() # download bisnet face model
Labels
To see the list of labels supported by the package, this function can be used.
from seg_mask_modifs import print_labels
print_labels.all() # prints all labels
print_labels.deeplab_pascal() # prints pascal labels
print_labels.maskrcnn_coco() # prints coco labels
print_label.face() # prints face labels
Mask Generation
Class to generate binary mask for any combination of labels. The models will be automatically used according to model preference and labels provided.
import cv2
from seg_mask_modifs import mask_generator
mask_gen = mask_generator.mask_generator(threshold=0.5, auto_init=True) # auto_init will only work if the models are saved to the default path.
# if auto_init is false or different path used to save model initialize them manually.
mask_gen.init_maskrcnn('maskrcnn.pt')
mask_gen.init_deeplab('deeplab.pt')
mask_gen.init_face('face.pth')
img = cv2.imread('images/city.jpg')
mask = mask_gen.generate(img=img, labels=['person', 'suitcase'])
In the example above the test image passed is:
This generates the following output, using deeplabv3 for person and maskrcnn for suitcase:
To generate mask use only one model, the use_model argument can be used.
mask = mask_gen.generate(img=img, labels=['person', 'suitcase'], use_model='maskrcnn')
By default, the deeplab model has the highest priority followed by maskrcnn and then bisnet face model. Any label which is supported by more than model will be generated by the one with higher preference. To check the model preference:
mask_gen.print_model_preference()
To change the model preference:
mask_gen.set_model_preference(model_list['maskrcnn', 'face', 'deeplab'])
mask_gen.set_model_preference(model='face', pos=0)
The model preference can be set using a list, or giving a particular model a particular position. Note: if model is not found in the list, it will be ignored.
Mask Utilities
Functions to combine, invert, dilate, etc. on multiple masks at once. Take a look at the documentation for more details.
Mask Modifications
Functions to modify masks. Includes various operations like blurring, pixelaing, replacing, inpainting the background and foreground among other operations. Take a look at the documentation for complete details. Some examples are given below.
Blurring Foreground
Drawing outline
Pixelate foreground
Grayscale background
References
Metadata
Release files for seg-mask-modifs 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| seg_mask_modifs-1.2.0.tar.gz | 16.7 kB | Without provenance | Details for seg_mask_modifs-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| seg_mask_modifs-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for seg_mask_modifs-1.2.0-py3-none-any.whl |
Total release size: 34.3 kB
Release files / seg_mask_modifs-1.2.0.tar.gz
| Download URL | seg_mask_modifs-1.2.0.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ac1a7cd3a9102a8358131cfaaa2d6c45dffe0f1101c8a4b89188930c92c2d80
|
|
BLAKE2b-256 checksum How to use checksums |
1b6952d20faf0c98c57c929f205bc7705750a8ef2fdd919215aadfbf3e712733
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / seg_mask_modifs-1.2.0-py3-none-any.whl
| Download URL | seg_mask_modifs-1.2.0-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b68778b1db60e4f6f5a44eaba88f59e7cc35b2c80ca6714cd4f18c8bb36eafa7
|
|
BLAKE2b-256 checksum How to use checksums |
65cc95e9c87a8f51c54e194bae894789b8d0c1065014b97cd9bb58b7031c3727
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for seg-mask-modifs 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.