SOL4Py Sample: DetectionTransformer

SOL4Py Samples

1 DetectionTransformer

The DetectionTransformer class is based on the following web site

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
pip install requests
Please clone DETR.git in the following way.
git clone

On PyTorch installation see :Resources | PyTorch

2 DetectionTransformer

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

python 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 images/img.png detected


objects stats_csv

Example 2:
python images/ShinJuku2.jpg detected

Example 3:

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

python 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 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