{"id":13443836,"url":"https://github.com/yhenon/pytorch-retinanet","last_synced_at":"2025-09-27T10:31:38.270Z","repository":{"id":39460986,"uuid":"130927929","full_name":"yhenon/pytorch-retinanet","owner":"yhenon","description":"Pytorch implementation of RetinaNet object detection.","archived":true,"fork":false,"pushed_at":"2023-04-29T14:16:18.000Z","size":1039,"stargazers_count":2138,"open_issues_count":148,"forks_count":664,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-09-20T17:17:37.461Z","etag":null,"topics":["python","pytorch","retinanet"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yhenon.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}},"created_at":"2018-04-25T00:15:22.000Z","updated_at":"2024-09-18T07:28:15.000Z","dependencies_parsed_at":"2024-01-12T19:48:18.057Z","dependency_job_id":"f365b5e7-967a-44fd-96d4-0056aceaa124","html_url":"https://github.com/yhenon/pytorch-retinanet","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/yhenon%2Fpytorch-retinanet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhenon%2Fpytorch-retinanet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhenon%2Fpytorch-retinanet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhenon%2Fpytorch-retinanet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yhenon","download_url":"https://codeload.github.com/yhenon/pytorch-retinanet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219871973,"owners_count":16554475,"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":["python","pytorch","retinanet"],"created_at":"2024-07-31T03:02:11.560Z","updated_at":"2025-09-27T10:31:32.997Z","avatar_url":"https://github.com/yhenon.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# pytorch-retinanet\n\n![img3](https://github.com/yhenon/pytorch-retinanet/blob/master/images/3.jpg)\n![img5](https://github.com/yhenon/pytorch-retinanet/blob/master/images/5.jpg)\n\nPytorch  implementation of RetinaNet object detection as described in [Focal Loss for Dense Object Detection](https://arxiv.org/abs/1708.02002) by Tsung-Yi Lin, Priya Goyal, Ross Girshick, Kaiming He and Piotr Dollár.\n\nThis implementation is primarily designed to be easy to read and simple to modify.\n\n## Results\nCurrently, this repo achieves 33.5% mAP at 600px resolution with a Resnet-50 backbone. The published result is 34.0% mAP. The difference is likely due to the use of Adam optimizer instead of SGD with weight decay.\n\n## Installation\n\n1) Clone this repo\n\n2) Install the required packages:\n\n```\napt-get install tk-dev python-tk\n```\n\n3) Install the python packages:\n\t\n```\npip install pandas\npip install pycocotools\npip install opencv-python\npip install requests\n\n```\n\n## Training\n\nThe network can be trained using the `train.py` script. Currently, two dataloaders are available: COCO and CSV. For training on coco, use\n\n```\npython train.py --dataset coco --coco_path ../coco --depth 50\n```\n\nFor training using a custom dataset, with annotations in CSV format (see below), use\n\n```\npython train.py --dataset csv --csv_train \u003cpath/to/train_annots.csv\u003e  --csv_classes \u003cpath/to/train/class_list.csv\u003e  --csv_val \u003cpath/to/val_annots.csv\u003e\n```\n\nNote that the --csv_val argument is optional, in which case no validation will be performed.\n\n## Pre-trained model\n\nA pre-trained model is available at: \n- https://drive.google.com/open?id=1yLmjq3JtXi841yXWBxst0coAgR26MNBS (this is a pytorch state dict)\n\nThe state dict model can be loaded using:\n\n```\nretinanet = model.resnet50(num_classes=dataset_train.num_classes(),)\nretinanet.load_state_dict(torch.load(PATH_TO_WEIGHTS))\n```\n\n## Validation\n\nRun `coco_validation.py` to validate the code on the COCO dataset. With the above model, run:\n\n`python coco_validation.py --coco_path ~/path/to/coco --model_path /path/to/model/coco_resnet_50_map_0_335_state_dict.pt`\n\n\nThis produces the following results:\n\n```\n Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.335\n Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.499\n Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.357\n Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.167\n Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.369\n Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.466\n Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.282\n Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.429\n Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.458\n Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.255\n Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.508\n Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.597\n```\n\nFor CSV Datasets (more info on those below), run the following script to validate:\n\n`python csv_validation.py --csv_annotations_path path/to/annotations.csv --model_path path/to/model.pt --images_path path/to/images_dir --class_list_path path/to/class_list.csv   (optional) iou_threshold iou_thres (0\u003ciou_thresh\u003c1) `\n\nIt produces following resullts:\n\n```\nlabel_1 : (label_1_mAP)\nPrecision :  ...\nRecall:  ...\n\nlabel_2 : (label_2_mAP)\nPrecision :  ...\nRecall:  ...\n```\n\nYou can also configure csv_eval.py script to save the precision-recall curve on disk.\n\n\n\n## Visualization\n\nTo visualize the network detection, use `visualize.py`:\n\n```\npython visualize.py --dataset coco --coco_path ../coco --model \u003cpath/to/model.pt\u003e\n```\nThis will visualize bounding boxes on the validation set. To visualise with a CSV dataset, use:\n\n```\npython visualize.py --dataset csv --csv_classes \u003cpath/to/train/class_list.csv\u003e  --csv_val \u003cpath/to/val_annots.csv\u003e --model \u003cpath/to/model.pt\u003e\n```\n\n## Model\n\nThe retinanet model uses a resnet backbone. You can set the depth of the resnet model using the --depth argument. Depth must be one of 18, 34, 50, 101 or 152. Note that deeper models are more accurate but are slower and use more memory.\n\n## CSV datasets\nThe `CSVGenerator` provides an easy way to define your own datasets.\nIt uses two CSV files: one file containing annotations and one file containing a class name to ID mapping.\n\n### Annotations format\nThe CSV file with annotations should contain one annotation per line.\nImages with multiple bounding boxes should use one row per bounding box.\nNote that indexing for pixel values starts at 0.\nThe expected format of each line is:\n```\npath/to/image.jpg,x1,y1,x2,y2,class_name\n```\n\nSome images may not contain any labeled objects.\nTo add these images to the dataset as negative examples,\nadd an annotation where `x1`, `y1`, `x2`, `y2` and `class_name` are all empty:\n```\npath/to/image.jpg,,,,,\n```\n\nA full example:\n```\n/data/imgs/img_001.jpg,837,346,981,456,cow\n/data/imgs/img_002.jpg,215,312,279,391,cat\n/data/imgs/img_002.jpg,22,5,89,84,bird\n/data/imgs/img_003.jpg,,,,,\n```\n\nThis defines a dataset with 3 images.\n`img_001.jpg` contains a cow.\n`img_002.jpg` contains a cat and a bird.\n`img_003.jpg` contains no interesting objects/animals.\n\n\n### Class mapping format\nThe class name to ID mapping file should contain one mapping per line.\nEach line should use the following format:\n```\nclass_name,id\n```\n\nIndexing for classes starts at 0.\nDo not include a background class as it is implicit.\n\nFor example:\n```\ncow,0\ncat,1\nbird,2\n```\n\n## Acknowledgements\n\n- Significant amounts of code are borrowed from the [keras retinanet implementation](https://github.com/fizyr/keras-retinanet)\n- The NMS module used is from the [pytorch faster-rcnn implementation](https://github.com/ruotianluo/pytorch-faster-rcnn)\n\n## Examples\n\n![img1](https://github.com/yhenon/pytorch-retinanet/blob/master/images/1.jpg)\n![img2](https://github.com/yhenon/pytorch-retinanet/blob/master/images/2.jpg)\n![img4](https://github.com/yhenon/pytorch-retinanet/blob/master/images/4.jpg)\n![img6](https://github.com/yhenon/pytorch-retinanet/blob/master/images/6.jpg)\n![img7](https://github.com/yhenon/pytorch-retinanet/blob/master/images/7.jpg)\n![img8](https://github.com/yhenon/pytorch-retinanet/blob/master/images/8.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhenon%2Fpytorch-retinanet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyhenon%2Fpytorch-retinanet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhenon%2Fpytorch-retinanet/lists"}