Skip to content

This is the YOLACT Instance Segmentation model, adapted to run on Apple Silicon MPS machines.

Notifications You must be signed in to change notification settings

sainatarajan/yolact-mps

Repository files navigation

██╗   ██╗ ██████╗ ██╗       █████╗  ██████╗████████╗   ███╗   ███╗██████╗  ██████╗ 
╚██╗ ██╔╝██╔═══██╗██║      ██╔══██╗██╔════╝╚══██╔══╝   ████╗ ████║██╔══██╗██╔════╝ 
 ╚████╔╝ ██║   ██║██║      ███████║██║        ██║      ██╔████╔██║██████╔╝╚██████╗  
  ╚██╔╝  ██║   ██║██║      ██╔══██║██║        ██║      ██║╚██ ╝██║██╔═══╝     ██║ 
   ██║   ╚██████╔╝███████╗██║  ██║╚██████╗    ██║      ██║ ╚═╝ ██║██║     ██████╔╝ 
   ╚═╝    ╚═════╝ ╚══════╝╚═╝  ╚═╝ ╚═════╝    ╚═╝      ╚═╝     ╚═╝╚═╝     ╚═════╝  

YOLACT for Apple Silicon MPS

This repository contains an implementation of YOLACT (You Only Look At CoefficienTs) that has been modified to support training and evaluation on Apple Silicon devices with Metal Performance Shaders (MPS).

Introduction

YOLACT is a real-time instance segmentation algorithm that is known for its speed and accuracy. This implementation has been adapted to leverage the power of Apple's M-series chips, allowing for efficient training and evaluation on macOS devices.

The key features of this repository are:

  • Apple Silicon MPS Support: The codebase has been updated to use the mps device in PyTorch, enabling hardware acceleration on Apple Silicon.
  • Training and Evaluation: The repository provides scripts for both training a new YOLACT model and evaluating a trained model on a dataset.
  • Compatibility: The modifications have been made to be compatible with the original YOLACT implementation, allowing for the use of pre-trained weights and configurations.

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/yolact-mps.git
    cd yolact-mps
  2. Create a Conda environment:

    The environment.yml file contains all the necessary dependencies for this project. You can create a Conda environment with these dependencies using the following command:

    conda env create -f environment.yml
  3. Activate the Conda environment:

    conda activate yolact

Usage

Training

To train a new YOLACT model, you can use the train.py script. Here is an example of how to train a model:

python -W ignore train.py --config=yolact_base_config

You can customize the training process by specifying various command-line arguments, such as the batch size, learning rate, and number of workers. For a full list of available options, you can use the following command:

python train.py --help

Evaluation

To evaluate a trained model, you can use the eval.py script. Here is an example of how to evaluate a model:

python -W ignore eval.py --trained_model=/path/to/your/weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=100 --images=/path/to/your/test_images:/path/to/your/test_masks

You can also use this script to perform inference on a single image, a folder of images, or a video. Note that video evaluation has not been tested. For more information on the available options, you can use the following command:

python eval.py --help

Example Results on Apple Silicon

Here are some example segmentation masks generated by YOLACT running on an Apple Silicon MPS device:

Image 1: Example Mask 1

Image 2: Example Mask 2

Apple Silicon MPS Support

The main modification in this repository is the addition of support for Apple Silicon MPS. This is achieved by detecting the availability of the mps device in PyTorch and using it for all tensor operations.

The following files have been modified to support MPS:

  • train.py: The device is set to mps if it is available, and the model and data are moved to the mps device.
  • eval.py: The device is set to mps if it is available, and the model and data are moved to the mps device.
  • yolact.py: The device is set to mps if it is available, and the tensors are created on the mps device.

By using the mps device, the model can take advantage of the hardware acceleration provided by Apple's M-series chips, resulting in a significant speedup in both training and evaluation.

Acknowledgements

This repository is based on the original YOLACT implementation by Daniel Bolya. The original repository can be found here:

About

This is the YOLACT Instance Segmentation model, adapted to run on Apple Silicon MPS machines.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published