SOL4Py Sample: DetectionTransformer

SOL4Py Samples

1 DetectionTransformer

The DetectionTransformer class is based on the following web site

https://colab.research.google.com/github/facebookresearch/detr/blob/colab/notebooks/detr_demo.ipynb


See also:DETR: End-to-End Object Detection with Transformers

We have installed torch and torchvision in the following way:

pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
pip install requests
Please clone DETR.git in the following way.
git clone https://github.com/atlan-antillia/DETR.git

On PyTorch installation see :Resources | PyTorch


2 DetectionTransformer

Please run the following script to detect objects in an image file:

python DetectionTransformer.py image_file_or_dir output_image_dir [filters]

If image_file_or_dir were a single image file, the commnand above will generate a detected_image_file, detected_objects_csv_file, and objects_stats_csv_file in output_image_dir, respectively.
If image_file_or_dir were a diretory, the above process will be applied to each image file (png, jpg) in the directory.

The optional filters parameter is a list of classes to be selected from the detected objects in a post-processing stage after a detection process.
To specify the classes to be selected in the post-processing stage, we use the list format like this.


[class1, class2,.. classN]


3 Inferecne Examples

Example 1:
python DetectionTransformer.py images/img.png detected



detected_objects


objects stats_csv


Example 2:
python DetectionTransformer.py images/ShinJuku2.jpg detected


Example 3:

Let's apply filters to draw matched labels specified by the filters on the input image.

python DetectionTransformer.py images/img.png detected [person,car]

In this case, the objects of person or car will be selected from the detected objects found in images/img.png.








Example 3:
You can specify input_image_dir, output_image_dir in the following way.

python DetectionTransformer.py images detected [person]

By using the filter "[person]", you can count the number of persons in each image of the images directory.




Last modified: 20 Aug. 2020