Skip to content

Commit adaa1da

Browse files
Evaluate Accuracy (#177)
I removed the download and build of tensorflow from github actions from build-linux because we don't use it. Should I remove this step from the other checks? --------- Co-authored-by: GitHub Actions <[email protected]>
1 parent ebb2345 commit adaa1da

File tree

2 files changed

+129
-56
lines changed

2 files changed

+129
-56
lines changed

.github/workflows/ci.yml

Lines changed: 126 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,11 @@ jobs:
1818
strategy:
1919
matrix:
2020
build_type: [DEBUG, RELEASE]
21-
use_tensorflow: [ON, OFF]
2221
runs-on: ubuntu-latest
2322
steps:
2423
- uses: actions/checkout@v4
2524
with:
2625
submodules: true
27-
- name: Download and extract TensorFlow
28-
run: |
29-
wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
30-
tar -xzvf libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
31-
if: ${{ matrix.use_tensorflow }} == ON
32-
- name: Set TensorFlow environment variables
33-
run: |
34-
echo "export TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
35-
echo "export TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
36-
if: ${{ matrix.use_tensorflow }} == ON
3726
- name: Setup ccache
3827
uses: hendrikmuhs/[email protected]
3928
with:
@@ -45,11 +34,25 @@ jobs:
4534
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
4635
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
4736
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
48-
-DTensorFlow_INCLUDE_DIRS=${{ env.TensorFlow_INCLUDE_DIRS }} \
49-
-DTensorFlow_LIBRARIES=${{ env.TensorFlow_LIBRARIES }}
37+
-DOPENCV_PATH=3rdparty/opencv/build
5038
cmake --build build --parallel
5139
env:
5240
CTEST_OUTPUT_ON_FAILURE: 1
41+
- name: Prepare OpenCV libs
42+
run: |
43+
mkdir -p build/bin/opencv_libs
44+
cp -a 3rdparty/opencv/build/lib/libopencv_* build/bin/opencv_libs/
45+
echo "Library permissions after copy:"
46+
stat -c "%A %n" build/bin/opencv_libs/libopencv_imgcodecs.so*
47+
48+
- name: Upload artifacts
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: mnist-${{ matrix.build_type }}
52+
path: |
53+
build/bin/ACC_MNIST*
54+
build/bin/opencv_libs/*
55+
build/setenv.sh
5356
- name: Test
5457
run: cmake --build build -t test
5558
env:
@@ -70,16 +73,6 @@ jobs:
7073
- name: Install prerequisites
7174
run: |
7275
sudo apt install clang libomp-dev
73-
- name: Download and extract TensorFlow
74-
run: |
75-
wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
76-
tar -xzvf libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
77-
- name: Set TensorFlow environment variables
78-
run: |
79-
echo "TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
80-
echo "TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
81-
echo "export TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
82-
echo "export TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
8376
- name: Setup ccache
8477
uses: hendrikmuhs/[email protected]
8578
with:
@@ -90,7 +83,7 @@ jobs:
9083
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
9184
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
9285
-DCMAKE_C_COMPILER=clang \
93-
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DTensorFlow_INCLUDE_DIRS=${{ env.TensorFlow_INCLUDE_DIRS }} -DTensorFlow_LIBRARIES=${{ env.TensorFlow_LIBRARIES }}
86+
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
9487
cmake --build build --parallel
9588
- name: Test
9689
run: cmake --build build -t test
@@ -113,16 +106,6 @@ jobs:
113106
run: |
114107
brew install libomp
115108
brew link libomp --overwrite --force
116-
- name: Download and extract TensorFlow
117-
run: |
118-
curl -O https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.7.0.tar.gz
119-
tar -xzvf libtensorflow-cpu-darwin-x86_64-2.7.0.tar.gz
120-
- name: Set TensorFlow environment variables
121-
run: |
122-
echo "TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
123-
echo "TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.dylib" >> $GITHUB_ENV
124-
echo "export TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
125-
echo "export TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.dylib" >> $GITHUB_ENV
126109
- name: Setup ccache
127110
uses: hendrikmuhs/[email protected]
128111
with:
@@ -133,7 +116,7 @@ jobs:
133116
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
134117
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
135118
-DCMAKE_C_FLAGS="-I$(brew --prefix libomp)/include" \
136-
-DCMAKE_CXX_FLAGS="-I$(brew --prefix libomp)/include" -DTensorFlow_INCLUDE_DIRS=$TensorFlow_INCLUDE_DIRS -DTensorFlow_LIBRARIES=$TensorFlow_LIBRARIES
119+
-DCMAKE_CXX_FLAGS="-I$(brew --prefix libomp)/include"
137120
cmake --build build --parallel
138121
- name: Test
139122
run: cmake --build build -t test
@@ -145,10 +128,6 @@ jobs:
145128
- uses: actions/checkout@v4
146129
with:
147130
submodules: true
148-
- name: Download and extract TensorFlow
149-
run: |
150-
curl -O https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.7.0.zip
151-
Expand-Archive -Path libtensorflow-cpu-windows-x86_64-2.7.0.zip -DestinationPath 3rdparty/tensorflow
152131
- name: Setup ccache
153132
uses: hendrikmuhs/[email protected]
154133
with:
@@ -174,20 +153,6 @@ jobs:
174153
- uses: actions/checkout@v4
175154
with:
176155
submodules: true
177-
- name: Download and extract TensorFlow
178-
run: |
179-
wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
180-
tar -xzvf libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
181-
- name: Set TensorFlow environment variables
182-
run: |
183-
echo "TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
184-
echo "TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
185-
echo "export TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
186-
echo "export TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
187-
- name: Display TensorFlow environment variables
188-
run: |
189-
echo "TensorFlow_INCLUDE_DIRS: ${{ env.TensorFlow_INCLUDE_DIRS }}"
190-
echo "TensorFlow_LIBRARIES: ${{ env.TensorFlow_LIBRARIES }}"
191156
- name: Setup ccache
192157
uses: hendrikmuhs/[email protected]
193158
with:
@@ -201,9 +166,7 @@ jobs:
201166
-DCMAKE_C_FLAGS="--coverage" \
202167
-DCMAKE_CXX_FLAGS="--coverage" \
203168
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
204-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
205-
-DTensorFlow_INCLUDE_DIRS=${{ env.TensorFlow_INCLUDE_DIRS }} \
206-
-DTensorFlow_LIBRARIES=${{ env.TensorFlow_LIBRARIES }}
169+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
207170
cmake --build build --parallel
208171
- name: Test
209172
run: cmake --build build -t test
@@ -216,3 +179,110 @@ jobs:
216179
with:
217180
token: ${{ secrets.CODECOV_TOKEN }}
218181
slug: embedded-dev-research/itlab_2023
182+
183+
evaluate-model:
184+
runs-on: ubuntu-latest
185+
needs: [build-linux]
186+
permissions:
187+
contents: write
188+
189+
steps:
190+
- uses: actions/checkout@v4
191+
with:
192+
fetch-depth: 0
193+
194+
- name: Install system dependencies
195+
run: |
196+
sudo apt-get update
197+
sudo apt-get install -y \
198+
libgtk-3-0 \
199+
libtbb12 \
200+
libjpeg-dev \
201+
libpng-dev \
202+
libtiff-dev
203+
sudo ldconfig
204+
- name: Generate model JSON
205+
run: |
206+
cd app/AlexNet
207+
pip install -r requirements.txt
208+
python parser.py
209+
cd ../..
210+
211+
- name: Download MNIST test dataset
212+
run: |
213+
mkdir -p docs/mnist/mnist/test
214+
if [ ! -f "docs/mnist/mnist/test/0_000000.png" ]; then
215+
echo "Downloading test images..."
216+
wget -q https://github.com/DeepTrackAI/MNIST_dataset/archive/main.zip
217+
unzip -q main.zip
218+
cp MNIST_dataset-main/mnist/test/*.png docs/mnist/mnist/test/
219+
rm -rf main.zip MNIST_dataset-main
220+
echo "Downloaded $(ls docs/mnist/mnist/test | wc -l) images"
221+
fi
222+
223+
- name: Download binary and libs
224+
uses: actions/download-artifact@v4
225+
with:
226+
name: mnist-RELEASE
227+
path: build/
228+
229+
- name: Prepare environment
230+
run: |
231+
chmod +x build/bin/ACC_MNIST*
232+
233+
export LD_LIBRARY_PATH=$PWD/build/bin/opencv_libs:/usr/lib/x86_64-linux-gnu
234+
echo "Final LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
235+
236+
- name: Verify library integrity
237+
run: |
238+
echo "### Library verification ###"
239+
file build/bin/opencv_libs/libopencv_imgcodecs.so.4.9.0 | grep "shared object"
240+
ldd build/bin/opencv_libs/libopencv_imgcodecs.so.4.9.0 || true
241+
realpath build/bin/opencv_libs/libopencv_imgcodecs.so.409
242+
243+
- name: Run evaluation
244+
run: |
245+
echo "### Pre-run checks ###"
246+
export LD_LIBRARY_PATH=$PWD/build/bin/opencv_libs:/usr/lib/x86_64-linux-gnu
247+
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
248+
249+
LD_DEBUG=files ./build/bin/ACC_MNIST* 2> ld_debug.log || true
250+
echo "### Library loading debug ###"
251+
grep -i "opencv_imgcodecs" ld_debug.log
252+
253+
./build/bin/ACC_MNIST* > accuracy.txt
254+
echo "Accuracy: $(cat accuracy.txt)"
255+
256+
- name: Update README (master only)
257+
if: github.ref == 'refs/heads/master'
258+
run: |
259+
ACCURACY=$(cat accuracy.txt | sed 's/%//g')
260+
DATE=$(date '+%Y-%m-%d')
261+
262+
echo "Updating README with:"
263+
echo "Accuracy: $ACCURACY"
264+
echo "Date: $DATE"
265+
266+
echo "Current README content:"
267+
grep -A 2 -B 2 "ACCURACY_PLACEHOLDER" README.md || echo "Placeholder not found"
268+
269+
sed -i "s/<!--ACCURACY_PLACEHOLDER-->.*<!--END_ACCURACY-->/<!--ACCURACY_PLACEHOLDER-->Accuracy: ${ACCURACY}% (updated: ${DATE})<!--END_ACCURACY-->/" README.md
270+
271+
echo "Updated README content:"
272+
grep -A 2 -B 2 "ACCURACY_PLACEHOLDER" README.md
273+
274+
- name: Commit and push changes (master only)
275+
if: github.ref == 'refs/heads/master'
276+
run: |
277+
git config --global user.name "GitHub Actions"
278+
git config --global user.email "[email protected]"
279+
280+
git add README.md
281+
282+
if git diff-index --quiet HEAD --; then
283+
echo "No changes to commit"
284+
else
285+
git commit -m "[CI] Update accuracy: $(cat accuracy.txt)%"
286+
git push origin master
287+
echo "Changes pushed to master branch"
288+
fi

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
[![codecov](https://codecov.io/gh/embedded-dev-research/itlab_2023/graph/badge.svg?token=L3OS8C4BI6)](https://codecov.io/gh/embedded-dev-research/itlab_2023)
33

44
# AlexNet-MNIST-Inference
5+
## Model Performance
6+
7+
<!--ACCURACY_PLACEHOLDER-->Accuracy: Stat: 98.01% (updated: 2025-04-28)<!--END_ACCURACY-->
58
## Short description
69
A lightweight C++ library for performing high-performance inference on MNIST handwritten digits using a modified AlexNet architecture. Designed for efficiency and educational purposes, this project demonstrates how classic CNNs can be optimized for small-scale tasks in native environments.
710
### Key Features:

0 commit comments

Comments
 (0)