{"id":15175876,"url":"https://github.com/vardanagarwal/seg_mask_modifs","last_synced_at":"2025-10-26T11:31:20.851Z","repository":{"id":40770023,"uuid":"375125116","full_name":"vardanagarwal/seg_mask_modifs","owner":"vardanagarwal","description":"Easily perform segmentation using different models and perform different operations on the mask.","archived":false,"fork":false,"pushed_at":"2024-08-31T19:46:07.000Z","size":275,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-31T18:56:35.286Z","etag":null,"topics":["deeplabv3","face-parsing","mask-rcnn","opencv","python","pytorch","segmentation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vardanagarwal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-08T19:38:59.000Z","updated_at":"2024-08-31T19:46:05.000Z","dependencies_parsed_at":"2023-12-26T10:02:47.646Z","dependency_job_id":"b607dd45-e4eb-48d8-9e21-bafada801279","html_url":"https://github.com/vardanagarwal/seg_mask_modifs","commit_stats":{"total_commits":72,"total_committers":5,"mean_commits":14.4,"dds":"0.41666666666666663","last_synced_commit":"b0cff2e4e4c4e418a4788cadb5aa9da24cbb248a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardanagarwal%2Fseg_mask_modifs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardanagarwal%2Fseg_mask_modifs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardanagarwal%2Fseg_mask_modifs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardanagarwal%2Fseg_mask_modifs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vardanagarwal","download_url":"https://codeload.github.com/vardanagarwal/seg_mask_modifs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238319450,"owners_count":19452339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deeplabv3","face-parsing","mask-rcnn","opencv","python","pytorch","segmentation"],"created_at":"2024-09-27T12:43:28.962Z","updated_at":"2025-10-26T11:31:20.456Z","avatar_url":"https://github.com/vardanagarwal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# seg_mask_modifs\n\n## Description\nA 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.\n\n### Update\nAdded support for SAM.\n\n### Curent models and labels supported:\n- Deeplabv3 with pascal labels\n- Maskrcnn with coco labels\n- Bisnet with face labels\n\n## Usage\n\n### Installation\npip:\n```\npip install seg-mask-modifs\npip install opencv-contrib-python\u003e=4.5.4.60\n# if you install opencv-python then inpainting won't work\n```\n\nCloning repo then install requirements:\n```\npip install -r requirements.txt\n```\n\n### Documentation\n\nThe documentation of the different classes and functions is available [here](https://vardanagarwal.github.io/seg_mask_modifs.html)\n\n### Usage\n\n### Download models\n[Documentation page](https://vardanagarwal.github.io/seg_mask_modifs/download_models.html)\n\nThe models can be downloaded seperately or all of then can be downloaded at once.\n\n```\nfrom seg_mask_modifs import download_models\n\ndownload_models.download_all() # download all models with default names which is highly recommended.\n\ndownload_models.maskrcnn_coco(save_path='models/maskrcnn_restnet50_fpn.pt') # download maskrcnn model with coco labels\ndownload_models.deeplab_pascal() # download deeplab model\ndownload_models.face() # download bisnet face model\n```\n\n### Labels\n[Documentation page](https://vardanagarwal.github.io/seg_mask_modifs/print_labels.html)\n\nTo see the list of labels supported by the package, this function can be used.\n\n```\nfrom seg_mask_modifs import print_labels\n\nprint_labels.all() # prints all labels\n\nprint_labels.deeplab_pascal() # prints pascal labels\nprint_labels.maskrcnn_coco() # prints coco labels\nprint_label.face() # prints face labels\n```\n\n### Mask Generation\n[Documentation page](https://vardanagarwal.github.io/seg_mask_modifs/mask_generator.html)\n\nClass to generate binary mask for any combination of labels. The models will be automatically used according to model preference and labels provided.\n\n```\nimport cv2\nfrom seg_mask_modifs import mask_generator\n\nmask_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.\n\n# if auto_init is false or different path used to save model initialize them manually.\nmask_gen.init_maskrcnn('maskrcnn.pt')\nmask_gen.init_deeplab('deeplab.pt')\nmask_gen.init_face('face.pth')\n\nimg = cv2.imread('images/city.jpg')\nmask = mask_gen.generate(img=img, labels=['person', 'suitcase'])\n```\n\nIn the example above the test image passed is:\n\n![City](seg_mask_modifs/images/city.jpg)\n\nThis generates the following output, using deeplabv3 for person and maskrcnn for suitcase:\n\n![Mask](seg_mask_modifs/images/city_mask.jpg)\n\nTo generate mask use only one model, the use_model argument can be used.\n```\nmask = mask_gen.generate(img=img, labels=['person', 'suitcase'], use_model='maskrcnn')\n```\n\nBy 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:\n\n```\nmask_gen.print_model_preference() \n```\n\nTo change the model preference:\n```\nmask_gen.set_model_preference(model_list['maskrcnn', 'face', 'deeplab'])\nmask_gen.set_model_preference(model='face', pos=0)\n```\nThe model preference can be set using a list, or giving a particular model a particular position. \nNote: if model is not found in the list, it will be ignored.\n\n### Mask Utilities\n[Documentation page](https://vardanagarwal.github.io/seg_mask_modifs/mask_utils.html)\n\nFunctions to combine, invert, dilate, etc. on multiple masks at once. Take a look at the documentation for more details.\n\n### Mask Modifications\n[Documentation page](https://vardanagarwal.github.io/seg_mask_modifs/mask_modifier.html)\n\nFunctions 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.\n\n#### Blurring Foreground\n![Blurring](seg_mask_modifs/images/face_blur_fg.jpg)\n\n#### Drawing outline\n![outline](seg_mask_modifs/images/city_outline.jpg)\n\n#### Pixelate foreground\n![Pixelate](seg_mask_modifs/images/city_pixelate_fg.jpg)\n\n#### Grayscale background\n![Grayscale](seg_mask_modifs/images/city_grayscale_bg.jpg)\n\n## References\n1. Face parsing: https://github.com/zllrunning/face-parsing.PyTorch\n2. Mask-RCNN: https://pytorch.org/vision/stable/_modules/torchvision/models/detection/mask_rcnn.html\n3. Deeplabv3: https://pytorch.org/vision/main/_modules/torchvision/models/segmentation/deeplabv3.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardanagarwal%2Fseg_mask_modifs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvardanagarwal%2Fseg_mask_modifs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardanagarwal%2Fseg_mask_modifs/lists"}