{"id":18858745,"url":"https://github.com/autodistill/autodistill-transformers","last_synced_at":"2026-02-07T19:30:15.515Z","repository":{"id":205363271,"uuid":"714063877","full_name":"autodistill/autodistill-transformers","owner":"autodistill","description":"Use object detection models in Hugging Face Transformers to automatically label data to train a fine-tuned model.","archived":false,"fork":false,"pushed_at":"2023-12-05T09:25:13.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-30T21:06:04.544Z","etag":null,"topics":["computer-vision","object-detection"],"latest_commit_sha":null,"homepage":"https://docs.autodistill.com","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/autodistill.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":"2023-11-03T20:49:41.000Z","updated_at":"2023-11-09T20:40:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"92222ac0-42d1-4c65-ba9d-3cd71a1e8ea2","html_url":"https://github.com/autodistill/autodistill-transformers","commit_stats":null,"previous_names":["autodistill/autodistill-transformers"],"tags_count":0,"template":false,"template_full_name":"autodistill/autodistill-base-model-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autodistill%2Fautodistill-transformers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autodistill%2Fautodistill-transformers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autodistill%2Fautodistill-transformers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autodistill%2Fautodistill-transformers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autodistill","download_url":"https://codeload.github.com/autodistill/autodistill-transformers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239800418,"owners_count":19699121,"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","object-detection"],"created_at":"2024-11-08T04:14:34.795Z","updated_at":"2026-02-07T19:30:15.453Z","avatar_url":"https://github.com/autodistill.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cp\u003e\n    \u003ca align=\"center\" href=\"\" target=\"_blank\"\u003e\n      \u003cimg\n        width=\"850\"\n        src=\"https://media.roboflow.com/open-source/autodistill/autodistill-banner.png\"\n      \u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n# Autodistill Transformers Module\n\nThis repository contains the code supporting the Transformers models model for use with [Autodistill](https://github.com/autodistill/autodistill).\n\n[Transformers](https://github.com/huggingface/transformers), maintained by Hugging Face, features a range of state of the art models for Natural Language Processing (NLP), computer vision, and more.\n\nThis package allows you to write a function that calls a Transformers object detection model and use it to automatically label data. You can use this data to train a fine-tuned model using an architecture supported by Autodistill (i.e. [YOLOv8](https://github.com/autodistil/autodistill-yolov8), [YOLOv5](https://github.com/autodistil/autodistill-yolov5), or [DETR](https://github.com/autodistil/autodistill-detr)).\n\nRead the full [Autodistill documentation](https://autodistill.github.io/autodistill/).\n\n## Installation\n\nTo use Transformers with autodistill, you need to install the following dependency:\n\n```bash\npip3 install autodistill-transformers\n```\n\n## Quickstart\n\nThe following example shows how to use the Transformers module to label images using the [Owlv2ForObjectDetection](https://huggingface.co/google/owlv2-large-patch14-ensemble) model.\n\nYou can update the `inference()` functon to use any object detection model supported in the Transformers library.\n\n```python\nimport cv2\nimport torch\nfrom autodistill.detection import CaptionOntology\nfrom autodistill.utils import plot\nfrom transformers import OwlViTForObjectDetection, OwlViTProcessor\n\nfrom autodistill_transformers import TransformersModel\n\nprocessor = OwlViTProcessor.from_pretrained(\"google/owlvit-base-patch32\")\nmodel = OwlViTForObjectDetection.from_pretrained(\"google/owlvit-base-patch32\")\n\n\ndef inference(image, prompts):\n    inputs = processor(text=prompts, images=image, return_tensors=\"pt\")\n    outputs = model(**inputs)\n\n    target_sizes = torch.Tensor([image.size[::-1]])\n\n    results = processor.post_process_object_detection(\n        outputs=outputs, target_sizes=target_sizes, threshold=0.1\n    )[0]\n\n    return results\n\n\nbase_model = TransformersModel(\n    ontology=CaptionOntology(\n        {\n            \"a photo of a person\": \"person\",\n            \"a photo of a cat\": \"cat\",\n        }\n    ),\n    callback=inference,\n)\n\n# run inference\nresults = base_model.predict(\"image.jpg\", confidence=0.1)\n\nprint(results)\n\n# plot results\nplot(\n    image=cv2.imread(\"image.jpg\"),\n    detections=results,\n    classes=base_model.ontology.classes(),\n)\n\n# label a directory of images\nbase_model.label(\"./context_images\", extension=\".jpeg\")\n```\n\n## License\n\nThis project is licensed under an [MIT license](LICENSE).\n\n## 🏆 Contributing\n\nWe love your input! Please see the core Autodistill [contributing guide](https://github.com/autodistill/autodistill/blob/main/CONTRIBUTING.md) to get started. Thank you 🙏 to all our contributors!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautodistill%2Fautodistill-transformers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautodistill%2Fautodistill-transformers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautodistill%2Fautodistill-transformers/lists"}