Skip to content

Latest commit

 

History

History
139 lines (124 loc) · 4.88 KB

README.md

File metadata and controls

139 lines (124 loc) · 4.88 KB

CERVICURE

Cervicure

This repository contains the implementation of the YOLOv8 model for object detection as part of the CerviCure project. The model is trained to detect and classify objects in cervical cancer-related datasets. This README provides a step-by-step guide for setting up, training, and running the YOLOv8 model using Google Colab.

Table of Contents

Installation

  1. Clone the repository:
    git clone https://github.com/ArnavGhosh999/CerviCure.git
  2. Install the required dependencies:
    pip install ultralytics
  3. Check the environment setup for YOLOv8:
    import ultralytics
    ultralytics.checks()

Dataset Preparation

  1. Mount your Google Drive in Colab to access the dataset:
    from google.colab import drive
    drive.mount('/content/drive')
  2. Navigate to the project directory:
    %cd /content/drive/MyDrive/CerviCure.v2i.yolov8
  3. Update the data.yaml file with the paths to your training and validation datasets.

Training the Model

  1. Load the YOLOv8 model:
    from ultralytics import YOLO
    model = YOLO('yolov8m.pt')
  2. Fine-tune the model's training layers:
    layer_index = 0
    for param in model.parameters():
        param.requires_grad = (layer_index == 1)
        layer_index += 1
  3. Train the model:
    model.train(
        data='data.yaml',
        epochs=20,
        batch=16,
        imgsz=640,
        optimizer='Adam',
        lr0=0.001,
        weight_decay=0.0005
    )

Validating the Model

Run model validation to assess performance:

results = model.val()
print(results)

Running Predictions

  1. Make predictions using a trained model:
    !yolo task=detect mode=predict model=/content/drive/MyDrive/CerviCure.v2i.yolov8/runs/detect/train8/weights/best.pt source=/content/drive/MyDrive/Cervix save=True
  2. Use the predict_and_annotate function to run predictions on new images and visualize the results:
    import cv2
    import matplotlib.pyplot as plt
    annotated_image = predict_and_annotate('path_to_image.jpg')
    plt.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB))
    plt.show()

Generating Classes Code

  1. Generate Python code for class definitions based on the names field in the data.yaml file:
    def generate_classes_code(data_yaml_path):
        # Function implementation
  2. Call the function to get class definitions:
    data_yaml_path = '/content/drive/MyDrive/CerviCure.v2i.yolov8/data.yaml'
    classes_code = generate_classes_code(data_yaml_path)
    print(classes_code)

Results Visualization

  1. Upload images and annotate them using the trained model:
    from google.colab import files
    uploaded = files.upload()
  2. Display the annotated images:
    for filename in uploaded.keys():
        annotated_image = predict_and_annotate(filename)
        if annotated_image is not None:
            plt.figure(figsize=(12, 8))
            plt.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB))
            plt.axis('off')
            plt.show()
        else:
            print(f"Failed to process image: {filename})

Acknowledgements

  • The YOLOv8 model is provided by the Ultralytics team.
  • The CerviCure project aims to assist in the detection and classification of cervical cancer-related abnormalities using deep learning techniques.

PR_curve

results