Skip to content

Commit 42b3bda

Browse files
authored
Include a CI job for cpp/custom-dataset (#1219)
1 parent 814f047 commit 42b3bda

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

.github/workflows/main_cpp.yml

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ jobs:
2727
sudo apt update && sudo apt upgrade
2828
sudo apt install cmake g++ make
2929
sudo apt-get -y install intel-mkl
30+
- name: Install OpenCV
31+
run: |
32+
sudo apt -y install libtbb-dev
33+
sudo apt install libopencv-dev
34+
35+
# Alternatively, you can install OpenCV from source
36+
# - name: Install OpenCV from source
37+
# run: |
38+
# wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
39+
# unzip opencv.zip
40+
# mkdir -p build && cd build
41+
# cmake ../opencv-4.x
42+
# cmake --build .
43+
# sudo make install
44+
3045
- name: Run Cpp Tests
3146
run: |
3247
chmod +x ./run_cpp_examples.sh

cpp/custom-dataset/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ set(CMAKE_CXX_STANDARD 17)
66
find_package(Torch REQUIRED)
77
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)
88

9+
message(STATUS "OpenCV include dirs: ${OpenCV_INCLUDE_DIRS}")
10+
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
11+
12+
13+
include_directories(${OpenCV_INCLUDE_DIRS})
914
add_executable(${PROJECT_NAME} "custom-dataset.cpp")
1015
target_link_libraries(${PROJECT_NAME} "${OpenCV_LIBS}")
1116
target_link_libraries(${PROJECT_NAME} "${TORCH_LIBRARIES}")

run_cpp_examples.sh

+30-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function error() {
2222
function get_libtorch() {
2323
echo "Getting libtorch"
2424
cd $HOME_DIR
25-
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
26-
unzip libtorch-shared-with-deps-latest.zip
25+
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip
26+
unzip libtorch-cxx11-abi-shared-with-deps-latest.zip
2727

2828
if [ $? -eq 0 ]; then
2929
echo "Successfully downloaded and extracted libtorch"
@@ -55,18 +55,46 @@ function autograd() {
5555
fi
5656
}
5757

58+
function custom-dataset() {
59+
start
60+
# Download the dataset and unzip it
61+
if [ ! -d "$BASE_DIR/cpp/$EXAMPLE/dataset" ]; then
62+
wget https://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zip
63+
unzip caltech-101.zip
64+
cd caltech-101
65+
tar -xzf 101_ObjectCategories.tar.gz
66+
mv 101_ObjectCategories $BASE_DIR/cpp/$EXAMPLE/dataset
67+
fi
68+
# build the executable and run it
69+
cd $BASE_DIR/cpp/$EXAMPLE
70+
mkdir build
71+
cd build
72+
cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
73+
make
74+
if [ $? -eq 0 ]; then
75+
echo "Successfully built $EXAMPLE"
76+
cd $BASE_DIR/cpp/$EXAMPLE
77+
./build/$EXAMPLE # Run the executable
78+
else
79+
error "Failed to build $EXAMPLE"
80+
exit 1
81+
fi
82+
}
83+
5884
function clean() {
5985
cd $BASE_DIR
6086
echo "Running clean to remove cruft"
6187
# Remove the build directories
6288
find . -type d -name 'build' -exec rm -rf {} +
6389
# Remove the libtorch directory
6490
rm -rf $HOME_DIR/libtorch
91+
rm -f $HOME_DIR/libtorch-shared-with-deps-latest.zip
6592
echo "Clean completed"
6693
}
6794

6895
function run_all() {
6996
autograd
97+
custom-dataset
7098
}
7199

72100
# by default, run all examples

0 commit comments

Comments
 (0)