labelme

用 Python 进行图像多边形标注(多边形、矩形、圆、线、点和图像级标志标注)。「Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).」

Github stars Tracking Chart

labelme

用 Python 进行图像多边形标注。

描述

Labelme 是一个图形化的图像注释工具,灵感来自于 http://labelme.csail.mit.edu。

它是用 Python 编写的,使用 Qt 作为其图形界面。

特点

  • 为多边形、矩形、圆、线和点提供图像注释。(教程)
  • 用于分类和清洁的图像标志注释。(#166)
  • 视频注解。(视频标注)
  • GUI定制(预定义标签/标志、自动保存、标签验证等)。(#144)
  • 为语义/实例分割导出VOC格式的数据集。(语义分割实例分割)
  • 导出COCO格式的数据集,用于实例分割。(实例分割)

要求

安装

有多种选择:

  • 平台无关的安装。Anaconda, Docker
  • 特定平台安装。Ubuntu, macOS, Windows
  • 从发布部分预先构建二进制文件

Anaconda

你需要安装 Anaconda,然后运行以下程序。

# python2
conda create --name=labelme python=2.7
source activate labelme
# conda install -c conda-forge pyside2
conda install pyqt
pip install labelme
# if you'd like to use the latest version. run below:
# pip install git+https://github.com/wkentaro/labelme.git
# python3
conda create --name=labelme python=3.6
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

Docker

你需要安装 docker,然后运行以下程序。

# on macOS
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" &
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=docker.for.mac.host.internal:0 -v $(pwd):/root/workdir wkentaro/labelme
# on Linux
xhost +
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=:0 -v $(pwd):/root/workdir wkentaro/labelme

Ubuntu
# Ubuntu 14.04 / Ubuntu 16.04
# Python2
# sudo apt-get install python-qt4  # PyQt4
sudo apt-get install python-pyqt5  # PyQt5
sudo pip install labelme
# Python3
sudo apt-get install python3-pyqt5  # PyQt5
sudo pip3 install labelme
# or install standalone executable from:
# https://github.com/wkentaro/labelme/releases

Ubuntu 19.10+ / Debian (sid)

sudo apt-get install labelme

macOS

# macOS Sierra
brew install pyqt  # maybe pyqt5
pip install labelme  # both python2/3 should work
# or install standalone executable/app from:
# https://github.com/wkentaro/labelme/releases

Windows

安装 Anaconda,然后在 Anaconda Prompt 中运行。

# python3
conda create --name=labelme python=3.6
conda activate labelme
pip install labelme

使用方法

运行 labelme --help 了解详情。

标注被保存为一个 JSON 文件。

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

对于更高级的用法,请参考实例。

命令行参数

  • --output 指定注释将被写入的位置。如果位置以 .json 结尾,一个注释将被写入这个文件。如果指定了以 .json 结尾的位置,则只能对一张图片进行注释。如果位置不是以 .json 结尾,程序会认为它是一个目录。注释将被保存在这个目录中,名称与注释的图像相对应。
  • 你第一次运行 labelme 时,它会在 ~/.labelmerc 创建一个配置文件。你可以编辑这个文件,修改的内容会在你下次启动 labelme时应用。如果你想使用另一个地方的配置文件,你可以用 --config 标志指定这个文件。
  • 如果没有 --nosortlabels 标志,程序将按字母顺序列出标签。当程序以这个标志运行时,它将按照提供的顺序显示标签。
  • 标志是分配给整个图像的。例子
  • 标签被分配给一个单一的多边形。例子

常见问题

  • 如何将 JSON 文件转换为 numpy 数组?见 实例/教程https://github.com/wkentaro/labelme/blob/master/examples/tutorial#convert-to-dataset。
  • 如何加载标签PNG文件?examples/tutorial
  • 如何获得语义分割的注释?见 。 examples/semantic_segmentation
  • 如何获取实例分割的注释?见examples/instance_segmentation。

测试

pip install hacking pytest pytest-qt
flake8 .
pytest -v tests

开发

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

如何建立独立的可执行文件

下面展示了如何在 macOS、Linux 和 Windows 上构建独立的可执行文件。

# Setup conda
conda create --name labelme python==3.6.0
conda activate labelme
# Build the standalone executable
pip install .
pip install pyinstaller
pyinstaller labelme.spec
dist/labelme --version

如何贡献

确保以下测试在你的环境中通过。

更多细节见 .github/workflows/ci.yml。

pip install black hacking pytest pytest-qt
flake8 .
black --line-length 79 --check labelme/
MPLBACKEND='agg' pytest tests/ -m 'not gpu'

鸣谢

这个 repo 是 mpitid/pylabelme 的分叉,它的开发已经停止。

引用本项目

如果你在你的研究中使用这个项目,或者希望参考README中公布的基线结果,请使用以下BibTeX条目。

@misc{labelme2016,
  author =       {Kentaro Wada},
  title =        {{labelme: Image Polygonal Annotation with Python}},
  howpublished = {\url{https://github.com/wkentaro/labelme}},
  year =         {2016}
}


(The first version translated by vz on 2021.09.09)

Overview

Name With Ownerlabelmeai/labelme
Primary LanguagePython
Program languagePython (Language Count: 2)
PlatformDocker, Linux, Mac, Windows
License:Other
Release Count200
Last Release Namev5.4.1 (Posted on )
First Release Namev1.0.0 (Posted on )
Created At2016-05-09 12:30:26
Pushed At2024-05-02 23:18:50
Last Commit At
Stargazers Count12.4k
Watchers Count149
Fork Count3.3k
Commits Count1.4k
Has Issues Enabled
Issues Count726
Issue Open Count76
Pull Requests Count329
Pull Requests Open Count33
Pull Requests Close Count115
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

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).

Features

Requirements

Installation

There are options:

Anaconda

You need install Anaconda, then run below:

# python2
conda create --name=labelme python=2.7
source activate labelme
# conda install -c conda-forge pyside2
conda install pyqt
pip install labelme
# if you'd like to use the latest version. run below:
# pip install git+https://github.com/wkentaro/labelme.git

# python3
conda create --name=labelme python=3.6
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

Docker

You need install docker, then run below:

# on macOS
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" &
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=docker.for.mac.host.internal:0 -v $(pwd):/root/workdir wkentaro/labelme

# on Linux
xhost +
docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=:0 -v $(pwd):/root/workdir wkentaro/labelme

Ubuntu

# Ubuntu 14.04 / Ubuntu 16.04
# Python2
# sudo apt-get install python-qt4  # PyQt4
sudo apt-get install python-pyqt5  # PyQt5
sudo pip install labelme
# Python3
sudo apt-get install python3-pyqt5  # PyQt5
sudo pip3 install labelme

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

Ubuntu 19.10+ / Debian (sid)

sudo apt-get install labelme

macOS

# macOS Sierra
brew install pyqt  # maybe pyqt5
pip install labelme  # both python2/3 should work

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

Windows

Install Anaconda, then in an Anaconda Prompt run:

# python3
conda create --name=labelme python=3.6
conda activate labelme
pip install labelme

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

Testing

pip install hacking pytest pytest-qt
flake8 .
pytest -v tests

Developing

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

# Install anaconda3 and labelme
curl -L https://github.com/wkentaro/dotfiles/raw/master/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.6.0
conda activate labelme

# Build the standalone executable
pip install .
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 black hacking pytest pytest-qt

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

Acknowledgement

This repo is the fork of mpitid/pylabelme,
whose development has already stopped.

Cite This Project

If you use this project in your research or wish to refer to the baseline results published in the README, please use the following BibTeX entry.

@misc{labelme2016,
  author =       {Kentaro Wada},
  title =        {{labelme: Image Polygonal Annotation with Python}},
  howpublished = {\url{https://github.com/wkentaro/labelme}},
  year =         {2016}
}
To the top