{"id":15642033,"url":"https://github.com/gau-nernst/centernet-lightning","last_synced_at":"2025-04-30T09:24:01.389Z","repository":{"id":37573613,"uuid":"371219102","full_name":"gau-nernst/centernet-lightning","owner":"gau-nernst","description":"Implementation of CenterNet and FairMOT with PyTorch Lightning","archived":false,"fork":false,"pushed_at":"2022-05-18T13:55:34.000Z","size":384,"stargazers_count":70,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-30T14:51:09.820Z","etag":null,"topics":["centernet","object-detection","object-tracking","pytorch","pytorch-lightning"],"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/gau-nernst.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}},"created_at":"2021-05-27T02:05:14.000Z","updated_at":"2025-03-24T17:39:18.000Z","dependencies_parsed_at":"2022-08-08T21:00:20.295Z","dependency_job_id":null,"html_url":"https://github.com/gau-nernst/centernet-lightning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gau-nernst%2Fcenternet-lightning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gau-nernst%2Fcenternet-lightning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gau-nernst%2Fcenternet-lightning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gau-nernst%2Fcenternet-lightning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gau-nernst","download_url":"https://codeload.github.com/gau-nernst/centernet-lightning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251675336,"owners_count":21625793,"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":["centernet","object-detection","object-tracking","pytorch","pytorch-lightning"],"created_at":"2024-10-03T11:53:43.705Z","updated_at":"2025-04-30T09:24:01.352Z","avatar_url":"https://github.com/gau-nernst.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CenterNet\n\nCenterNet is a strong **single-stage**, **single-scale**, and **anchor-free** object detector. This implementation is built with PyTorch Lightning, supports TorchScript and ONNX export, and has modular design to make customizing components simple.\n\nReferences\n\n- [Original CenterNet](https://github.com/xingyizhou/CenterNet)\n- [CenterNet-better-plus](https://github.com/lbin/CenterNet-better-plus)\n- [Simple-CenterNet](https://github.com/developer0hye/Simple-CenterNet)\n- [TF CenterNet](https://github.com/tensorflow/models/tree/master/research/object_detection)\n- [mmdetection CenterNet](https://github.com/open-mmlab/mmdetection/blob/master/mmdet/models/dense_heads/centernet_head.py)\n\nTo read more about the architecture and code structure of this implementation, see [implementation.md](docs/implementation.md)\n\n## Install\n\nDependencies\n\n```bash\nconda install pytorch torchvision cudatoolkit=11.3 -c pytorch\npip install pytorch-lightning pycocotools albumentations\npip install git+https://github.com/gau-nernst/vision-toolbox.git            # backbones and necks\npip install filterpy git+https://github.com/JonathonLuiten/TrackEval.git    # for FairMOT\npip install jsonargparse[signatures]                                        # for training\n```\n\n## Inference\n\n### Create a CenterNet model\n\nImport `build_centernet` from `models` to build a CenterNet model from a YAML file. Sample config files are provided in the `configs/` directory.\n\n```python\nfrom centernet_lightning.models import build_centernet\n\nmodel = build_centernet(\"configs/coco_resnet34.yaml\")\n```\n\nYou also can load a CenterNet model directly from a checkpoint thanks to PyTorch Lightning.\n\n```python\nfrom centernet_lightning.models import CenterNet\n\nmodel = CenterNet.load_from_checkpoint(\"path/to/checkpoint.ckpt\")\n```\n\n### Folder of images\n\nUse `CenterNet.inference_detection()` or `CenterNet.inference_tracking()`\n\n```python\nmodel = ...     # create a model as above\nimg_dir = \"path/to/img/dir\"\ndetections = model.inference_detection(img_dir, num_detections=100)\n```\n\n`detections` is a dictionary with the following keys:\n\nKey | Description | Shape\n----|-------------|-------\n`bboxes` | bounding boxes in x1y1x2y2 format | (num_images x num_detections x 4)\n`labels` | class labels | (num_images x num_detections)\n`scores` | confidence scores | (num_images x num_detections)\n\nResults are `np.ndarray`, ready for post-processing.\n\n### Single image\n\nThis is useful when you use `CenterNet` in your own applications\n\n```python\nimport numpy as np\nimport torch\nimport cv2\nimport albumentations as A\nfrom albumentations.pytorch import ToTensorV2\n\n# read image\nimg = cv2.imread(\"path/to/image\")\nimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n# apply pre-processing: resize to 512x512 and normalize with ImageNet statistics\n# use torchvision.transforms should work also\ntransforms = A.Compose([\n    A.Resize(height=512, width=512),\n    A.Normalize(),\n    ToTensorV2()\n])\nimg = transforms(image=img)[\"image\"]\n\n# create a model as above and put it in evaluation mode\nmodel = ...     \nmodel.eval()\n\n# turn off gradient calculation and do forward pass\nwith torch.no_grad():\n    encoded_outputs = model(img.unsqueeze(0))\n    detections = model.gather_detection2d(encoded_outputs)\n```\n\n`detections` has the same format as above, but the values are `torch.Tensor`.\n\nNote: Due to data augmentations during training, the model is robust enough to not need ImageNet normalization in inference. You can normalize input image to `[0,1]` and CenterNet should still work fine.\n\n## Deployment\n\n`CenterNet` is export-friendly. You can directly export a trained model to ONNX or TorchScript (only tracing) using PyTorch Lightning API\n\n```python\nimport torch\nfrom centernet_lightning.models import CenterNet\n\nmodel = CenterNet.load_from_checkpoint(\"path/to/checkpoint.ckpt\")\nmodel.to_onnx(\"model.onnx\", torch.rand((1,3,512,512)))      # export to ONNX\nmodel.to_torchscript(\"model.pt\", method=\"trace\")            # export to TorchScript. scripting might not work\n```\n\n### Evaluate a trained model\n\nWIP\n\n## Training CenterNet\n\nYou can train CenterNet with the provided train script `train.py` and a config file.\n\n```bash\npython train.py --config \"configs/coco_resnet34.yaml\"\n```\n\nSee sample config files at [configs/](configs/). To customize training, see [training.md](docs/training)\n\n## Datasets\n\nThe following dataset formats are supported:\n\nDetection:\n\n- [x] [COCO](https://cocodataset.org/)\n- [x] [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/)\n- [x] [CrowdHuman](https://www.crowdhuman.org/)\n\nTracking:\n\n- [x] [MOT](https://motchallenge.net/)\n- [x] [KITTI Tracking](http://www.cvlibs.net/datasets/kitti/eval_tracking.php)\n\nTo see how to use each dataset type, see [datasets.md](docs/datasets.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgau-nernst%2Fcenternet-lightning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgau-nernst%2Fcenternet-lightning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgau-nernst%2Fcenternet-lightning/lists"}