{"id":22882523,"url":"https://github.com/bnbsking/cosmodules","last_synced_at":"2025-04-14T21:11:35.215Z","repository":{"id":139525939,"uuid":"458091188","full_name":"bnbsking/COSMOduleS","owner":"bnbsking","description":"Classification, Object detection, Segmentation MOduleS. Such as automatic format conversion, visualization, metrics with plotting and exporting suspected data.","archived":false,"fork":false,"pushed_at":"2024-12-25T13:34:20.000Z","size":100035,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T21:11:23.828Z","etag":null,"topics":["classification","conversion-tool","metrics-exporter","object-detection","segmentation","visualization-tools"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/bnbsking.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":"2022-02-11T07:44:09.000Z","updated_at":"2024-12-25T13:34:24.000Z","dependencies_parsed_at":"2024-12-08T10:25:48.337Z","dependency_job_id":"a4bd2795-3794-4f3f-a129-89b2ca37f3e7","html_url":"https://github.com/bnbsking/COSMOduleS","commit_stats":null,"previous_names":["bnbsking/0-object-detection-tools","bnbsking/object-detection-tools","bnbsking/cosmos","bnbsking/cosmodules"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnbsking%2FCOSMOduleS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnbsking%2FCOSMOduleS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnbsking%2FCOSMOduleS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnbsking%2FCOSMOduleS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnbsking","download_url":"https://codeload.github.com/bnbsking/COSMOduleS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961236,"owners_count":21189993,"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":["classification","conversion-tool","metrics-exporter","object-detection","segmentation","visualization-tools"],"created_at":"2024-12-13T18:18:07.106Z","updated_at":"2025-04-14T21:11:35.190Z","avatar_url":"https://github.com/bnbsking.png","language":"Jupyter Notebook","readme":"# COSMOduleS: Classification, Object detection, Segmentation MOduleS\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://pypi.python.org/pypi/cosmodules\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/cosmodules.svg\"\u003e\u003c/a\u003e\u003cbr\u003e\n  \u003ca href=\"https://pypi.org/project/cosmodules\"\u003e\u003cimg src=\"https://img.shields.io/pypi/pyversions/cosmodules.svg\"\u003e\u003c/a\u003e\u003cbr\u003e\n  Github: \u003ca href=\"https://github.com/bnbsking/COSMOduleS\"\u003esource\u003c/a\u003e \u003ca href=\"https://github.com/bnbsking/COSMOduleS\"\u003e\u003cimg src=\"https://github.com/bnbsking/COSMOduleS/blob/main/pictures/github-mark-white.png\" width=\"20\" height=\"20\"\u003e\u003c/a\u003e\n  \u003c!--\u003ca href=\"https://github.com/bnbsking/COSMOduleS\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/bnbsking/COSMOduleS\"\u003e\u003c/a\u003e\u003cbr\u003e--\u003e\n\u003c/div\u003e\n\n## **Introduction**\nThis repo provides comprehensive preprocessing and post-processing tools for common **Computer Vision** tasks.\n\n\n| Tasks | Subtasks | Defined\u003cbr\u003eFormat | Visualization | Format\u003cbr\u003eConversion | Output\u003cbr\u003eAnalysis | Label\u003cbr\u003eMerging | Active\u003cbr\u003eLearning |\n| - | - | - | - | - | - | - | - |\n| Classification | binary\u003csup\u003e1\u003c/sup\u003e\u003cbr\u003e binary-bg\u003csup\u003e2\u003c/sup\u003e\u003cbr\u003e multi-class\u003csup\u003e1\u003c/sup\u003e\u003cbr\u003e multiclass-bg\u003csup\u003e2\u003c/sup\u003e\u003cbr\u003e multi-binary\u003csup\u003e3\u003c/sup\u003e\u003cbr\u003e | [single_label](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/single_label.json)\u003csup\u003e1\u003c/sup\u003e\u003cbr\u003e [single_label_bg](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/single_label_background.json)\u003csup\u003e2\u003c/sup\u003e\u003cbr\u003e [multi_label](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/multi_label.json)\u003csup\u003e3\u003c/sup\u003e | - | - | [metrics\u003cbr\u003eplotting\u003cbr\u003eexport](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/s3_output_analysis.ipynb) | [ALL](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/s4_label_merging.ipynb) | [Entropy](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/s5_active_learning.ipynb) |\n| Detection      | - | [coco](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/data/coco)\u003cbr\u003e [voc](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/data/voc)\u003cbr\u003e [yolo](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/data/yolo)\u003cbr\u003e [**GENERAL**](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/data/general.json)\u003cbr\u003e | [ALL](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s1_visualization_gt_and_pd.ipynb) | [between ANY\u003cbr\u003etwo types](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s2_format_conversion.ipynb) | [metrics\u003cbr\u003eplotting\u003cbr\u003eexport](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s3_output_analysis.ipynb) | [V](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s4_label_merging.ipynb) | [horizontal\u003cbr\u003eflip](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s5_active_learning.ipynb) |\n| Segmentation   | instance\u003csup\u003e1\u003c/sup\u003e\u003cbr\u003e semantic\u003csup\u003e2\u003c/sup\u003e\u003cbr\u003e | [coco](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/data/coco)\u003csup\u003e1+2\u003c/sup\u003e\u003cbr\u003e [**GENERAL**](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/data/general)\u003csup\u003e1+2\u003c/sup\u003e | [ALL](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/s1_visualization_gt_and_pd.ipynb) | [coco2general](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/s2_format_conversion.ipynb) | [metrics\u003cbr\u003eplotting\u003cbr\u003eexport](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/s3_output_analysis.ipynb) | - | [instance\u003cbr\u003esemantic\u003cbr\u003e](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/s5_active_learning.ipynb) |\n\n\n+ \"bg\" means background. If there is background class, it must be class 0 in this repo.\n+ Adding prediction results after the defined format can use the visualization and output analysis. All the formats with predictions are in `example/*/prediction`, e.g. [here](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/prediction/general.json).\n\n\n## **Motivation**\n\n+ **[Classification]** Complicated tasks\n\n| task                                          | label idx min | compute class-0 metrics | threshold optimization | data format |  \n| -                                             | -             | -                       | -                      | -           |\n| binary classification                         | 0             | V                       | V                      | [single_label](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/single_label.json)       |\n| binary classification (cls-0 background)      | 1             |                         | V                      | [single_label_background](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/single_label_background.json) |\n| multi-class classification                    | 0             | V                       |                        | single_label |\n| multi-class classification (cls-0 background) | 1             |                         | V                      | single_label_background |\n| multi-label classification (cls-0 background) | 0             |                         | V                      | [multi_label](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/multi_label.json)   |\n\n\n+ **[Classification]** threshold optimization\n    + `multi-class classification (cls-0 background)` checks whether prob-cls-0 \u003c threshold, if yes, the pd-cls is pd[1:].argmax()\n    + `multi-class classification (cls-0 background)` and `multi-label classification (cls-0 background)` take the mean of all optimized threshold for each foreground class\n\n\n+ **[Object Detection]** Develop a [**GENERAL**](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/data/general.json) format to be the most convenient.\n\nThe formats can be summarized as following:\n| format | extension | files     | type  | box                      | disadvantage |\n| -      | -         | -         | -     | -                        | -            |\n| coco   | .json     | 1         | int   | (xmin, ymin, w, h)       | get label of an image |\n| yolo   | .txt      | len(imgs) | float | (cx, cy, w/2, h/2)       | visualization, compute metrics, etc. |\n| voc    | .xml      | len(imgs) | int   | (xmin, ymin, xmax, ymax) | get class list |\n| general| .json | 1 | int | (xmin, ymin, xmax, ymax) | **NO** |\n\n\n+ **[Segmentation]** Develop a [**GENERAL**](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/data/general) format to be the most convenient.\n\n\n| Includes         | Content | Advantage |\n| -                | -       | -         |\n| general.json     | Includes every imgs: path, contour, filled and boxes with class | Searching | \n| gt_contour_*.npy | (H, W) with {0, 1, ..., num_classes} int | Plotting |\n| gt_filled_*.npy  | (num_classes, H, W) with 0 or 1 int values | Compute IOU for Metrics |\n| *.jpg            | Raw data | - |\n\n\n+ Segmentation prediction format: `(num_classes, H, W) with 0~1 float values (probability)`. e.g. [here](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/prediction/instance/pd_filled_img1.npy)\n\n\n## **Installation**\n```bash\npip install cosmodules\n```\n\nor\n\n```bash\ngit clone https://github.com/bnbsking/COSMOduleS.git\npip install -e .\n```\n\n## **Quick Start - Classification**\n+ Output Analysis:\n    + Please conform your data format as either of one\n        + [single_label](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/single_label.json)\n        + [multilabel](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/multi_label.json)\n        + [single_label_background](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/data/single_label_background.json)\n    + The analysis pipeline is at [here](https://github.com/bnbsking/COSMOduleS/blob/main/cosmodules/classification/output_analysis.yaml)\n    + See more in the [example](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/s3_output_analysis.ipynb)\n\n```python\nfrom cosmodules.classification import ClassificationAnalysis\n\nClassificationAnalysis(\n    ant_path = \"example/classification/data/single_label.json\",\n    save_folder = \"example/classification/output/single_label\",\n)\n```\n\n+ Label Merging:\n```python\nfrom cosmodules.classification import ClassificationLabelMerging\n\nClassificationLabelMerging(\n    cfg_path_list = [\n        \"example/classification/data/single_label.json\",\n        \"example/classification/data_another_labeler/single_label.json\",\n    ],\n    save_path = f\"example/classification/output/label_merging/single_label.json\"\n)\n```\n\n+ Active Learning (see more in the [example](https://github.com/bnbsking/COSMOduleS/blob/main/example/classification/s5_active_learning.ipynb)):\n```python\nfrom cosmodules.classification import ClassificationActiveLearning\n\nClassificationActiveLearning(\n    pred_path = \"example/classification/prediction/single_label.json\",\n    save_path = \"example/classification/output/active_learning/single_label.json\",\n    loss_name = \"entropy\"\n)\n```\n\n## **Quick Start - Object detection**\n+ Format Conversion (see more in the [example](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s2_format_conversion.ipynb))\n\n```python\nfrom cosmodules.detection import coco2any\n\ncoco2any(\n    tgt_foramt = \"voc\",\n    img_folder = \"example/detection/data/coco\",\n    ant_path = \"example/detection/data/coco/coco.json\",\n    save_folder = \"example/detection/output/visualization_gt_conversion/coco2voc\"\n)\n```\n\nor \n\n```python\nfrom cosmodules.detection import coco2general\n\ncoco2general(\n    img_folder = \"example/detection/data/coco\",\n    ant_path = \"example/detection/data/coco/coco.json\",\n    save_path = \"example/detection/output/visualization_gt_conversion/coco2general/general.json\"\n)\n```\n\n+ Visualization (see more in the [example](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/s1_visualization_gt_and_pd.ipynb))\n\n```python\nfrom cosmodules.detection import show_coco\n\nshow_coco(\n    img_name = \"pic0.jpg\",\n    img_folder = \"example/detection/data/coco\",\n    ant_path = \"example/detection/data/coco/coco.json\"\n)\n```\n\nor\n\n```python\nfrom cosmodules.detection import show_general\n\nshow_general(\n    img_name = \"pic0.jpg\",\n    ant_path = \"example/detection/data/general.json\",\n)  # when the anntotation includes predictions it will be shown!\n```\n\n+ Output Analysis\n    + Please use the above `Format conversion` to change data format as [general](https://github.com/bnbsking/COSMOduleS/blob/main/example/detection/data/general.json)\n    + The analysis pipeline is at [here](https://github.com/bnbsking/COSMOduleS/blob/main/cosmodules/detection/output_analysis.yaml)\n\n```python\nfrom cosmodules.detection import DetectionAnalysis\n\nDetectionAnalysis(\n    ant_path = \"example/detection/data/general.json\",\n    save_folder = \"example/detection/output/metrics\"\n)\n```\n\n+ Label Merging:\n```python\nfrom cosmodules.detection import DetectionLabelMerging\n\nDetectionLabelMerging(\n    cfg_path_list = [\n        \"example/detection/data/general.json\",\n        \"example/detection/data_another_labeler/general.json\",\n    ],\n    save_path = \"example/detection/output/label_merging/general.json\",\n    ties_handling = \"union\"\n)\n```\n\n+ Active Learning:\n```python\nfrom cosmodules.detection import DetectionActiveLearningByHFlip\n\nDetectionActiveLearningByHFlip(\n    pred_path_1 = f\"{ROOT}/example/detection/prediction/general.json\",\n    pred_path_2 = f\"{ROOT}/example/detection/prediction/general_horizontal_flip.json\",\n    save_path = f\"{ROOT}/example/detection/output/active_learning/general.json\"\n)\n```\n\n## **Quick Start - Segmentation**\n+ Format Conversion (see more in the [example](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/s2_format_conversion.ipynb))\n\n```python\nfrom cosmodules.segmentation import coco2general\n\ncoco2general(\n    img_folder = \"example/segmentation/data/coco\",\n    ant_path = \"example/segmentation/data/coco/coco.json\",\n    save_folder = f\"example/segmentation/output/visualization_gt_conversion/coco2general\"\n)\n```\n\n+ Visualization (see more in the [example](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/s1_visualization_gt_and_pd.ipynb))\n\n```python\nfrom cosmodules.segmentation import show_coco\n\nshow_coco(\n    img_name = \"img1.jpg\",\n    img_folder = \"example/segmentation/data/coco\",\n    ant_path = \"example/segmentation/data/coco/coco.json\"\n)   # when the anntotation includes predictions it will be shown!\n```\n\nor\n\n```python\nfrom cosmodules.segmentation import show_general\n\nshow_general(\n    img_name = \"img1.jpg\",\n    ant_path = \"example/segmentation/data/general/general.json\"\n)\n```\n\n+ Output Analysis\n    + Please use the above `Format conversion` to change data format as [general](https://github.com/bnbsking/COSMOduleS/blob/main/example/segmentation/data/general)\n    + The analysis pipeline is at [here](https://github.com/bnbsking/COSMOduleS/blob/main/cosmodules/segmentation/output_analysis_instance.yaml)\n\n```python\nfrom cosmodules.segmentation import SegmentationAnalysis\n\nSegmentationAnalysis(\n    ant_path = \"example/segmentation/prediction/instance/general.json\",\n    save_folder = \"example/segmentation/output/metrics/instance\",\n    task = \"instance\",\n)\n```\n\nor\n\n```Python\nfrom cosmodules.segmentation import SegmentationAnalysis\n\nSegmentationAnalysis(\n    ant_path = \"example/segmentation/prediction/semantic/general.json\",\n    save_folder = \"example/segmentation/output/metrics/semantic\",\n    task = \"semantic\"\n)\n```\n\n+ Active Learning:\n```python\nfrom cosmodules.segmentation import (\n    InstanceSegmentationActiveLearningByHFlip,\n    SemanticSegmentationActiveLearning\n)\n\nInstanceSegmentationActiveLearningByHFlip(\n    pred_path_1 = \"example/segmentation/prediction/instance/general.json\",\n    pred_path_2 = \"example/segmentation/prediction/instance_horizontal_flip/general.json\",\n    save_path = \"example/segmentation/output/active_learning/instance.json\"\n)\n```\n\nor\n\n```python\nSemanticSegmentationActiveLearning(\n    pred_path = \"example/segmentation/prediction/semantic/general.json\",\n    save_path = \"example/segmentation/output/active_learning/semantic.json\",\n    loss_name = \"entropy\"\n)\n```\n\n## **Examples**\n+ **[detection]**: format conversion workflow\n![.](https://github.com/bnbsking/COSMOduleS/blob/main/pictures/detection_workflow.png)\n\n+ detection visualization\n![.](https://github.com/bnbsking/COSMOduleS/blob/main/pictures/detection_visualization.jpg)\n\n+ confusion\n![.](https://github.com/bnbsking/COSMOduleS/blob/main/pictures/confusion.jpg)\n\n+ prf curves\n![.](https://github.com/bnbsking/COSMOduleS/blob/main/pictures/prf_curves.jpg)\n\n\n## **More**\n+ Feel free to ask if you have any question.\n+ Notice not supported\n    + segmentation general2coco\n    + segmentation label merging\n\n\n## **Acknowledgement**\n+ Confusion Matrix reference [here](https://github.com/kaanakan/object_detection_confusion_matrix/blob/master/confusion_matrix.py)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnbsking%2Fcosmodules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnbsking%2Fcosmodules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnbsking%2Fcosmodules/lists"}