/Label-Detect

Label-Detect is a graphical image annotation tool and using this tool a user can also train and test large satellite images.

Primary LanguagePythonMIT LicenseMIT

Label-Detect

Label-Detection is a graphical image annotation tool and using this tool a user can also train and test large satellite images. User can create small patches from a large image, annotate it, create training and testing data, select model, train-test the model. The annotations (labeling) part of this application is based on this repository.

It is written in Python and uses Qt for its graphical interface.

Annotations are saved as XML files in PASCAL VOC format, the format used by ImageNet.

Users can use many deep learning models such as Faster RCNN Resnet or SSD Mobilenet.

We can see an example of image labeling and detection in the following images. Sample Labeling, Training and Testing procedures can be found in the videos that are posted below the images.

Demo Image

Demo Image

Watch a demo video [Labeling] [Created by tzutalin]

Watch a demo video [Training Part-1]

Watch a demo video [Training Part-2]

Watch a demo video [Testing]

Installation

Build from source

Linux/Ubuntu requires at least Python 3.6 and has been tested with PyQt 5.8. Download or clone the Label-Detect repository and then run the following commands (Ubuntu/Windows) within the Label-Detect directory.

Ubuntu Linux

Install Tensorflow with GPU support

Install Tensorflow with GPU support [Tensorflow Documentation]

sudo apt-get install pyqt5-dev-tools
sudo pip3 install -r requirements/requirements-linux-python3.txt
make qt5py3
python3 labelImg.py

Windows + Anaconda ^^^^^^^

Download and install Anaconda (Python 3.6+)

Install Tensorflow with GPU support

Hardware Requirements

Open the Anaconda Prompt and go to the Labe-Detect directory

conda install pip
pip install -r requirements/requirements-linux-python3.txt
pyrcc5 -o resources.py resources.qrc
python labelImg.py

Tensorflow Object Detection API

  1. Tensoflow object detection API is used only for training purpose. By using this API we can use different types of models to train. I am also integrating models that are not in the API.
  2. Ubuntu: Go to the '/home/your-username/' directory and create a folder named 'tensorflow' and go into the folder. Now download or clone this repository and follow this installation process.
  3. Windows: Download Git Bash, go to the 'C:/Users/your-username/' directory of your computer, create a folder named 'tensorflow' and go into the folder. Now follow this tutorial or this tutorial

Usage

Annotation

Steps (PascalVOC) ~~~~~

  1. Build and launch using the instructions above.
  2. Click 'Change default saved annotation folder' in Menu/File
  3. Click 'Open Dir'
  4. Click 'Create RectBox'
  5. Click and release left mouse to select a region to annotate the rect box
  6. You can use right mouse to drag the rect box to copy or move it

The annotation will be saved to the folder you specify.

You can refer to the below hotkeys to speed up your workflow.

Training

Steps

  1. Select 'File -> Open Image and Slice' [Ctrl+i]
  2. Select the desired Satellite Image and then can enter the slice/patch height and width. The default value is 512 pixels.
  3. Then select 'Start Slicing'
  4. After Slicing the big image, you can see a new directory on the image's directory and within it, you can see image slices/patches.
  5. Annotate the images and save the .xml files according to the 'Annotation' section discussed above.
  6. Select 'File -> Select Directory to Create TFrecords' [Ctrl+t] and select the directory that contains all the .xml files.
  7. Then TFRecords files for training and testing will be created under TFrecords folder within the directory selected in step 6.
  8. Select 'Start Training' [Ctrl+Shift+t]
  9. Select the TFRecord file for training which is 'train.record'
  10. Select 'detection.pbtxt' and a '.config' file from 'Label-Detect/Training_config' directory. If you want to use Faster R-CNN ResNet-101 then select the corresponding file otherwise you can select the '.config' file for SSD MobileNet.
  11. Download the Faster R-CNN Resnet-101 model, extract it and select the 'model.ckpt.index' file for the model file. You can also use SSD MobileNet
  12. If you want to use other models you can download from here and the corresponding .config files from 'tensorflow/models/research/object_detection/samples/configs' or here
  13. Then you can start training and after the completion of the training you will get 'frozen_inference_graph.pb' file and this file will be used for testing images.
  14. Here, the training is for three labels which are in 'detection.pbtxt' file. If you want to create your own labels then just edit the detection.pbtxt file. Give an item id starting from value 1 and give it a name. The format must be same as the given 'detectin.pbtxt' file.
  15. In the config files that are provided in the repository in 'Label-Detect/Training_config', you can find "num_steps: 20000". This is the number of training steps. You can change the steps as you wish.

Testing

Steps

  1. Select 'File -> Load Test Image to Get the Results'
  2. For testing large images, the images must be sliced into small overlapping patches for detection. Therefore, enter the height and width of the slices. The default size is 512 for height and width.
  3. Then select the 'frozen_inference_graph.pb' file that is created on the training phase.
  4. Then after some processing time, (slicing, detection of objects, convert local coordinates of the bounding box of small images to the global coordinate of the big image and use non-max suppression to the overlapped detection) the final labeled image with bounding boxes will be uploaded.

Hotkeys

+--------------------+--------------------------------------------+ | Ctrl + u | Load all of the images from a directory | +--------------------+--------------------------------------------+ | Ctrl + r | Change the default annotation target dir | +--------------------+--------------------------------------------+ | Ctrl + s | Save | +--------------------+--------------------------------------------+ | Ctrl + d | Copy the current label and rect box | +--------------------+--------------------------------------------+ | Ctrl + i | Open Image and Slice | +--------------------+--------------------------------------------+ | Ctrl + t | Select Directory to Create TFrecords | +--------------------+--------------------------------------------+ | Ctrl + Shift + t | Start Training | +--------------------+--------------------------------------------+ | Ctrl + Shift + w | Load Test Image to Get the Results | +--------------------+--------------------------------------------+ +--------------------+--------------------------------------------+ | Space | Flag the current image as verified | +--------------------+--------------------------------------------+ | w | Create a rect box | +--------------------+--------------------------------------------+ | d | Next image | +--------------------+--------------------------------------------+ | a | Previous image | +--------------------+--------------------------------------------+ | del | Delete the selected rect box | +--------------------+--------------------------------------------+ | Ctrl++ | Zoom in | +--------------------+--------------------------------------------+ | Ctrl-- | Zoom out | +--------------------+--------------------------------------------+ | ↑→↓← | Keyboard arrows to move selected rect box | +--------------------+--------------------------------------------+

Verify Image:

When pressing space, the user can flag the image as verified, a green background will appear. This is used when creating a dataset automatically, the user can then through all the pictures and flag them instead of annotate them.

How to contribute

Send a pull request

License

Free software: MIT license

Citation

Tzutalin. LabelImg. Git code (2015). https://github.com/tzutalin/labelImg

App Icon based on Icon by Nick Roach (GPL) <https://www.elegantthemes.com/> <https://www.iconfinder.com/icons/1054978/shop_tag_icon> __