[go: up one dir, main page]

Skip to content

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).

License

Notifications You must be signed in to change notification settings

3335083534/labelme-with-segment-anything

 
 

Repository files navigation

About SAM:

1. Installation

You can use pip install . as described below to install all the dependencies. Except the original dependencies, additional dependencies are

torch>=1.7
torchvision>=0.8
appdirs
opencv-python-headless
segment-anything @ git+https://github.com/facebookresearch/segment-anything.git

Note that latest opencv-python could cause conflicts with pyqt5, need to install older versions of it or use opencv-python-headless

2. Configuration

The SAM related configuration is available in config file. You can find a .labelmerc file at user home directory after you open labelme for the first time (You need to delete old ones if you used official labelme previously). Under sam section, you can adjust the settings accordingly.

sam:
  weights: vit_h # vit_h, vit_l or vit_b
  maxside: 1280 # will downsize the image during inference to the maxsize.
  approxpoly_epsilon: 1. # adjust the poylgon simplification algorithm. The larger the lesser vertices.
  device: "cuda" # "cuda" or "cpu"

3. Use

After loaded one image, you can click Edit -> Create Polygons with Segment Anything. At the first time you use this option, it will freeze for a while and download the model weights(vit_h's weights file is around 2gb, so it could take some time). After it downloaded, you can start annotating. Only points prompt is supported, you can left click to mark positive prompt and right click for negative prompt. When done, hit enter and it will generate polygons from the result.



labelme

Image Polygonal Annotation with Python


Description

Labelme is a graphical image annotation tool inspired by http://labelme.csail.mit.edu. It is written in Python and uses Qt for its graphical interface.

VOC dataset example of instance segmentation.

Other examples (semantic segmentation, bbox detection, and classification).

Various primitives (polygon, rectangle, circle, line, and point).

Experimenting with segment anything, can create polygons by a few clicks.

Features

Requirements

Installation

There are options:

Anaconda

You need install Anaconda, then run below:

# python3
conda create --name=labelme python=3
source activate labelme
# conda install -c conda-forge pyside2
# conda install pyqt
# pip install pyqt5  # pyqt5 can be installed via pip on python3
pip install labelme
# or you can install everything by conda command
# conda install labelme -c conda-forge

Ubuntu

sudo apt-get install labelme

# or
sudo pip3 install labelme

# or install standalone executable from:
# https://github.com/wkentaro/labelme/releases

macOS

brew install pyqt  # maybe pyqt5
pip install labelme

# or
brew install wkentaro/labelme/labelme  # command line interface
# brew install --cask wkentaro/labelme/labelme  # app

# or install standalone executable/app from:
# https://github.com/wkentaro/labelme/releases

Windows

Install Anaconda, then in an Anaconda Prompt run:

conda create --name=labelme python=3
conda activate labelme
pip install labelme

# or install standalone executable/app from:
# https://github.com/wkentaro/labelme/releases

Usage

Run labelme --help for detail. The annotations are saved as a JSON file.

labelme  # just open gui

# tutorial (single image example)
cd examples/tutorial
labelme apc2016_obj3.jpg  # specify image file
labelme apc2016_obj3.jpg -O apc2016_obj3.json  # close window after the save
labelme apc2016_obj3.jpg --nodata  # not include image data but relative image path in JSON file
labelme apc2016_obj3.jpg \
  --labels highland_6539_self_stick_notes,mead_index_cards,kong_air_dog_squeakair_tennis_ball  # specify label list

# semantic segmentation example
cd examples/semantic_segmentation
labelme data_annotated/  # Open directory to annotate all images in it
labelme data_annotated/ --labels labels.txt  # specify label list with a file

For more advanced usage, please refer to the examples:

Command Line Arguments

  • --output specifies the location that annotations will be written to. If the location ends with .json, a single annotation will be written to this file. Only one image can be annotated if a location is specified with .json. If the location does not end with .json, the program will assume it is a directory. Annotations will be stored in this directory with a name that corresponds to the image that the annotation was made on.
  • The first time you run labelme, it will create a config file in ~/.labelmerc. You can edit this file and the changes will be applied the next time that you launch labelme. If you would prefer to use a config file from another location, you can specify this file with the --config flag.
  • Without the --nosortlabels flag, the program will list labels in alphabetical order. When the program is run with this flag, it will display labels in the order that they are provided.
  • Flags are assigned to an entire image. Example
  • Labels are assigned to a single polygon. Example

FAQ

Developing

git clone https://github.com/wkentaro/labelme.git
cd labelme

# Install anaconda3 and labelme
curl -L https://github.com/wkentaro/dotfiles/raw/main/local/bin/install_anaconda3.sh | bash -s .
source .anaconda3/bin/activate
pip install -e .

How to build standalone executable

Below shows how to build the standalone executable on macOS, Linux and Windows.

# Setup conda
conda create --name labelme python=3.9
conda activate labelme

# Build the standalone executable
pip install .
pip install 'matplotlib<3.3'
pip install pyinstaller
pyinstaller labelme.spec
dist/labelme --version

How to contribute

Make sure below test passes on your environment. See .github/workflows/ci.yml for more detail.

pip install -r requirements-dev.txt

flake8 .
black --line-length 79 --check labelme/
MPLBACKEND='agg' pytest -vsx tests/

Acknowledgement

This repo is the fork of mpitid/pylabelme.

About

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%