CV_From_Scratch is a project where I implemented a PyTorch-like library in C++ for Computer Vision tasks. This library includes layers, a CNN architecture, a Learner class, data loaders, and basic image transforms, all from scratch. The project uses OpenCV for image processing and LibTorch (temporarily) for tensor operations. My colleague later replaced LibTorch with a custom tensor implementation, this final version can be seen in the final branch.
- Implemented CNN architecture and layers from scratch in C++.
- DataLoader and Datasets with basic transformations using OpenCV.
- A simple demonstration app for training and testing a CNN model.
- Unit tests for verification (optional).
While this project doesn't support CUDA and isn't designed for high-performance usage, it includes a basic terminal-based demonstration app. This app allows you to:
- Train a CNN.
- Run inference on the trained model.
To use the app, compile the project and run the CV_From_Scratch executable.
There are also unit tests located in the tests/ directory that can be executed by running tests/tests after compilation.
To set up the project locally, follow these steps:
-
Clone the repository:
git clone <repository-url> cd CV_From_Scratch
-
Download the MNIST dataset: Run the following Python script to download the MNIST dataset and place the images in the
data/directory:python get_data.py -
Download required libraries: You need to download the following libraries and place them in the
lib/directory:
-
The details regarding setting up all the 3 above mentioned libraries is in the
README.mdfile insidelib/
Note: If you do not want to use tests, you can skip Catch2 by disabling tests in the CMakeLists.txt file:
# Add tests directory if tests are enabled
option(ENABLE_TESTS "Enable unit tests" ON) # Set ON -> OFF to disable tests
if (ENABLE_TESTS)
add_subdirectory(tests)
endif()- Build and compile the project: Follow the standard CMake build process:
mkdir build
cd build
cmake ..
make- Run the demonstration app: After compilation, run the executable:
./CV_From_Scratch
Here’s a quick overview of the project structure:
CV_From_Scratch/
├── build/ # A place for compiling the project
├── data/ # MNIST dataset
├── include/ # Header files for CNN, layers, data loading, etc.
├── lib/ # External libraries (LibTorch, OpenCV, Catch2)
├── src/ # Source code for CNN, layers, data loading, etc.
├── tests/ # Unit tests (optional)
├── CMakeLists.txt # CMake configuration
├── get_data.py # Download MNIST dataset
└── README.md # Project descriptionThis project is licensed under the MIT License. See the LICENSE file for more information.