songweijia opened a new issue #15373: CPP inference example behaves different 
from Python one
URL: https://github.com/apache/incubator-mxnet/issues/15373
 
 
   ## The CPP inference example (inception_inference) seems not working
   I followed the [CPP 
tutorial](https://mxnet.incubator.apache.org/versions/master/tutorials/c++/mxnet_cpp_inference_tutorial.html).
 But found the CPP inference does not work as I expected. The python code works 
totally fine:
   ```
   $ ./inference.py data/test/watercress/image_00672.jpg 
   probability=11.384139, class=watercress, idx=98
   ```
   But when I use the code at 
incubator-mxnet/cpp-package/example/inference/inception_inference.cpp, loading 
EXACTLY THE SAME parameter file, symbol json file, and mean/std file, it gives 
me a DIFFERENT result:
   ```
   [12:27:12] inception_inference.cpp:150: Loading the model from 
/home/weijia/workspace/learn-mxnet/flower-recognition-symbol.json
   
   [12:27:12] inception_inference.cpp:163: Loading the model parameters from 
/home/weijia/workspace/learn-mxnet/flower-recognition-0010.params
   
   [12:27:12] inception_inference.cpp:190: Loading the synset file.
   [12:27:12] inception_inference.cpp:212: Load the mean image data that will 
be used to normalize the image before running forward pass.
   [12:27:12] inception_inference.cpp:257: Loading the image 
/home/weijia/workspace/learn-mxnet/data/test/watercress/image_00672.jpg
   
   [12:27:12] inception_inference.cpp:290: Running the forward pass on model to 
predict the image
   [12:27:13] inception_inference.cpp:325: The model predicts the input image 
to be a [ ] with Accuracy = 11.5736
   ```
   I checked the `best_idx`, which is evaluated to 73.
   
   ## Environment info (Required)
   ```
   $uname -a
   Linux compute26 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 
x86_64 x86_64 x86_64 GNU/Linux
   ```
   
   ## Build info (Required if built from source)
   
   Compiler (gcc/clang/mingw/visual studio):
   ```
   $ gcc -v
   Using built-in specs.
   COLLECT_GCC=gcc
   COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
   OFFLOAD_TARGET_NAMES=nvptx-none
   OFFLOAD_TARGET_DEFAULT=1
   Target: x86_64-linux-gnu
   Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
7.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs 
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr 
--with-gcc-major-version-only --program-suffix=-7 
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie 
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto 
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic 
--enable-offload-targets=nvptx-none --without-cuda-driver 
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu 
--target=x86_64-linux-gnu
   Thread model: posix
   gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04)
   ```
   
   MXNet commit hash: `12c422697413cfd69d846cdb4d1d487c487220e2>`
   
   Build config:
   (Paste the content of config.mk, or the build command.)
   ```
   $ cmake -GNinja -DUSE_CUDA=OFF -DUSE_JEMALLOC=OFF -DUSE_MKL_IF_AVAILABLE=OFF 
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DUSE_CPP_PACKAGE=ON ..
   $ ninja
   ```
   Then, go to `incubator-mxnet/cpp_package/example/inferences`, change the 
`Makefile` to fit my path setting:
   ```
   diff --git a/cpp-package/example/inference/Makefile 
b/cpp-package/example/inference/Makefile
   index 5efe6cfb6..9b01d0d97 100644
   --- a/cpp-package/example/inference/Makefile
   +++ b/cpp-package/example/inference/Makefile
   @@ -25,7 +25,7 @@ CXX=g++
   
   
    CFLAGS=$(COMMFLAGS) -I../../../3rdparty/tvm/nnvm/include 
-I../../../3rdparty/dmlc-core/include -I ../../include -I ../../../include 
-Wall -O3 -msse3 -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas
   -CPPEX_EXTRA_LDFLAGS := -L../../../lib -lmxnet $(OPENCV_LDFLAGS)
   +CPPEX_EXTRA_LDFLAGS := -L../../../build -lmxnet $(OPENCV_LDFLAGS)
   
    all: $(CPPEX_EXE)
   ```
   And then, build the CPP example:
   ```
   $ make
   ```
   ## Steps to reproduce
   Run this command:
   ```
   ./inception_inference --params 
~/workspace/learn-mxnet/flower-recognition-0010.params --synset 
~/workspace/learn-mxnet/synset.txt --symbol 
~/workspace/learn-mxnet/flower-recognition-symbol.json --image 
~/workspace/learn-mxnet/data/test/watercress/image_00672.jpg --mean 
~/workspace/learn-mxnet/mean_std_224.nd --input_shape "3 224 224"
   ```
   
   ## What have you tried to solve it?
   I checked that I'm using the correct parameter files, symbol files, and 
mean/std files.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to