You can execute run_detector.sh with custom paths to video, polygon and output.
Polygon file should contain dictionary the same as original polygons.json
file.
./run_detector.sh video_path polygon_path output_path
You can find Work Analysis Report in English and Russian.
- Important information
- Brief task description
- Activate Poetry Environment
- Baseline
- Detector
- Fixing Problems with Project Initialization
Fixed cameras have been installed to monitor the area where the aircraft is preparing for departure. The task is to make sure that there are no vehicles on the stand before the aircraft arrives. If any vehicles are found inside the booth boundary, the ground operator should be notified.
This repository offers a baseline solution with Pixel Brightness variance Analysis, as well as a solution with Object Detection and the selection of treshold.
-
First, clone the project repository from its source. This can usually be done using a command like:
git clone https://github.com/kirill-push/object-detection-task.git
-
After cloning, navigate into the project directory:
cd object-detection-task
If you don't have Poetry installed, you'll need to install it. I recommend using Poetry version 1.6 or higher, but any version above 1.2 should suffice.
-
To install Poetry, run:
pipx install poetry
or
curl -sSL https://install.python-poetry.org | python3 -
Alternatively, you can visit Poetry's installation guide for other methods.
-
Verify the installation with:
poetry --version
With Poetry installed, you can now install the project's dependencies.
-
To install dependencies, run from project directory:
poetry install
This command reads the
pyproject.toml
file and installs all the dependencies listed there.
-
Check that everything is set up correctly by running a simple command, like:
poetry run python --version
This should display your Python version, which should be 3.8 or higher.
-
Activate Poetry Environment: Ensure you are in the Poetry-managed virtual environment by running:
poetry shell
-
Running the Script: The
evaluate_baseline.py
script in thebaseline
directory accepts the following arguments:-v
or--video_to_val
: One video name or list of video names to validate.-d
or--path_to_video_dir
: Path to the directory with all videos. Default is"resources/videos"
.-i
or--file_path_intervals
: Path to intervals annotation. Default is"resources/time_intervals.json"
.-p
or--file_path_polygons
: Path to polygons annotation. Default is"resources/polygons.json"
.-r
or--path_to_resources
: Path to the resources directory.
To run the script, use a command in the following format:
python baseline/evaluate_baseline.py [-v video_1.mp4 video_2.mp4 ...] [-d path/to/video/dir] [-i path/to/intervals.json] [-p path/to/polygons.json] [-r path/to/resources]
Example:
python baseline/evaluate_baseline.py -v video_1.mp4 video_2.mp4 -d resources/videos -i resources/time_intervals.json -p resources/polygons.json -r resources
This command will run the baseline evaluation on the specified videos using the resources from the given path.
-
Output: The script will evaluate the baseline on the videos and output the results in JSON format in the
baseline_metrics_test.json
file within the specified resources directory.
- The script will automatically exclude
video_16.mp4
andvideo_17.mp4
as they are duplicates ofvideo_4.mp4
andvideo_3.mp4
, respectively. - If no videos are specified for validation (
--video_to_val
), the script will process all videos except for the excluded and specified validation videos. - The resources directory should contain
time_intervals.json
,polygons.json
, and avideos
subdirectory with the video files.
-
Activate Poetry Environment: Activate the Poetry virtual environment by running:
poetry shell
-
Run the Script: The
run_detector.py
script accepts the following arguments:-v
or--video_path
: Path(s) to one or more videos to process. This argument is required.-p
or--polygon_path
: Path to the JSON file containing boundaries for the videos. This argument is required.-o
or--output_path
: Path to save the results in a JSON file. This argument is required.-t
or--thresholds_path
: Path to the JSON file with thresholds. Default is"resources/thresholds.json"
.
To run the script, use a command in the following format:
python object_detection_task/detector/run_detector.py -v path/to/video.mp4 -p path/to/polygon.json -o path/to/save/results.json [-t path/to/thresholds.json]
Example:
python object_detection_task/detector/run_detector.py -v resources/videos/video_1.mp4 resources/videos/video_2.mp4 -p resources/polygons.json -o resources/val_intervals.json
This command will process the specified videos, using the given polygon boundaries and thresholds, and save the predicted intervals in the specified output JSON file.
-
Output: The script will predict the labels for each video and save the intervals in the specified output file.
- Ensure that the paths to the videos, polygon JSON file, and output file are correctly specified.
- The script allows processing multiple videos in one run. You can list several video paths separated by spaces.
- The default thresholds path assumes that the
thresholds.json
file is in theresources
directory. You can specify a different path if necessary.
-
Activate Poetry Environment: Start the Poetry virtual environment:
poetry shell
-
Run the Script: The
calculate_metrics.py
script requires several arguments:-v
or--video_path
: Path to the video file for which you want to calculate metrics.-i
or--intervals_path
: Path to the JSON file containing intervals for the video.-p
or--polygons_path
: Path to the JSON file containing boundaries for the video.-o
or--output_path
: Path where the results will be saved in a JSON file.-t
or--thresholds_path
: Path to the JSON file containing thresholds (optional, defaults to"resources/thresholds.json"
).
To run the script, use a command in the following format:
python object_detection_task/metrics/calculate_metrics.py -v path/to/video.mp4 -i path/to/intervals.json -p path/to/polygons.json -o path/to/output.json [-t path/to/thresholds.json]
Example:
python object_detection_task/metrics/calculate_metrics.py -v resources/videos/video_1.mp4 -i resources/time_intervals.json -p resources/polygons.json -o resources/metrics_video_1.json
This command will calculate the metrics for the specified video using the provided intervals and polygons, and then save the results in the specified output file.
-
Output: The script will generate metrics for the video and save them in the specified output file.
- Ensure that the paths to the video, intervals JSON file, polygons JSON file, output file, and thresholds (if not using default) are correctly specified.
- The script is designed to work with one video at a time.
-
Activate Poetry Environment: Ensure you are in the Poetry-managed virtual environment by running:
poetry shell
-
Running the Script: The
detect_objects.py
script has two primary arguments:-v
or--video_to_val
: One video name or list of video names to validate.-r
or--path_to_resources
: Path to the resources directory.
To run the script, use a command in the following format:
python object_detection_task/detector/detect_objects.py [-v video_1.mp4 video_2.mp4 ...] [-r path/to/resources]
Example:
python object_detection_task/detector/detect_objects.py -v video_1.mp4 video_2.mp4 -r resources
This command will run the object detection on the specified videos using the resources from the given path.
-
Output: The script will process the videos and output detection results in JSON format in the specified resources directory and save it with name detections_dict.json.
- The script will ignore
video_16.mp4
andvideo_17.mp4
as they are duplicates ofvideo_4.mp4
andvideo_3.mp4
, respectively. - If no videos are specified for validation (
--video_to_val
), the script will process all videos except the ignored and specified validation videos. - The resources directory should contain
time_intervals.json
,polygons.json
, and avideos
subdirectory with the video files.
-
Activate Poetry Environment: Activate the Poetry virtual environment by running:
poetry shell
-
Running the Script: The
train.py
script accepts the following arguments:-v
or--video_to_val
: Specifies one or more video names used for validation. This is optional.-r
or--path_to_resources
: The path to the resources directory containing intervals and polygons JSON files. The default is"resources"
.
To run the script, use a command in the following format:
python object_detection_task/detector/train.py [-v video_1.mp4 video_2.mp4 ...] [-r path/to/resources]
Example:
python object_detection_task/detector/train.py -v video_1.mp4 video_2.mp4 -r resources
This will start the training process using the specified videos for validation and resources from the given path.
-
Output: The script performs the following operations:
- Finds the best thresholds based on the detections in
detections_dict.json
. - Saves the calculated thresholds in
thresholds.json
within the resources directory. - If validation videos are provided, it validates these videos using the calculated thresholds and saves the metrics in
detector_metrics_test.json
.
- Finds the best thresholds based on the detections in
- Make sure the
resources
directory containsdetections_dict.json
anddetections_dict_val.json
(if validation videos are specified). - The script saves the threshold values and validation metrics in JSON format in the specified resources directory.
If you encounter the following error while using the cv2
module in the OpenCV library:
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
This indicates that the necessary OpenGL libraries are missing from your environment. Follow these steps to resolve the issue:
-
Update Package List: Update your system's package list to ensure you can access the latest versions of packages.
sudo apt-get update
-
Install OpenGL Dependency: Install the
libgl1
package which provides thelibGL.so.1
library.sudo apt-get install libgl1
If you encounter the following error in Python:
ModuleNotFoundError: No module named 'pkg_resources'
This error typically occurs due to the absence of setuptools
or an outdated version in your environment. Follow these steps to resolve the issue:
-
Install
setuptools
: If you don't havesetuptools
installed, you can install it usingpip
. It's also a good idea to upgrade it to the latest version.pip install --upgrade setuptools