Coder Social home page Coder Social logo

autodistill / autodistill-seggpt Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 4.61 MB

SegGPT module for use with Autodistill

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

Makefile 0.01% Python 0.99% Jupyter Notebook 99.00%
autodistill computer-vision seggpt

autodistill-seggpt's Introduction

Autodistill SegGPT Module

This repository contains the code supporting the SegGPT base model for use with Autodistill.

SegGPT is a transformer-based, few-shot semantic segmentation model developed by BAAI Vision.

This model performs well on task-specific segmentation tasks when given a few labeled images from which to learn features about the objects you want to identify.

Read the full Autodistill documentation.

Read the SegGPT Autodistill documentation.

Installation

To use SegGPT with Autodistill, you need to install the following dependency:

pip3 install autodistill-seggpt

About SegGPT

SegGPT performs "in-context" segmentation. This means it requires a handful of pre-labelled "context" images.

You will need some labeled images to use SegGPT. Don't have any labeled images? Check out Roboflow Annotate, a feature-rich annotation tool from which you can export data for use with Autodistill.

Quickstart

from autodistill_seggpt import SegGPT, FewShotOntology

base_model = SegGPT(
    ontology=FewShotOntology(supervision_dataset)
)

base_model.label("./unlabelled-photos", extension=".jpg")

How to load data from Roboflow

Labelling and importing images is easy!

You can use Roboflow Annotate to label a few images (1-3 should work fine). For your Project Type, make sure to pick Instance Segmentation, as you will be labelling with polygons.

Once you have labelled your images, you can press Generate > Generate New Version. You can use all the default options--no Augmentations are necessary.

Once your dataset version is generated, you can press Export > Continue.

Then you will get some download code to copy. It should look something like this:

!pip install roboflow

from roboflow import Roboflow
rf = Roboflow(api_key="ABCDEFG")
project = rf.workspace("lorem-ipsum").project("dolor-sit-amet")
dataset = project.version(1).download("yolov8")

Note: if you are not using a notebook environment, you should remove !pip install roboflow from your code, and run pip install roboflow in your terminal instead.

To import your dataset into Autodistill, run the following:

import supervision as sv

supervision_dataset = sv.DetectionDataset.from_yolo(
    images_directory_path=f"{dataset.location}/train/images",
    annotations_directory_path=f"{dataset.location}/train/labels",
    data_yaml_path=f"{dataset.location}/data.yaml",
    force_masks=True
)

License

The code in this repository is licensed under an MIT license.

See the SegGPT repository for more information on the SegGPT license.

๐Ÿ† Contributing

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

autodistill-seggpt's People

Contributors

andrew-healey avatar capjamesg avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jeremy-costello

autodistill-seggpt's Issues

CUDA out of memory

I'm using this library in a server that has 4 GPU's with 16 GB each GPU. When I set the number to pre-annotated images to more than 8 the one GPU get's without memory making the process to crash.

Is this possible to run the process across multiple GPU's? If not what it's the optimal size from the annotated images that need to be used? Cause I've been resizing my images from 960 down to 448 and even with the low resolution I get the memory error. In which type of GPU is recommended to use this tool?

Memory Leak? CUDA memory finishes quickly when using more than 50 pre-annotated data

Even when using 150 pre annotated images to label 10 additional images, CUDA memory finishes on a 3090 GPU.

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 31.36 GiB (GPU 0; 24.00 GiB total capacity; 49.21 GiB already allocated; 0 bytes free; 49.35 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

It stops working after about 50 pre annotated images due to this error.

No module named 'seggpt_engine'

Traceback (most recent call last):
File "/home/smiv/Temp2018/ZWP/project2/01-yolo/autodistill/s.py", line 1, in
from autodistill_seggpt import SegGPT, FewShotOntology
File "/home/smiv/anaconda3/envs/zwp_autodistill/lib/python3.9/site-packages/autodistill_seggpt/init.py", line 6, in
from .seggpt import SegGPT
File "/home/smiv/anaconda3/envs/zwp_autodistill/lib/python3.9/site-packages/autodistill_seggpt/seggpt.py", line 63, in
from seggpt_engine import run_one_image
ModuleNotFoundError: No module named 'seggpt_engine'

Ability to use different GPU in cluster in seggpt.py

Currently the code is hard coded to use device:0 with device = ("cuda" if torch.cuda.is_available() else "cpu"). It would be a great enhancement to also be able to set an environment variable with the GPU ID that we would want to use when there are multiple GPUs available.

I attempted to set CUDA_VISIBLE_DEVICES=1 to see if it would use the next GPU, but it did not.

So maybe something like in a terminal the user could set:
$export CUDA_DEVICE=1

And in seggpt.py:
if os.getenv("CUDA_DEVICE"):
device = torch.device(f"cuda:{os.getenv('CUDA_DEVICE')}" if torch.cuda.is_available() else "cpu")
else:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

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.