{"id":13400107,"url":"https://github.com/alankbi/detecto","last_synced_at":"2025-10-21T20:03:14.011Z","repository":{"id":44532673,"uuid":"227467008","full_name":"alankbi/detecto","owner":"alankbi","description":"Build fully-functioning computer vision models with PyTorch","archived":false,"fork":false,"pushed_at":"2024-07-25T11:20:23.000Z","size":33330,"stargazers_count":612,"open_issues_count":48,"forks_count":107,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-09-30T23:47:19.459Z","etag":null,"topics":["computer-vision","faster-rcnn","machine-learning","object-detection","python","pytorch"],"latest_commit_sha":null,"homepage":"https://detecto.readthedocs.io/","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/alankbi.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":"2019-12-11T21:50:28.000Z","updated_at":"2024-09-03T15:20:42.000Z","dependencies_parsed_at":"2024-10-25T19:50:26.582Z","dependency_job_id":"27fd3ebd-96a5-487e-8071-cf44dfe66118","html_url":"https://github.com/alankbi/detecto","commit_stats":{"total_commits":120,"total_committers":12,"mean_commits":10.0,"dds":0.125,"last_synced_commit":"c57b5fe3037bf8bc077a41d74c769dd5b164b994"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankbi%2Fdetecto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankbi%2Fdetecto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankbi%2Fdetecto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankbi%2Fdetecto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alankbi","download_url":"https://codeload.github.com/alankbi/detecto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234733016,"owners_count":18878417,"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":["computer-vision","faster-rcnn","machine-learning","object-detection","python","pytorch"],"created_at":"2024-07-30T19:00:48.383Z","updated_at":"2025-09-30T12:30:38.936Z","avatar_url":"https://github.com/alankbi.png","language":"Python","readme":"![Detecto Logo](assets/logo_words.svg)\n--------------------------------------\n    \n[![Documentation Status](https://readthedocs.org/projects/detecto/badge/?version=latest)](https://detecto.readthedocs.io/en/latest/?badge=latest)\n[![Downloads](https://pepy.tech/badge/detecto)](https://pepy.tech/project/detecto)\n\nDetecto is a Python package that allows you to build fully-functioning computer vision and object detection models with just 5 lines of code. \nInference on still images and videos, transfer learning on custom datasets, and serialization of models to files are just a few of Detecto's features. \nDetecto is also built on top of PyTorch, allowing an easy transfer of models between the two libraries.\n\nThe table below shows a few examples of Detecto's performance:   \n\nStill Image                                                                   |  Video\n:----------------------------------------------------------------------------:|:-----------------------------------------:\n\u003cimg src=\"./assets/apple_orange.png\" alt=\"Detecto still image\" width=\"500px\"\u003e | ![Video demo of Detecto](assets/demo.gif)\n\n# Installation\n\nTo install Detecto using pip, run the following command:\n\n`pip3 install detecto`\n\nInstalling with pip should download all of Detecto's dependencies automatically. \nHowever, if an issue arises, you can manually download the dependencies listed in the [requirements.txt](requirements.txt) file.\n\n# Usage\n\nThe power of Detecto comes from its simplicity and ease of use. Creating and running a pre-trained \n[Faster R-CNN ResNet-50 FPN](https://pytorch.org/docs/stable/torchvision/models.html#object-detection-instance-segmentation-and-person-keypoint-detection) \nfrom PyTorch's model zoo takes 4 lines of code:\n\n```python\nfrom detecto.core import Model\nfrom detecto.visualize import detect_video\n\nmodel = Model()  # Initialize a pre-trained model\ndetect_video(model, 'input_video.mp4', 'output.avi')  # Run inference on a video\n```\n\nBelow are several more examples of things you can do with Detecto:\n\n### Transfer Learning on Custom Datasets\n\nMost of the times, you want a computer vision model that can detect custom objects. With Detecto, you can train a model on a custom dataset with 5 lines of code: \n\n```python\nfrom detecto.core import Model, Dataset\n\ndataset = Dataset('custom_dataset/')  # Load images and label data from the custom_dataset/ folder\n\nmodel = Model(['dog', 'cat', 'rabbit'])  # Train to predict dogs, cats, and rabbits\nmodel.fit(dataset)\n\nmodel.predict(...)  # Start using your trained model!\n```\n\n### Inference and Visualization\n\nWhen using a model for inference, Detecto returns predictions in an easy-to-use format and provides several visualization tools:\n\n```python\n\nfrom detecto.core import Model\nfrom detecto import utils, visualize\n\nmodel = Model()\n\nimage = utils.read_image('image.jpg')  # Helper function to read in images\n\nlabels, boxes, scores = model.predict(image)  # Get all predictions on an image\npredictions = model.predict_top(image)  # Same as above, but returns only the top predictions\n\nprint(labels, boxes, scores)\nprint(predictions)\n\nvisualize.show_labeled_image(image, boxes, labels)  # Plot predictions on a single image\n\nimages = [...]\nvisualize.plot_prediction_grid(model, images)  # Plot predictions on a list of images\n\nvisualize.detect_video(model, 'input_video.mp4', 'output.avi')  # Run inference on a video\nvisualize.detect_live(model)  # Run inference on a live webcam\n```\n\n### Advanced Usage\n\nIf you want more control over how you train your model, Detecto lets you do just that:\n\n```python\n\nfrom detecto import core, utils\nfrom torchvision import transforms\nimport matplotlib.pyplot as plt\n\n# Convert XML files to CSV format\nutils.xml_to_csv('training_labels/', 'train_labels.csv')\nutils.xml_to_csv('validation_labels/', 'val_labels.csv')\n\n# Define custom transforms to apply to your dataset\ncustom_transforms = transforms.Compose([\n    transforms.ToPILImage(),\n    transforms.Resize(800),\n    transforms.ColorJitter(saturation=0.3),\n    transforms.ToTensor(),\n    utils.normalize_transform(),\n])\n\n# Pass in a CSV file instead of XML files for faster Dataset initialization speeds\ndataset = core.Dataset('train_labels.csv', 'images/', transform=custom_transforms)\nval_dataset = core.Dataset('val_labels.csv', 'val_images')  # Validation dataset for training\n\n# Create your own DataLoader with custom options\nloader = core.DataLoader(dataset, batch_size=2, shuffle=True) \n\n# Use MobileNet instead of the default ResNet\nmodel = core.Model(['car', 'truck', 'boat', 'plane'], model_name='fasterrcnn_mobilenet_v3_large_fpn')\nlosses = model.fit(loader, val_dataset, epochs=15, learning_rate=0.001, verbose=True)\n\nplt.plot(losses)  # Visualize loss throughout training\nplt.show()\n\nmodel.save('model_weights.pth')  # Save model to a file\n\n# Directly access underlying torchvision model for even more control\ntorch_model = model.get_internal_model()\nprint(type(torch_model))\n```\n\nFor more examples, visit the [docs](https://detecto.readthedocs.io/), which includes a [quickstart](https://detecto.readthedocs.io/en/latest/usage/quickstart.html) tutorial.\n\nAlternatively, check out the [demo on Colab](https://colab.research.google.com/drive/1ISaTV5F-7b4i2QqtjTa7ToDPQ2k8qEe0).  \n\n# API Documentation\n\nThe full API documentation can be found at [detecto.readthedocs.io](https://detecto.readthedocs.io/en/latest/api/index.html).\nThe docs are split into three sections, each corresponding to one of Detecto's modules:\n\n### Core\n\nThe [detecto.core](https://detecto.readthedocs.io/en/latest/api/core.html) module contains the central classes of the package: Dataset, DataLoader, and Model. \nThese are used to read in a labeled dataset and train a functioning object detection model.\n\n### Utils\n\nThe [detecto.utils](https://detecto.readthedocs.io/en/latest/api/utils.html) module contains a variety of useful helper functions. \nWith it, you can read in images, convert XML files into CSV files, apply standard transforms to images, and more.\n\n### Visualize\n\nThe [detecto.visualize](https://detecto.readthedocs.io/en/latest/api/visualize.html) module is used to display labeled images, plot predictions, and run object detection on videos.\n\n\n\n# Contributing\n\nAll issues and pull requests are welcome! To run the code locally, first fork the repository and then run the following commands on your computer: \n\n```bash\ngit clone https://github.com/\u003cyour-username\u003e/detecto.git\ncd detecto\n# Recommended to create a virtual environment before the next step\npip3 install -r requirements.txt\n```\n\nWhen adding code, be sure to write unit tests and docstrings where necessary.  \n\nTests are located in `detecto/tests` and can be run using pytest:\n\n`python3 -m pytest`\n\nNote that some tests may fail due to them requiring a pretrained model file. \nThis file can be downloaded [here](https://www.dropbox.com/s/kjalrfs3la97du8/model.pth?dl=1)\nand should be placed at `detecto/tests/static/model.pth`.\n\nTo generate the documentation locally, run the following commands:\n\n```bash\ncd docs\nmake html\n```\n\nThe documentation can then be viewed at `docs/_build/html/index.html`.\n\n# Contact\n\nDetecto was created by [Alan Bi](https://www.alanbi.com/). Feel free to reach out on [Twitter](https://twitter.com/alankbi) or through [email](mailto:alan.bi326@gmail.com)!\n","funding_links":[],"categories":["Machine Learning","Python","Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries","Researchers"],"sub_categories":["CV｜计算机视觉:","CV:","General-Purpose Machine Learning","Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankbi%2Fdetecto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falankbi%2Fdetecto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankbi%2Fdetecto/lists"}