Skip to content

ADILShakoor/Object-detection-using-yolov8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv8 Object Detection Project

This project demonstrates object detection using the YOLOv8 model. The notebook leverages Google Colab and Google Drive to train and test a YOLOv8 model on custom data. A fruit detection model from image using yolov8 model Here's a README.md template based on the code you've shared for an object detection project using YOLOv8 in Google Colab. This file will include sections describing the setup, usage, and code explanations.

Dataset

dataset have fallowing type of image each object in image is annotated by bounding box

  • Apple
  • Banana
  • Grape
  • Orange
  • Pineapple
  • Watermelon

Project Structure

  • notebooks/: Contains the Colab notebook for object detection with YOLOv8.
  • data/: Dataset with training images and annotations.
  • results/: Directory for storing training results and output predictions.

Requirements

  • Python 3.x
  • YOLOv8 (installed via ultralytics package)
  • Google Colab and Google Drive for storage

Installation

  1. Clone the repository and navigate to the project folder:

    git clone : https://github.com/ADILShakoor/Object-detection-using-yolov8.git
    cd your-repo-name
  2. In the Google Colab notebook, install the required packages:

    !pip install ultralytics

Usage

The following steps explain how to use the Colab notebook to train and test the model.

  1. Set Up Google Drive: Mount Google Drive to access and save files.

    from google.colab import drive
    drive.mount('/content/drive')
  2. Install YOLOv8:

    !pip install ultralytics
    from ultralytics import YOLO
  3. Train the Model:

    • Define the path to the YOLOv8 model and data configuration file.
    • Start the training process with specified epochs and image size.
    model = YOLO("yolov8m.pt")
    ROOT_DIR = '/content/drive/MyDrive/path current dir'
    results = model.train(data=os.path.join(ROOT_DIR, "data.yaml"), epochs=20, imgsz=640)
  4. Save Results to Google Drive:

    • Copy the results to Google Drive to retain training outputs.
    import shutil
    destination = '/content/drive/MyDrive/yolov8_003_results'
    if os.path.exists(destination):
        shutil.rmtree(destination)
    shutil.copytree('/content/runs', destination)
  5. Make Predictions:

    • Use the trained model to make predictions on new images.
    load the model which you trained
    model = YOLO("weights/best.pt")
    results = model.predict("test01.jpg")
  6. Extract Prediction Details:

    • Retrieve bounding boxes, object class, and confidence scores for each prediction.
    result = results[0]
    for box in result.boxes:
        class_id = result.names[box.cls[0].item()]
        cords = [round(x) for x in box.xyxy[0].tolist()]
        conf = round(box.conf[0].item(), 2)
        print("Object type:", class_id)
        print("Coordinates:", cords)
        print("Probability:", conf)
        print("--")

Example Output

An example output showing object type, bounding box coordinates, and probability:

Object type: cat
Coordinates: [50, 30, 200, 180]
Probability: 0.85
--
Object type: dog
Coordinates: [120, 60, 300, 220]
Probability: 0.90
--

Results

  • Model Accuracy:

  • results R_curve PR_curve P_curve labels_correlogram labels F1_curve confusion_matrix_normalized confusion_matrix

  • results Images: val_batch2_labels val_batch1_pred val_batch1_labels val_batch0_pred val_batch0_labels train_batch4502val_batch2_pred train_batch4501 train_batch4500 train_batch2 train_batch1 train_batch0

License

This project is licensed under the MIT License. See the LICENSE file for details.


About

A fruit detection model from image using yolov8 model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published