Skip to content

Include a CI job for cpp/custom-dataset #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/main_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ jobs:
sudo apt update && sudo apt upgrade
sudo apt install cmake g++ make
sudo apt-get -y install intel-mkl
- name: Install OpenCV
run: |
sudo apt -y install libtbb-dev
sudo apt install libopencv-dev

# Alternatively, you can install OpenCV from source
# - name: Install OpenCV from source
# run: |
# wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
# unzip opencv.zip
# mkdir -p build && cd build
# cmake ../opencv-4.x
# cmake --build .
# sudo make install

- name: Run Cpp Tests
run: |
chmod +x ./run_cpp_examples.sh
Expand Down
5 changes: 5 additions & 0 deletions cpp/custom-dataset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ set(CMAKE_CXX_STANDARD 17)
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)

message(STATUS "OpenCV include dirs: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")


include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} "custom-dataset.cpp")
target_link_libraries(${PROJECT_NAME} "${OpenCV_LIBS}")
target_link_libraries(${PROJECT_NAME} "${TORCH_LIBRARIES}")
Expand Down
32 changes: 30 additions & 2 deletions run_cpp_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function error() {
function get_libtorch() {
echo "Getting libtorch"
cd $HOME_DIR
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip
unzip libtorch-cxx11-abi-shared-with-deps-latest.zip

if [ $? -eq 0 ]; then
echo "Successfully downloaded and extracted libtorch"
Expand Down Expand Up @@ -55,18 +55,46 @@ function autograd() {
fi
}

function custom-dataset() {
start
# Download the dataset and unzip it
if [ ! -d "$BASE_DIR/cpp/$EXAMPLE/dataset" ]; then
wget https://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zip
unzip caltech-101.zip
cd caltech-101
tar -xzf 101_ObjectCategories.tar.gz
mv 101_ObjectCategories $BASE_DIR/cpp/$EXAMPLE/dataset
fi
# build the executable and run it
cd $BASE_DIR/cpp/$EXAMPLE
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
make
if [ $? -eq 0 ]; then
echo "Successfully built $EXAMPLE"
cd $BASE_DIR/cpp/$EXAMPLE
./build/$EXAMPLE # Run the executable
else
error "Failed to build $EXAMPLE"
exit 1
fi
}

function clean() {
cd $BASE_DIR
echo "Running clean to remove cruft"
# Remove the build directories
find . -type d -name 'build' -exec rm -rf {} +
# Remove the libtorch directory
rm -rf $HOME_DIR/libtorch
rm -f $HOME_DIR/libtorch-shared-with-deps-latest.zip
echo "Clean completed"
}

function run_all() {
autograd
custom-dataset
}

# by default, run all examples
Expand Down