Repository and basic GUI for experimenting with visual prompting based on SAM and segGPT.
Project description
visprompt
Welcome to visprompt, a repository and basic GUI for experimenting with visual prompting based on SAM and segGPT.
If you would like to learn more about visual prompting, please check out the website accompanying this project.
Current version: 0.1.5
https://github.com/MSchnei/visprompt/assets/15090072/3243cd79-7373-48f3-a45d-b0caf8b7e6c0
Installation
There are two ways in which you can install this repository:
- standalone
- add as a dependency in your poetry project
Standalone
First, clone the project by running:
cd /home/folder/git/
git clone https://github.com/MSchnei/visprompt.git
Then set up a poetry environment by running:
cd /home/folder/git/visprompt/
poetry shell
poetry install
As a dependency
To add visprompt as a dependency to your poetry project, simply run:
poetry add visprompt
To add visprompt as a dependency using pip
, simply run:
pip install visprompt
How to use
There are two modes in which you can use visprompt:
- run and visualise segmentations via the GUI
- run SAM and segGPT segmentation via commmand line
Segmentation via GUI
To start the GUI from your terminal, run:
poetry run task gui
Alternatively, to start the GUI from a python shell, run:
from visprompt import run_gui
run_gui()
Once the GUI opens
- drop one or several image(s) for sam segmentation in the top-left window and draw a prompt per image
- drop one or several image(s) for segGPT segmentation in the bottom-left window panel
- click the
Submit
button
Running the application for the first time might take a while, since we need to download the models from the huggingface hub.
Segmentation via CLI
To run a SAM segmentation from your terminal, run the following:
poetry run task inference_sam --prompt-image /path/to/prompt_image.png -p 100 - p 150
To run a segGPT segmentation from your terminal, run
poetry run task inference_seggpt --input-image /path/to/input_image.png --prompt-images /path/to/prompt_image.png --prompt-targets /path/to/prompt_targets.png
Alternatively, run the below from a python shell:
from PIL import Image
from visprompt import SAMInference, SegGPTInference
# Set prompt_image and input_points for SAM segmentation
prompt_image = Image.open("/path/to/prompt_image.png").convert("RGB")
input_points = [[[100, 150]]]
# Run SAM segmentation
inference_instance = SAMInference()
mask = inference_instance.run_inference(
prompt_image=prompt_image,
input_points=input_points,
)
# Set input_image, prompt_images and prompt_targets for SegGPT segmentation
input_image = Image.open("/path/to/input_image.png").convert("RGB")
prompt_images = [Image.open("/path/to/prompt_image.png").convert("RGB")]
prompt_targets = [Image.open("/path/to/prompt_target.png").convert("RGB")]
# Run SegGPT segmentation
inference_instance = SegGPTInference(num_labels=1)
mask = inference_instance.run_inference(
input_image=input_image,
prompt_images=prompt_images,
prompt_targets=prompt_targets,
)
Contributing
Contributions are welcome! Before submitting a PR, please run:
make style
This will run black
, isort
and flake8
on the code.
Unit tests can be executed via
make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file visprompt-0.1.5.tar.gz
.
File metadata
- Download URL: visprompt-0.1.5.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc2c3e8f138ab894b8ffd65819b20e7b2e31f45191c64e1d67c081312d1a8949 |
|
MD5 | 50fcf17d6657fd29d2dd1fdcd760eba0 |
|
BLAKE2b-256 | 08ad00eea25734e5a28047f9c17c74d9fa8d78c9d542302814e7c5486f7ce331 |
File details
Details for the file visprompt-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: visprompt-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 727df982340d395c3b13ddb606237b7e18a0d04d5d128073d6437c2a49a64e68 |
|
MD5 | 3e829b4b19ea95206c7fe34dafea0e75 |
|
BLAKE2b-256 | ffbd8369591424beffff67f93e2eb307cc566cadf0a9d2c3d05203b9d7fe0a8e |