This project performs image classification on .tiff or .tif images stored in a specified directory. It utilizes NVIDIA CUDA and cuDNN libraries to handle GPU-accelerated image preprocessing and inference simulation. The classification output includes predicted class indices and associated probabilities for each image, saved in a results text file.
The program performs the following steps:
-
Initialization: Initializes CUDA and cuDNN libraries and displays GPU properties such as compute capability.
-
Image Loading and Preprocessing: Loads TIFF images using the libTIFF library and normalizes RGB channels to the [0, 1] range. Each image is converted into a cuDNN-compatible 4D tensor (NHWC format).
-
Mock Inference: A mock forward pass simulates a classification model by generating random class probabilities for a fixed number of output classes.
-
Result Logging: For each image, the predicted class and the full list of class probabilities are written to a specified output text file.
-
Cleanup: Releases all allocated GPU memory and destroys the cuDNN handle to ensure clean termination.
This project requires the following libraries and tools:
- CUDA Toolkit (version 10.2 or higher)
- cuDNN (compatible with your CUDA version)
- libTIFF (
libtiff-devon Linux) - C++17-compatible compiler (e.g.,
g++,clang++)
Run the executable by providing the input folder path containing TIFF images and the path to the output results file:
./classify_images <input_folder_path> <output_file.txt>Example:
./classify_images ./images ./results.txtThe output text file will contain entries for each processed image in the following format:
File: images/image1.tiff
Predicted class: 7
Class probabilities: 0.12 0.03 0.08 0.05 0.01 0.10 0.15 0.22 0.14 0.10
File: images/image2.tiff
Predicted class: 2
Class probabilities: 0.09 0.07 0.21 0.12 0.10 0.09 0.08 0.05 0.08 0.11