diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..b1189a5042a6c95dfb986338530bce896b5eba94 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,43 @@ +# +# +# ****************************************************************************** +# MontiCAR Modeling Family, www.se-rwth.de +# Copyright (c) 2017, Software Engineering Group at RWTH Aachen, +# All rights reserved. +# +# This project is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this project. If not, see . +# ******************************************************************************* +# + +stages: +- linux + +TestMXNET: + stage: linux + image: registry.git.rwth-aachen.de/monticore/embeddedmontiarc/applications/mnistcalculator/mxnet:v0.0.3 + script: + - cd mxnet + - ./prepare.sh + - ./build.sh + - RES=$(./build/src/cpp/DigitCalculator resources/images/1.png resources/images/2.png resources/images/3.png resources/images/4.png resources/images/5.png resources/images/6.png) + - "if [[ $RES != *\"SUM: 579\"* ]]; then echo \"Wrong result:\" $RES; exit 1; fi;" + + +TestCAFFE2: + stage: linux + image: registry.git.rwth-aachen.de/monticore/embeddedmontiarc/applications/mnistcalculator/caffe2:v0.0.2 + script: + - cd caffe2 + - ./build.sh + - RES=$(./build/src/cpp/DigitCalculator resources/images/2.jpg resources/images/3.jpg resources/images/4.png resources/images/6.png resources/images/2.jpg resources/images/3.jpg) + - "if [[ $RES != *\"SUM: 857\"* ]]; then echo \"Wrong result:\" $RES; exit 1; fi;" diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..33b2b6816e156d64f23b589c8e44041302fbdce0 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# MNISTCalculator + + +## Prerequisites +1. Ubuntu Linux 16.04 LTS or 18.04 LTS (experimental) +2. Deep Learning Framework **Caffe2**. [Follow the instructions from this link](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/CNNArch2Caffe2#ubuntu). +3. Deep Learning Framework **MXNet**. +4. Armadillo (at least armadillo version 6.600 must be used) [Official instructions at Armadillo Website](http://arma.sourceforge.net/download.html). +4. OpenCV + +## MXNet and Caffe2 +For detailed instructions on how to run the MXNet and Caffe2 example, see the README in the corresponding folder. \ No newline at end of file diff --git a/caffe2/.gitignore b/caffe2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a375722583c1f578b920d98b358d1959366bead4 --- /dev/null +++ b/caffe2/.gitignore @@ -0,0 +1,4 @@ +train.log +target/ +model/ +build/ \ No newline at end of file diff --git a/example/CMakeLists.txt b/caffe2/CMakeLists.txt similarity index 100% rename from example/CMakeLists.txt rename to caffe2/CMakeLists.txt diff --git a/caffe2/README.md b/caffe2/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a91d0d398e7980e6f999939e26a6b1f42ff8924e --- /dev/null +++ b/caffe2/README.md @@ -0,0 +1,36 @@ +# MNISTCalculator Caffe2 + + +## Prerequisites +1. Ubuntu Linux 16.04 LTS or 18.04 LTS (experimental) +2. Deep Learning Framework **Caffe2**. [Follow the instructions from this link](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/CNNArch2Caffe2#ubuntu). +3. Armadillo (at least armadillo version 6.600 must be used) [Official instructions at Armadillo Website](http://arma.sourceforge.net/download.html). +4. OpenCV + + +## How to Run +Generate and build the code for the EMADL model by executing: + +``` +bash build.sh +``` + +Finally, run the calculator as follows: +``` +./build/src/cpp/DigitCalculator test_img/2.jpg test_img/3.jpg test_img/4.png test_img/6.png test_img/2.jpg test_img/3.jpg +``` + +You can try different images from the provided `/test_img` directory or even create your own images for testing. Note that the application program DigitCalculator will automatically rescale the given input image to the size 28x28. + + +## Troubleshooting Help + +ERROR: HelperA.h:79:28: error: ‘sqrtmat’ was not declared in this scope. + +FIX: +Copy compiled armadillo lib and include files to usr/lib and usr/include respectively. Replace YOUR_ARMADILLO_REPOSITORY and VERSION (e.g. 8.500.1) with your corresponding information: +``` +cd YOUR_ARMADILLO_REPOSITORY/armadillo-VERSION +sudo cp libarmadillo* /usr/lib +cd YOUR_ARMADILLO_REPOSITORY/armadillo-VERSION/include +sudo cp -r * /usr/include diff --git a/example_caffe2/build.sh b/caffe2/build.sh similarity index 52% rename from example_caffe2/build.sh rename to caffe2/build.sh index 25257b559df50697ae5b03232cfd017f009b6686..bf11cc81f2238d77516d36a9aee29915ea3d14dd 100755 --- a/example_caffe2/build.sh +++ b/caffe2/build.sh @@ -1,5 +1,5 @@ -rm -r target/; -java -jar embedded-montiarc-emadl-generator-0.2.9-jar-with-dependencies.jar -m src/emadl/models/ -r cNNCalculator.Connector -o target -b CAFFE2 +rm -rf target +java -jar ../embedded-montiarc-emadl-generator-0.2.13-jar-with-dependencies.jar -m src/emadl/models/ -r cNNCalculator.Connector -o target -b CAFFE2 rm -rf build mkdir build && cd build diff --git a/caffe2/resources/docker/Dockerfile b/caffe2/resources/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3ce8bc0641a0bd39d979e3ab5322f707b33ab0fa --- /dev/null +++ b/caffe2/resources/docker/Dockerfile @@ -0,0 +1,4 @@ +FROM registry.git.rwth-aachen.de/monticore/embeddedmontiarc/generators/emadl2cpp/integrationtests/caffe2:v0.0.5 + +RUN apt-get update +RUN apt-get install -y libopenblas-dev \ No newline at end of file diff --git a/example_caffe2/test_img/2.jpg b/caffe2/resources/images/2.jpg similarity index 100% rename from example_caffe2/test_img/2.jpg rename to caffe2/resources/images/2.jpg diff --git a/example_caffe2/test_img/3.jpg b/caffe2/resources/images/3.jpg similarity index 100% rename from example_caffe2/test_img/3.jpg rename to caffe2/resources/images/3.jpg diff --git a/example_caffe2/test_img/4.png b/caffe2/resources/images/4.png similarity index 100% rename from example_caffe2/test_img/4.png rename to caffe2/resources/images/4.png diff --git a/example_caffe2/test_img/6.png b/caffe2/resources/images/6.png similarity index 100% rename from example_caffe2/test_img/6.png rename to caffe2/resources/images/6.png diff --git a/caffe2/resources/training_data/test_lmdb/data.mdb b/caffe2/resources/training_data/test_lmdb/data.mdb new file mode 100755 index 0000000000000000000000000000000000000000..f32d4d2b9500cf48b4889978612dc48669707b11 Binary files /dev/null and b/caffe2/resources/training_data/test_lmdb/data.mdb differ diff --git a/caffe2/resources/training_data/test_lmdb/lock.mdb b/caffe2/resources/training_data/test_lmdb/lock.mdb new file mode 100755 index 0000000000000000000000000000000000000000..9b4b004a3b9427dcc34dffc79ccf7982ea8559df Binary files /dev/null and b/caffe2/resources/training_data/test_lmdb/lock.mdb differ diff --git a/caffe2/resources/training_data/train_lmdb/data.mdb b/caffe2/resources/training_data/train_lmdb/data.mdb new file mode 100755 index 0000000000000000000000000000000000000000..4a4a977f239ca2605b3c009cc19ba8c3aa8d6d69 Binary files /dev/null and b/caffe2/resources/training_data/train_lmdb/data.mdb differ diff --git a/caffe2/resources/training_data/train_lmdb/lock.mdb b/caffe2/resources/training_data/train_lmdb/lock.mdb new file mode 100755 index 0000000000000000000000000000000000000000..ae31ea81055711f9a8ae54df1468c667cf90baf5 Binary files /dev/null and b/caffe2/resources/training_data/train_lmdb/lock.mdb differ diff --git a/example_caffe2/src/cpp/CMakeLists.txt b/caffe2/src/cpp/CMakeLists.txt similarity index 100% rename from example_caffe2/src/cpp/CMakeLists.txt rename to caffe2/src/cpp/CMakeLists.txt diff --git a/example_caffe2/src/cpp/DigitCalculator.cpp b/caffe2/src/cpp/DigitCalculator.cpp similarity index 100% rename from example_caffe2/src/cpp/DigitCalculator.cpp rename to caffe2/src/cpp/DigitCalculator.cpp diff --git a/example/src/emadl/models/cNNCalculator/Add.emadl b/caffe2/src/emadl/models/cNNCalculator/Add.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/Add.emadl rename to caffe2/src/emadl/models/cNNCalculator/Add.emadl diff --git a/example/src/emadl/models/cNNCalculator/ArgMax.emadl b/caffe2/src/emadl/models/cNNCalculator/ArgMax.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/ArgMax.emadl rename to caffe2/src/emadl/models/cNNCalculator/ArgMax.emadl diff --git a/example/src/emadl/models/cNNCalculator/Calculator.emadl b/caffe2/src/emadl/models/cNNCalculator/Calculator.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/Calculator.emadl rename to caffe2/src/emadl/models/cNNCalculator/Calculator.emadl diff --git a/example_caffe2/src/emadl/models/cNNCalculator/Connector.emadl b/caffe2/src/emadl/models/cNNCalculator/Connector.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/Connector.emadl rename to caffe2/src/emadl/models/cNNCalculator/Connector.emadl diff --git a/example/src/emadl/models/cNNCalculator/DigitCombiner.emadl b/caffe2/src/emadl/models/cNNCalculator/DigitCombiner.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/DigitCombiner.emadl rename to caffe2/src/emadl/models/cNNCalculator/DigitCombiner.emadl diff --git a/example_caffe2/src/emadl/models/cNNCalculator/Network.cnnt b/caffe2/src/emadl/models/cNNCalculator/Network.cnnt similarity index 88% rename from example_caffe2/src/emadl/models/cNNCalculator/Network.cnnt rename to caffe2/src/emadl/models/cNNCalculator/Network.cnnt index 5887cea81de839ce48f7dc5a28ee594bfc2d791b..63d9af4f1e314aa0bfb5644a05041c197bb76425 100644 --- a/example_caffe2/src/emadl/models/cNNCalculator/Network.cnnt +++ b/caffe2/src/emadl/models/cNNCalculator/Network.cnnt @@ -1,7 +1,7 @@ configuration Network{ - num_epoch:11 + num_epoch:10 batch_size:64 - context:gpu + context:cpu eval_metric:accuracy optimizer:adam{ learning_rate:0.001 diff --git a/example_caffe2/src/emadl/models/cNNCalculator/Network.emadl b/caffe2/src/emadl/models/cNNCalculator/Network.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/Network.emadl rename to caffe2/src/emadl/models/cNNCalculator/Network.emadl diff --git a/example/src/emadl/models/cNNCalculator/VGG16.cnnt b/caffe2/src/emadl/models/cNNCalculator/VGG16.cnnt similarity index 100% rename from example/src/emadl/models/cNNCalculator/VGG16.cnnt rename to caffe2/src/emadl/models/cNNCalculator/VGG16.cnnt diff --git a/example/src/emadl/models/cNNCalculator/VGG16.emadl b/caffe2/src/emadl/models/cNNCalculator/VGG16.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/VGG16.emadl rename to caffe2/src/emadl/models/cNNCalculator/VGG16.emadl diff --git a/example_caffe2/src/emadl/models/data_paths.txt b/caffe2/src/emadl/models/data_paths.txt similarity index 100% rename from example_caffe2/src/emadl/models/data_paths.txt rename to caffe2/src/emadl/models/data_paths.txt diff --git a/example/src/resources/data/vGG16/test.h5 b/caffe2/src/resources/data/vGG16/test.h5 similarity index 100% rename from example/src/resources/data/vGG16/test.h5 rename to caffe2/src/resources/data/vGG16/test.h5 diff --git a/example/src/resources/data/vGG16/train.h5 b/caffe2/src/resources/data/vGG16/train.h5 similarity index 100% rename from example/src/resources/data/vGG16/train.h5 rename to caffe2/src/resources/data/vGG16/train.h5 diff --git a/example_caffe2/embedded-montiarc-emadl-generator-0.2.9-jar-with-dependencies.jar b/embedded-montiarc-emadl-generator-0.2.13-jar-with-dependencies.jar similarity index 96% rename from example_caffe2/embedded-montiarc-emadl-generator-0.2.9-jar-with-dependencies.jar rename to embedded-montiarc-emadl-generator-0.2.13-jar-with-dependencies.jar index 58c034a65605946324be1a5d07300afb42c0fc22..45d51e432efce6bb58c2aad7808c1ad27907b1e8 100644 Binary files a/example_caffe2/embedded-montiarc-emadl-generator-0.2.9-jar-with-dependencies.jar and b/embedded-montiarc-emadl-generator-0.2.13-jar-with-dependencies.jar differ diff --git a/example/build.sh b/example/build.sh deleted file mode 100755 index bcada44ee90040b90f7565ef992590e312367f19..0000000000000000000000000000000000000000 --- a/example/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -rm -r target/; -java -jar embedded-montiarc-emadl-generator-0.2.5-SNAPSHOT-jar-with-dependencies.jar -m src/emadl/models/ -r cNNCalculator.Connector -o target -b MXNET - -rm -rf build -mkdir build && cd build - -echo "Building DigitClassifier.." -cmake .. -#cp -r /home/christopher/Documents/Master/Semester2/Praktikum/mxnet/include/mxnet/ ../target/ -make \ No newline at end of file diff --git a/example/embedded-montiarc-emadl-generator-0.2.5-SNAPSHOT-jar-with-dependencies.jar b/example/embedded-montiarc-emadl-generator-0.2.5-SNAPSHOT-jar-with-dependencies.jar deleted file mode 100644 index 5d574fec49cc71c5a62995ce5c24b51730027df5..0000000000000000000000000000000000000000 Binary files a/example/embedded-montiarc-emadl-generator-0.2.5-SNAPSHOT-jar-with-dependencies.jar and /dev/null differ diff --git a/example/generate.sh b/example/generate.sh deleted file mode 100644 index 3c1e259411b2b18b9a791ca757a7a75e70bc21dc..0000000000000000000000000000000000000000 --- a/example/generate.sh +++ /dev/null @@ -1,4 +0,0 @@ -echo "-- Generating files and training Models:" - -java -jar embedded-montiarc-emadl-generator-0.2.5-SNAPSHOT-jar-with-dependencies.jar -m src/emadl/models -r cNNCalculator.Connector -o target -b MXNET - diff --git a/example/images/0.jpg b/example/images/0.jpg deleted file mode 100644 index dd1bc63359f3362de2cc9f14d15ebdb0f1e5ebc6..0000000000000000000000000000000000000000 Binary files a/example/images/0.jpg and /dev/null differ diff --git a/example/images/1.jpg b/example/images/1.jpg deleted file mode 100644 index 2699c40b322105eb36fa70e8e23a5b261a91d0ef..0000000000000000000000000000000000000000 Binary files a/example/images/1.jpg and /dev/null differ diff --git a/example/images/2.jpg b/example/images/2.jpg deleted file mode 100644 index 1ecf1c17378c5681f231c8a65aca2204ddc11ecd..0000000000000000000000000000000000000000 Binary files a/example/images/2.jpg and /dev/null differ diff --git a/example/images/3.jpg b/example/images/3.jpg deleted file mode 100644 index 8b52a6d3da5f64b9375989e3eb7e16b1e17aeda4..0000000000000000000000000000000000000000 Binary files a/example/images/3.jpg and /dev/null differ diff --git a/example/images/4.jpg b/example/images/4.jpg deleted file mode 100644 index e998df901c05c7572caccdd563672bb5f33e77a7..0000000000000000000000000000000000000000 Binary files a/example/images/4.jpg and /dev/null differ diff --git a/example/images/5.jpg b/example/images/5.jpg deleted file mode 100644 index 988b7228eb555562c9462cfa5e676b079f02d9af..0000000000000000000000000000000000000000 Binary files a/example/images/5.jpg and /dev/null differ diff --git a/example/images/6.jpg b/example/images/6.jpg deleted file mode 100644 index 5bc4953157ecef7c46ab3a05ba88e518eaf5e4d3..0000000000000000000000000000000000000000 Binary files a/example/images/6.jpg and /dev/null differ diff --git a/example/images/7.jpg b/example/images/7.jpg deleted file mode 100644 index fd1644ca5d4f1c3c5cd9d38e970f6f70ff26fbc9..0000000000000000000000000000000000000000 Binary files a/example/images/7.jpg and /dev/null differ diff --git a/example/images/8.jpg b/example/images/8.jpg deleted file mode 100644 index 95988d65758ae7810cd35b21c2301c117825a720..0000000000000000000000000000000000000000 Binary files a/example/images/8.jpg and /dev/null differ diff --git a/example/images/9.jpg b/example/images/9.jpg deleted file mode 100644 index 0fe63e1807a9fedfff2fed7d579d09e031101f7b..0000000000000000000000000000000000000000 Binary files a/example/images/9.jpg and /dev/null differ diff --git a/example/images/black.jpg b/example/images/black.jpg deleted file mode 100644 index 5226016c0c716977a65db92a12ece1411a89deec..0000000000000000000000000000000000000000 Binary files a/example/images/black.jpg and /dev/null differ diff --git a/example/images/white.jpg b/example/images/white.jpg deleted file mode 100644 index 095af016720a8430be2207ad34ad6500dccd168f..0000000000000000000000000000000000000000 Binary files a/example/images/white.jpg and /dev/null differ diff --git a/example/resources/sort.sh b/example/resources/sort.sh deleted file mode 100755 index e0c67e733735271109e3a2912bef8ae36c7b792b..0000000000000000000000000000000000000000 --- a/example/resources/sort.sh +++ /dev/null @@ -1,39 +0,0 @@ -mkdir 0 -mv *-num0.png 0/. - -mkdir 1 -mv *-num1.png 1/. - - -mkdir 2 -mv *-num2.png 2/. - - -mkdir 3 -mv *-num3.png 3/. - -mkdir 4 -mv *-num4.png 4/. - - -mkdir 5 -mv *-num5.png 5/. - - -mkdir 6 -mv *-num6.png 6/. - - -mkdir 7 -mv *-num7.png 7/. - - -mkdir 8 -mv *-num8.png 8/. - - -mkdir 9 -mv *-num9.png 9/. - - - diff --git a/example_caffe2/.gitignore b/example_caffe2/.gitignore deleted file mode 100644 index b78dd3fe549ebb5e088c56ecdf31c0e73c0ca366..0000000000000000000000000000000000000000 --- a/example_caffe2/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -train.log -target/ -resources/training_data -model/ -build/ \ No newline at end of file diff --git a/example_caffe2/images/0.jpg b/example_caffe2/images/0.jpg deleted file mode 100644 index dd1bc63359f3362de2cc9f14d15ebdb0f1e5ebc6..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/0.jpg and /dev/null differ diff --git a/example_caffe2/images/1.jpg b/example_caffe2/images/1.jpg deleted file mode 100644 index 2699c40b322105eb36fa70e8e23a5b261a91d0ef..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/1.jpg and /dev/null differ diff --git a/example_caffe2/images/2.jpg b/example_caffe2/images/2.jpg deleted file mode 100644 index 1ecf1c17378c5681f231c8a65aca2204ddc11ecd..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/2.jpg and /dev/null differ diff --git a/example_caffe2/images/3.jpg b/example_caffe2/images/3.jpg deleted file mode 100644 index 8b52a6d3da5f64b9375989e3eb7e16b1e17aeda4..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/3.jpg and /dev/null differ diff --git a/example_caffe2/images/4.jpg b/example_caffe2/images/4.jpg deleted file mode 100644 index e998df901c05c7572caccdd563672bb5f33e77a7..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/4.jpg and /dev/null differ diff --git a/example_caffe2/images/5.jpg b/example_caffe2/images/5.jpg deleted file mode 100644 index 988b7228eb555562c9462cfa5e676b079f02d9af..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/5.jpg and /dev/null differ diff --git a/example_caffe2/images/6.jpg b/example_caffe2/images/6.jpg deleted file mode 100644 index 5bc4953157ecef7c46ab3a05ba88e518eaf5e4d3..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/6.jpg and /dev/null differ diff --git a/example_caffe2/images/7.jpg b/example_caffe2/images/7.jpg deleted file mode 100644 index fd1644ca5d4f1c3c5cd9d38e970f6f70ff26fbc9..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/7.jpg and /dev/null differ diff --git a/example_caffe2/images/8.jpg b/example_caffe2/images/8.jpg deleted file mode 100644 index 95988d65758ae7810cd35b21c2301c117825a720..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/8.jpg and /dev/null differ diff --git a/example_caffe2/images/9.jpg b/example_caffe2/images/9.jpg deleted file mode 100644 index 0fe63e1807a9fedfff2fed7d579d09e031101f7b..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/9.jpg and /dev/null differ diff --git a/example_caffe2/images/black.jpg b/example_caffe2/images/black.jpg deleted file mode 100644 index 5226016c0c716977a65db92a12ece1411a89deec..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/black.jpg and /dev/null differ diff --git a/example_caffe2/images/white.jpg b/example_caffe2/images/white.jpg deleted file mode 100644 index 095af016720a8430be2207ad34ad6500dccd168f..0000000000000000000000000000000000000000 Binary files a/example_caffe2/images/white.jpg and /dev/null differ diff --git a/example_caffe2/resources/images/0.png b/example_caffe2/resources/images/0.png deleted file mode 100644 index 7e6e5bf1e101512267f09cd0179cb179ddd42814..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/0.png and /dev/null differ diff --git a/example_caffe2/resources/images/1.png b/example_caffe2/resources/images/1.png deleted file mode 100644 index b6272fdaf03c3045018c9a6bfa2a475809550eab..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/1.png and /dev/null differ diff --git a/example_caffe2/resources/images/2.png b/example_caffe2/resources/images/2.png deleted file mode 100644 index 26e1b894d41c30d83bc43589f179ceb2f4a6f474..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/2.png and /dev/null differ diff --git a/example_caffe2/resources/images/3.png b/example_caffe2/resources/images/3.png deleted file mode 100644 index d0a8b7d2a922a0b8726ffce217bb353368a815e4..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/3.png and /dev/null differ diff --git a/example_caffe2/resources/images/4.png b/example_caffe2/resources/images/4.png deleted file mode 100644 index 52e6b75f253b1166ab4af03cb195ee69e3f06ce7..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/4.png and /dev/null differ diff --git a/example_caffe2/resources/images/5.png b/example_caffe2/resources/images/5.png deleted file mode 100644 index 7c1722e0c669b9b6b41f17de288c32428b33b91f..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/5.png and /dev/null differ diff --git a/example_caffe2/resources/images/6.png b/example_caffe2/resources/images/6.png deleted file mode 100644 index 7528fad41e24fe9d8ad3eb9830fa03abb7220be1..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/6.png and /dev/null differ diff --git a/example_caffe2/resources/images/7.png b/example_caffe2/resources/images/7.png deleted file mode 100644 index 5134aa8fec499ef22ad6a436641e81210b3096c6..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/7.png and /dev/null differ diff --git a/example_caffe2/resources/images/8.png b/example_caffe2/resources/images/8.png deleted file mode 100644 index fac03a2643307c4fce91e2a5115bd17d5e833664..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/8.png and /dev/null differ diff --git a/example_caffe2/resources/images/9.png b/example_caffe2/resources/images/9.png deleted file mode 100644 index 4efdac5d348204d51517109da97cc5dd4ed921b2..0000000000000000000000000000000000000000 Binary files a/example_caffe2/resources/images/9.png and /dev/null differ diff --git a/example_caffe2/resources/imgDir-to-h5.py b/example_caffe2/resources/imgDir-to-h5.py deleted file mode 100644 index 8f621eb2b77e251a9253fa326b6f20ec91f299ee..0000000000000000000000000000000000000000 --- a/example_caffe2/resources/imgDir-to-h5.py +++ /dev/null @@ -1,88 +0,0 @@ -from __future__ import print_function -from __future__ import division -import h5py -import numpy as np -import cv2 -import os -import argparse -import errno -import random -import sys - - -def create_img_list(name, data_path): - dir_name = data_path + "/" + name - - image_paths = [] - image_class_indices = [] - print(dir_name) - for class_index_name in os.listdir(dir_name): - class_dir_path = dir_name + "/" + class_index_name - if os.path.isdir(class_dir_path): - for image_name in os.listdir(class_dir_path): - image_path = class_dir_path + "/" + image_name - image_paths.append(image_path) - class_index = float(class_index_name) - image_class_indices.append(class_index) - return image_paths, image_class_indices - -def create_h5_from_list(image_paths, image_class_indices, target_dir, target_file_name, input_port_name, output_port_name, shuffle=True): - img = cv2.imread(image_paths[0]) - t_img = np.transpose(img, (2,0,1)).astype(np.float32) - #t_img = t_img[-1:,:,:] - #print(t_img) - channels = t_img.shape[0] - height = t_img.shape[1] - width = t_img.shape[2] - data_size = len(image_paths) - - target_file = target_dir + "/" + target_file_name + ".h5" - if os.path.isfile(target_file): - print("File", target_file, "already exists. Skipping data file creation.") - return - try: - os.makedirs(target_dir) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - if shuffle: - combined = list(zip(image_paths, image_class_indices)) - random.shuffle(combined) - image_paths[:], image_class_indices[:] = zip(*combined) - - print("Creating " + target_file + " (images:" + str(data_size) + ", channels:" + str(channels) + ", height:" + str(height) + ", width:" + str(width) + "):") - with h5py.File(target_file, "w") as ofile: - in_dset = ofile.create_dataset(input_port_name, (data_size,channels, height, width), dtype=np.float32) - out_dset = ofile.create_dataset(output_port_name + "_label", (data_size,), dtype=np.float32) - for i in range(data_size): - img = cv2.imread(image_paths[i]) - t_img = np.transpose(img, (2,0,1)).astype(np.float32) - #t_img = t_img[-1:,:,:] - in_dset[i] = t_img - out_dset[i] = image_class_indices[i] - - #print progress - if i % 100 == 0: - percentage = 100*i / data_size - sys.stdout.write("\r{:0.1f}%".format(percentage)) - sys.stdout.flush() - sys.stdout.write("\r100.0%\n") - sys.stdout.flush() - - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Translate image directories into hdf5 training sets for EMADL.') - parser.add_argument("--in_port", action="store", dest="in_port", default="data") - parser.add_argument("--out_port", action="store", dest="out_port", default="softmax") - parser.add_argument("--data_path", action="store", dest="data_path", default=".") - parser.add_argument("--target_path", action="store", dest="target_path", default=".") - args = parser.parse_args() - for file_name in os.listdir(args.data_path): - if file_name == "train": - image_paths, image_class_indices = create_img_list(file_name, args.data_path) - create_h5_from_list(image_paths, image_class_indices, args.target_path, file_name, args.in_port, args.out_port) - if file_name == "test": - image_paths, image_class_indices = create_img_list(file_name, args.data_path) - create_h5_from_list(image_paths, image_class_indices, args.target_path, file_name, args.in_port, args.out_port) diff --git a/example_caffe2/resources/sort.sh b/example_caffe2/resources/sort.sh deleted file mode 100755 index e0c67e733735271109e3a2912bef8ae36c7b792b..0000000000000000000000000000000000000000 --- a/example_caffe2/resources/sort.sh +++ /dev/null @@ -1,39 +0,0 @@ -mkdir 0 -mv *-num0.png 0/. - -mkdir 1 -mv *-num1.png 1/. - - -mkdir 2 -mv *-num2.png 2/. - - -mkdir 3 -mv *-num3.png 3/. - -mkdir 4 -mv *-num4.png 4/. - - -mkdir 5 -mv *-num5.png 5/. - - -mkdir 6 -mv *-num6.png 6/. - - -mkdir 7 -mv *-num7.png 7/. - - -mkdir 8 -mv *-num8.png 8/. - - -mkdir 9 -mv *-num9.png 9/. - - - diff --git a/example_caffe2/test_img/8.jpeg b/example_caffe2/test_img/8.jpeg deleted file mode 100644 index e6d946b8f95ff297d9cadbc5f5c229be638a6ae8..0000000000000000000000000000000000000000 Binary files a/example_caffe2/test_img/8.jpeg and /dev/null differ diff --git a/example_caffe2/test_img/one.jpeg b/example_caffe2/test_img/one.jpeg deleted file mode 100644 index e1aed1ca5d31cf8816807c28e2a0971540b6e237..0000000000000000000000000000000000000000 Binary files a/example_caffe2/test_img/one.jpeg and /dev/null differ diff --git a/example_caffe2/test_img/three.jpeg b/example_caffe2/test_img/three.jpeg deleted file mode 100644 index c0f4f0e49b66100880e7a4f3efb23f027006c178..0000000000000000000000000000000000000000 Binary files a/example_caffe2/test_img/three.jpeg and /dev/null differ diff --git a/example_caffe2/test_img/three_1.jpeg b/example_caffe2/test_img/three_1.jpeg deleted file mode 100644 index f1112af2bb605aa24cc721488ae47f3e5799b193..0000000000000000000000000000000000000000 Binary files a/example_caffe2/test_img/three_1.jpeg and /dev/null differ diff --git a/example_caffe2/test_img/zero.jpeg b/example_caffe2/test_img/zero.jpeg deleted file mode 100644 index 0e8b3f314f640af07a12cabb539d3b98f849b30b..0000000000000000000000000000000000000000 Binary files a/example_caffe2/test_img/zero.jpeg and /dev/null differ diff --git a/example/.gitignore b/mxnet/.gitignore similarity index 100% rename from example/.gitignore rename to mxnet/.gitignore diff --git a/example_caffe2/CMakeLists.txt b/mxnet/CMakeLists.txt similarity index 100% rename from example_caffe2/CMakeLists.txt rename to mxnet/CMakeLists.txt diff --git a/mxnet/README.md b/mxnet/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3200252b56e52a70f41f34f634cd2b90834b1d67 --- /dev/null +++ b/mxnet/README.md @@ -0,0 +1,45 @@ +# Calculator MXNET + + +## Prerequisites +1. Ubuntu Linux 16.04 LTS or 18.04 LTS (experimental) +2. Deep Learning Framework **MXNet** +3. Armadillo (at least armadillo version 6.600 must be used) [Official instructions at Armadillo Website](http://arma.sourceforge.net/download.html). +4. OpenCV + +## Prepare the data + +To create the data for training, execute: + +``` +bash ./prepare.sh +``` + +## How to Run +Generate and build the code for the EMADL model by executing: + +``` +bash build.sh +``` + +Finally, run the calculator as follows: +``` +./build/src/cpp/DigitCalculator resources/images/1.png resources/images/2.png resources/images/3.png resources/images/4.png resources/images/5.png resources/images/6.png +``` + +You can try different images from the provided `/resources/images` directory or even create your own images for testing. Note that the application program DigitCalculator will automatically rescale the given input image to the size 32x32. + +Note: Currently, the mxnet example uses CIFAR-10 data, not MNIST! + + +## Troubleshooting Help + +ERROR: HelperA.h:79:28: error: ‘sqrtmat’ was not declared in this scope. + +FIX: +Copy compiled armadillo lib and include files to usr/lib and usr/include respectively. Replace YOUR_ARMADILLO_REPOSITORY and VERSION (e.g. 8.500.1) with your corresponding information: +``` +cd YOUR_ARMADILLO_REPOSITORY/armadillo-VERSION +sudo cp libarmadillo* /usr/lib +cd YOUR_ARMADILLO_REPOSITORY/armadillo-VERSION/include +sudo cp -r * /usr/include diff --git a/mxnet/build.sh b/mxnet/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..925f226b2acd7d5f47eac39637e8737a7ca88535 --- /dev/null +++ b/mxnet/build.sh @@ -0,0 +1,20 @@ +MXNET_PATH=$(python -c "import mxnet; print(mxnet.__file__)") +MXNET_FOLDER=$(dirname $MXNET_PATH) +echo $MXNET_FOLDER + +if [ ! -f $MXNET_FOLDER/libmxnet.so ]; then + echo "libmxnet.so not found at default location" $MXNET_FOLDER + echo "It should be there if the python mxnet package is installed" + echo "Either fix the installation, or adapt the ./build.sh script to locate libmxnet.so correctly" + exit 1 +fi + +rm -rf target +java -jar ../embedded-montiarc-emadl-generator-0.2.13-jar-with-dependencies.jar -m src/emadl/models/ -r cNNCalculator.Connector -o target -b MXNET + +rm -rf build +mkdir build && cd build + +echo "Building DigitClassifier.." +cmake -D MXNET_PATH=$MXNET_FOLDER/libmxnet.so .. +make \ No newline at end of file diff --git a/example/prepare.sh b/mxnet/prepare.sh similarity index 100% rename from example/prepare.sh rename to mxnet/prepare.sh diff --git a/mxnet/resources/docker/Dockerfile b/mxnet/resources/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..379f3029eb6bb23544776ed8795c22483217b274 --- /dev/null +++ b/mxnet/resources/docker/Dockerfile @@ -0,0 +1,31 @@ +FROM registry.git.rwth-aachen.de/monticore/embeddedmontiarc/generators/emadl2cpp/integrationtests/mxnet:v0.0.3 + +RUN pip install opencv-python + +# Install Open CV - Warning, this takes absolutely forever +RUN apt-get update && apt-get install -y libgdal-dev +RUN mkdir -p ~/opencv cd ~/opencv && \ + wget https://github.com/Itseez/opencv/archive/3.0.0.zip && \ + unzip 3.0.0.zip && \ + rm 3.0.0.zip && \ + mv opencv-3.0.0 OpenCV +RUN apt-get install -y qtbase5-dev +RUN apt-get install -y build-essential +ENV PATH="${PATH}:/usr/include/" +RUN cd OpenCV && \ + mkdir build && \ + cd build && \ + cmake \ + -DWITH_QT=ON \ + -DWITH_OPENGL=ON \ + -DFORCE_VTK=ON \ + -DWITH_TBB=ON \ + -DWITH_GDAL=ON \ + -DWITH_XINE=ON \ + -DBUILD_EXAMPLES=ON \ + -D ENABLE_PRECOMPILED_HEADERS=OFF .. +RUN cd OpenCV/build && make -j4 +RUN cd OpenCV/build && make install +RUN cd OpenCV/build && ldconfig + +RUN apt-get install -y libopenblas-dev \ No newline at end of file diff --git a/example/resources/images/0.png b/mxnet/resources/images/0.png similarity index 100% rename from example/resources/images/0.png rename to mxnet/resources/images/0.png diff --git a/example/resources/images/1.png b/mxnet/resources/images/1.png similarity index 100% rename from example/resources/images/1.png rename to mxnet/resources/images/1.png diff --git a/example/resources/images/2.png b/mxnet/resources/images/2.png similarity index 100% rename from example/resources/images/2.png rename to mxnet/resources/images/2.png diff --git a/example/resources/images/3.png b/mxnet/resources/images/3.png similarity index 100% rename from example/resources/images/3.png rename to mxnet/resources/images/3.png diff --git a/example/resources/images/4.png b/mxnet/resources/images/4.png similarity index 100% rename from example/resources/images/4.png rename to mxnet/resources/images/4.png diff --git a/example/resources/images/5.png b/mxnet/resources/images/5.png similarity index 100% rename from example/resources/images/5.png rename to mxnet/resources/images/5.png diff --git a/example/resources/images/6.png b/mxnet/resources/images/6.png similarity index 100% rename from example/resources/images/6.png rename to mxnet/resources/images/6.png diff --git a/example/resources/images/7.png b/mxnet/resources/images/7.png similarity index 100% rename from example/resources/images/7.png rename to mxnet/resources/images/7.png diff --git a/example/resources/images/8.png b/mxnet/resources/images/8.png similarity index 100% rename from example/resources/images/8.png rename to mxnet/resources/images/8.png diff --git a/example/resources/images/9.png b/mxnet/resources/images/9.png similarity index 100% rename from example/resources/images/9.png rename to mxnet/resources/images/9.png diff --git a/example/resources/imgDir-to-h5.py b/mxnet/resources/imgDir-to-h5.py similarity index 100% rename from example/resources/imgDir-to-h5.py rename to mxnet/resources/imgDir-to-h5.py diff --git a/example/src/cpp/CMakeLists.txt b/mxnet/src/cpp/CMakeLists.txt similarity index 74% rename from example/src/cpp/CMakeLists.txt rename to mxnet/src/cpp/CMakeLists.txt index c2e23b1b391a5d8ed945da016e2e5e4f358f0a4a..fa09183137fab046c10b94f62a337588c04fde91 100644 --- a/example/src/cpp/CMakeLists.txt +++ b/mxnet/src/cpp/CMakeLists.txt @@ -2,13 +2,14 @@ cmake_minimum_required(VERSION 3.5) project(DigitCalculator CXX) set(CMAKE_CXX_STANDARD 11) +option(MXNET_PATH "Path to libmxnet.so") add_executable(DigitCalculator DigitCalculator.cpp) set_target_properties(DigitCalculator PROPERTIES LINKER_LANGUAGE CXX) find_package(OpenCV REQUIRED) -target_link_libraries(DigitCalculator "/home/christopher/Documents/Master/Semester2/Praktikum/mxnet/lib/libmxnet.so") +target_link_libraries(DigitCalculator ${MXNET_PATH}) set(INCLUDE_DIRS ${INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}) set(LIBS ${LIBS} ${OpenCV_LIBS}) target_link_libraries(DigitCalculator cNNCalculator_connector ${LIBS} -lblas -lopenblas) diff --git a/example/src/cpp/DigitCalculator.cpp b/mxnet/src/cpp/DigitCalculator.cpp similarity index 100% rename from example/src/cpp/DigitCalculator.cpp rename to mxnet/src/cpp/DigitCalculator.cpp diff --git a/example_caffe2/src/emadl/models/cNNCalculator/Add.emadl b/mxnet/src/emadl/models/cNNCalculator/Add.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/Add.emadl rename to mxnet/src/emadl/models/cNNCalculator/Add.emadl diff --git a/example_caffe2/src/emadl/models/cNNCalculator/ArgMax.emadl b/mxnet/src/emadl/models/cNNCalculator/ArgMax.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/ArgMax.emadl rename to mxnet/src/emadl/models/cNNCalculator/ArgMax.emadl diff --git a/example_caffe2/src/emadl/models/cNNCalculator/Calculator.emadl b/mxnet/src/emadl/models/cNNCalculator/Calculator.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/Calculator.emadl rename to mxnet/src/emadl/models/cNNCalculator/Calculator.emadl diff --git a/example/src/emadl/models/cNNCalculator/Connector.emadl b/mxnet/src/emadl/models/cNNCalculator/Connector.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/Connector.emadl rename to mxnet/src/emadl/models/cNNCalculator/Connector.emadl diff --git a/example_caffe2/src/emadl/models/cNNCalculator/DigitCombiner.emadl b/mxnet/src/emadl/models/cNNCalculator/DigitCombiner.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/DigitCombiner.emadl rename to mxnet/src/emadl/models/cNNCalculator/DigitCombiner.emadl diff --git a/example/src/emadl/models/cNNCalculator/Network.cnnt b/mxnet/src/emadl/models/cNNCalculator/Network.cnnt similarity index 86% rename from example/src/emadl/models/cNNCalculator/Network.cnnt rename to mxnet/src/emadl/models/cNNCalculator/Network.cnnt index 5bc28ea32b47ee6d281d6d2418529ce3387475e3..4a92e62ba44155c1de8587161507289f5810e80c 100644 --- a/example/src/emadl/models/cNNCalculator/Network.cnnt +++ b/mxnet/src/emadl/models/cNNCalculator/Network.cnnt @@ -1,8 +1,8 @@ configuration Network{ - num_epoch:5 + num_epoch:10 batch_size:100 normalize:true - context:gpu + context:cpu load_checkpoint:false optimizer:sgd{ learning_rate:0.2 diff --git a/example/src/emadl/models/cNNCalculator/Network.emadl b/mxnet/src/emadl/models/cNNCalculator/Network.emadl similarity index 100% rename from example/src/emadl/models/cNNCalculator/Network.emadl rename to mxnet/src/emadl/models/cNNCalculator/Network.emadl diff --git a/example_caffe2/src/emadl/models/cNNCalculator/VGG16.cnnt b/mxnet/src/emadl/models/cNNCalculator/VGG16.cnnt similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/VGG16.cnnt rename to mxnet/src/emadl/models/cNNCalculator/VGG16.cnnt diff --git a/example_caffe2/src/emadl/models/cNNCalculator/VGG16.emadl b/mxnet/src/emadl/models/cNNCalculator/VGG16.emadl similarity index 100% rename from example_caffe2/src/emadl/models/cNNCalculator/VGG16.emadl rename to mxnet/src/emadl/models/cNNCalculator/VGG16.emadl diff --git a/example/src/emadl/models/data_paths.txt b/mxnet/src/emadl/models/data_paths.txt similarity index 100% rename from example/src/emadl/models/data_paths.txt rename to mxnet/src/emadl/models/data_paths.txt diff --git a/example_caffe2/src/resources/data/vGG16/test.h5 b/mxnet/src/resources/data/vGG16/test.h5 similarity index 100% rename from example_caffe2/src/resources/data/vGG16/test.h5 rename to mxnet/src/resources/data/vGG16/test.h5 diff --git a/example_caffe2/src/resources/data/vGG16/train.h5 b/mxnet/src/resources/data/vGG16/train.h5 similarity index 100% rename from example_caffe2/src/resources/data/vGG16/train.h5 rename to mxnet/src/resources/data/vGG16/train.h5