Skip to content

4a Context classification

Hou Yujun edited this page Jul 25, 2024 · 3 revisions

Inference

The script inference.py classifies each image for the following eight contextual attributes:

  • panoramic status (True, False)
  • lighting condition (day, night, dawn/dusk)
  • weather (clear, cloudy, rainy, snowy, foggy)
  • platform (walking surface, driving surface, cycling surface, railway, fields, tunnel)
  • view direction (front/back, side)
  • quality (good, slightly poor, very poor)
  • presence of glare (yes, no)
  • presence of reflection (yes, no)

Set up environment with requirements-cv-linux.txt.

Input

The input CSV should:

  • have each row representing an image to process, and
  • contain minimally two columns, named uuid and path, to specify image UUID and the local image file path, respectively

Output

One CSV for each contextual attribute.

Each CSV contains two columns: uuids and the inferred contextual classes.

Models

The pretained models will be automatically downloaded when running inference.py (recommended method). You can also manually download the models here.

To reproduce sample_output

Modify inference.py:

  1. Modify out_folderPath to the directory you wish to store the output CSVs
  2. Modify batch_size to suit your GPU capacity

Run:

python3 inference.py

To run inference for other images

Modify inference.py:

  1. Modify out_folderPath to the directory you wish to store the output CSVs
  2. Modify in_csvPath to your input CSV file path
  3. Modify batch_size to suit your GPU capacity

Run:

python3 inference.py

Training

This section trains classification models based on the contextual labels in manual_labels/*.

Download labels from the above link. Unzip all images into img/ folder.

Adjust ROOT_PATH in config.yaml to point at the directory of manual_labels, in which train/, test/, and img/ folders are expected to exist.

Please also make sure you have a wandb account and have created a team which is set as the default location for storing runs. After that, run wandb login in your terminal.

To run the CV-calculations all scenarios can be run with

chmod +x cv.multiruns.sh
bash cv_multiruns.sh

To run the training configurations

chmod +x run_combinations.sh
bash run_combinations

All trained models, their performance metrics and confusion matrix plots are stored here.

To run other configurations

Adjust parameters in config.yaml and run python train_and_test.py