Skip to main content

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:

  1. standalone
  2. 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:

  1. run and visualise segmentations via the GUI
  2. 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

Release files for visprompt 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for visprompt 0.1.5
File Size Uploaded
visprompt-0.1.5.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for visprompt 0.1.5
File Interpreter ABI Platform
visprompt-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / visprompt-0.1.5.tar.gz

Download URL visprompt-0.1.5.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bc2c3e8f138ab894b8ffd65819b20e7b2e31f45191c64e1d67c081312d1a8949
BLAKE2b-256 checksum
How to use checksums
08ad00eea25734e5a28047f9c17c74d9fa8d78c9d542302814e7c5486f7ce331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure

Release files / visprompt-0.1.5-py3-none-any.whl

Download URL visprompt-0.1.5-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
727df982340d395c3b13ddb606237b7e18a0d04d5d128073d6437c2a49a64e68
BLAKE2b-256 checksum
How to use checksums
ffbd8369591424beffff67f93e2eb307cc566cadf0a9d2c3d05203b9d7fe0a8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page