Coder Social home page Coder Social logo

autodistill / autodistill-yolov8 Goto Github PK

View Code? Open in Web Editor NEW
40.0 4.0 9.0 25 KB

YOLOv8 Target Model plugin for Autodistill

Home Page: https://docs.autodistill.com

License: GNU Affero General Public License v3.0

Makefile 21.70% Python 78.30%
autodistill computer-vision yolov8

autodistill-yolov8's Introduction

Autodistill: YOLOv8 Target Model

This repository contains the code implementing YOLOv8 as a Target Model for use with autodistill. You can also use a YOLOv8 model as a base model to auto-label data.

YOLOv8 is a Convolutional Neural Network (CNN) that supports realtime object detection, instance segmentation, and other tasks. It can be deployed to a variety of edge devices.

Read the full Autodistill documentation.

Read the YOLOv8 Autodistill documentation.

Installation

To use the YOLOv8 Target Model, simply install it along with a Base Model supporting the detection task:

pip3 install autodistill-grounded-sam autodistill-yolov8

You can find a full list of detection Base Models on the main autodistill repo.

Quickstart (Train a YOLOv8 Model)

from autodistill_grounded_sam import GroundedSAM
from autodistill.detection import CaptionOntology
from autodistill_yolov8 import YOLOv8

# define an ontology to map class names to our GroundingDINO prompt
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
base_model = GroundedSAM(ontology=CaptionOntology({"shipping container": "container"}))

# label all images in a folder called `context_images`
base_model.label(
  input_folder="./images",
  output_folder="./dataset"
)

target_model = YOLOv8("yolov8n.pt")
target_model.train("./dataset/data.yaml", epochs=200)

# run inference on the new model
pred = target_model.predict("./dataset/valid/your-image.jpg", confidence=0.5)
print(pred)

# optional: upload your model to Roboflow for deployment
from roboflow import Roboflow

rf = Roboflow(api_key="API_KEY")
project = rf.workspace().project("PROJECT_ID")
project.version(DATASET_VERSION).deploy(model_type="yolov8", model_path=f"./runs/detect/train/")

Quickstart (Use a YOLOv8 Model to Label Data)

from autodistill_yolov8 import YOLOv8Base
from autodistill.detection import CaptionOntology

# define an ontology to map class names to our YOLOv8 classes
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
# then, load the model

# replace weights_path with the path to your YOLOv8 weights file
base_model = YOLOv8Base(ontology=CaptionOntology({"car": "car"}), weights_path="yolov5s.pt")

# run inference on a single image
results = base_model.predict("mercedes.jpeg")

base_model.label(
  input_folder="./images",
  output_folder="./dataset"
)

Choosing a Task

YOLOv8 supports training both object detection and instance segmentation tasks at various sizes (larger models are slower but can be more accurate). This selection is done in the constructor.

For example:

# initializes a nano-sized instance segmentation model
target_model = YOLOv8("yolov8n-seg.pt")

Available object detection initialization options are:

  • yolov8n.pt - nano (3.2M parameters)
  • yolov8s.pt - small (11.2M parameters)
  • yolov8m.pt - medium (25.9M parameters)
  • yolov8l.pt - large (43.7M parameters)
  • yolov8x.pt - extra-large (68.2M parameters)

Available instance segmentation initialization options are:

  • yolov8n-seg.pt - nano (3.4M parameters)
  • yolov8s-seg.pt - small (11.8M parameters)
  • yolov8m-seg.pt - medium (27.3M parameters)
  • yolov8l-seg.pt - large (46.0M parameters)
  • yolov8x-seg.pt - extra-large (71.8M parameters)

License

The code in this repository is licensed under an AGPL 3.0 license.

๐Ÿ† Contributing

We love your input! Please see the core Autodistill contributing guide to get started. Thank you ๐Ÿ™ to all our contributors!

autodistill-yolov8's People

Contributors

capjamesg avatar skalskip avatar yeldarby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

autodistill-yolov8's Issues

device handling in yolov8.py: device=device?

Just a question:
Tried to run the code on windows, and DEVICE overwrote function parameter for self.yolo.train when run with cpu argument on machine with gpu. Is this behaviour intended?

call in main

target_model.train(DATA_YAML_PATH, epochs=2, device = 'cpu')

yolov8.py

DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")

class YOLOv8(DetectionTargetModel):
def init(self, model_name):
self.yolo = YOLO(model_name)

def train(self, dataset_yaml, epochs=300, device=DEVICE):
    print('My sanity', device)
    #self.yolo.train(data=dataset_yaml, epochs=epochs, device=DEVICE)     # CURRENT VERSION 
    self.yolo.train(data=dataset_yaml, epochs=epochs, device=device)         # now takes user definition of defice

Best regards,
Reinhard

Is related to FastSAM ?

Asking out of curiosity. Since the the framework is named with yolov8, by any chance is this work related to FastSAM?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.