LabelImg

repository·master·Indexed 12 days ago

https://github.com/humansignal/labelimg

A graphical image annotation tool written in Python using Qt, used to create bounding box annotations for machine learning datasets in PASCAL VOC, YOLO, and CreateML formats. Includes a CLI tool, label_to_csv.py, for converting label files to CSV for Google Cloud AutoML.

Tokens
3.9K
Snippets
19
Records
27
Agent score
94%

What's inside LabelImg

  1. Build labelImg from source using Anaconda on Windows

    master

    If using Anaconda on Windows, use the Anaconda Prompt to install dependencies and run the build commands.

    conda install pyqt=5
    conda install -c anaconda lxml
    pyrcc5 -o libs/resources.py resources.qrc
    python labelImg.py
    # Or with arguments
    python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
  2. Annotate images in PASCAL VOC format

    master

    PASCAL VOC is the default format where annotations are saved as XML files.

    1. Launch LabelImg.
    2. Go to Menu/File -> Change default saved annotation folder to select your output directory.
    3. Click Open Dir to select your image folder.
    4. Click Create RectBox (or press w).
    5. Click and drag the left mouse button to draw the bounding box.
    6. Use the right mouse button to drag an existing box to move or copy it.

    Annotations are saved to the folder specified in step 2.

  3. Install LabelImg from source on Windows

    master

    On Windows, you need to install Python, PyQt5, and lxml manually. After installing, navigate to the labelImg directory and compile the resources.

    Standard Windows Installation:

    1. Run pyrcc5 -o libs/resources.py resources.qrc to compile resources.
    2. Run python labelImg.py.

    Windows with Anaconda:

    1. Open Anaconda Prompt and navigate to the labelImg directory.
    2. Install dependencies using conda install pyqt=5 and conda install -c anaconda lxml.
    3. Run pyrcc5 -o libs/resources.py resources.qrc.
    4. Run python labelImg.py.
    # Windows + Anaconda
    conda install pyqt=5
    conda install -c anaconda lxml
    pyrcc5 -o libs/resources.py resources.qrc
    python labelImg.py
  4. Annotate images in YOLO format

    master

    To use YOLO format, follow these steps:

    1. Define your classes in data/predefined_classes.txt.
    2. Launch LabelImg.
    3. In the toolbar, click the PascalVOC button to switch the mode to YOLO.
    4. Use Open/OpenDIR to load images.
    5. When you save an image, a .txt file with the same name is created in the image folder, along with a classes.txt file defining the class names.

    Important Notes for YOLO:

    • Do not change your class list in the middle of processing a directory; saving an image updates classes.txt, but previous annotations won't be updated to match.
    • The "default class" function is not used when saving in YOLO format.
    • The "difficult" flag is discarded in YOLO format.
  5. Build labelImg from source on Ubuntu

    master

    To build labelImg from source on Ubuntu using Python 3 and Qt5, follow these steps:

    sudo apt-get install pyqt5-dev-tools
    sudo pip3 install -r requirements/requirements-linux-python3.txt
    make qt5py3
    python3 labelImg.py
    # Or with arguments
    python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
  6. Run LabelImg using Docker

    master

    You can use a pre-built Docker image that contains all required dependencies.

    docker run -it \
    --user $(id -u) \
    -e DISPLAY=unix$DISPLAY \
    --workdir=$(pwd) \
    --volume="/home/$USER:/home/$USER" \
    --volume="/etc/group:/etc/group:ro" \
    --volume="/etc/passwd:/etc/passwd:ro" \
    --volume="/etc/shadow:/etc/shadow:ro" \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    tzutalin/py2qt4
    
    # After container starts:
    make qt4py2;./labelImg.py
    docker run -it \
    --user $(id -u) \
    -e DISPLAY=unix$DISPLAY \
    --workdir=$(pwd) \
    --volume="/home/$USER:/home/$USER" \
    --volume="/etc/group:/etc/group:ro" \
    --volume="/etc/passwd:/etc/passwd:ro" \
    --volume="/etc/shadow:/etc/shadow:ro" \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    tzutalin/py2qt4
  7. Install LabelImg using Docker

    master

    You can run LabelImg in a Docker container. This requires passing the display environment and mounting necessary system volumes to allow GUI access and user permissions.

    Run the following command to start the container and compile the resources for qt4py2:

    docker run -it \
    --user $(id -u) \
    -e DISPLAY=unix$DISPLAY \
    --workdir=$(pwd) \
    --volume="/home/$USER:/home/$USER" \
    --volume="/etc/group:/etc/group:ro" \
    --volume="/etc/passwd:/etc/passwd:ro" \
    --volume="/etc/shadow:/etc/shadow:ro" \
    --volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    tzutalin/py2qt4
    
    make qt4py2;./labelImg.py
  8. Install LabelImg from source on Ubuntu Linux

    master

    To build LabelImg from source on Ubuntu, you need Python 3 and Qt5. Follow these steps:

    1. Install pyqt5-dev-tools via apt-get.
    2. Install dependencies from the provided requirements file.
    3. Compile the resources using make qt5py3.
    4. Run the application using python3 labelImg.py.
    sudo apt-get install pyqt5-dev-tools
    sudo pip3 install -r requirements/requirements-linux-python3.txt
    make qt5py3
    python3 labelImg.py
    # Or with arguments
    python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
  9. Install LabelImg via PyPI

    master

    The simplest way to install LabelImg on modern Linux distributions (like Ubuntu or Fedora) is using pip3. You can launch the application directly or provide an image path and a pre-defined class file as arguments.

    pip3 install labelImg
    labelImg
    # Or with arguments:
    labelImg [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
    pip3 install labelImg
    labelImg
    labelImg [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
  10. Build LabelImg from source on Linux, macOS, or Windows

    master

    If you need to build from source, follow the platform-specific instructions below. It is strongly recommended to use Python 3 and PyQt5.

    Ubuntu Linux

    Requires pyqt5-dev-tools.

    sudo apt-get install pyqt5-dev-tools
    sudo pip3 install -r requirements/requirements-linux-python3.txt
    make qt5py3
    python3 labelImg.py
    python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]

    macOS

    Install qt and libxml2 via Homebrew, or use pip for dependencies.

    brew install qt
    brew install libxml2
    # OR via pip:
    pip3 install pyqt5 lxml
    
    make qt5py3
    python3 labelImg.py
    python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]

    Windows

    Requires Python, PyQt5, and lxml. You must compile resources using pyrcc5 before running.

    pyrcc5 -o libs/resources.py resources.qrc
    python labelImg.py
    python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]

    Windows + Anaconda

    conda install pyqt=5
    conda install -c anaconda lxml
    pyrcc5 -o libs/resources.py resources.qrc
    python labelImg.py
    python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
    sudo apt-get install pyqt5-dev-tools
    sudo pip3 install -r requirements/requirements-linux-python3.txt
    make qt5py3
    python3 labelImg.py