Skip to content

Add a simple C++ inference example for fluid #7097

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 5 commits into from
Jan 5, 2018

Conversation

Xreki
Copy link
Contributor

@Xreki Xreki commented Dec 28, 2017

To test this PR, you need to:

  • Download PicklingTools and build the library it in the C++ sub-directory using command make -f Makefile.Linux libptools.so.
  • Set environment variable PTOOLS_ROOT to the root directory of PicklingTools, then build PaddlePaddle from source codes of this PR.
  • Use pip install -U /home/liuyiqun01/PaddlePaddle/Paddle/build_paddle/dist/opt/paddle/share/wheels/paddlepaddle_gpu-0.11.0-cp27-cp27mu-linux_x86_64.whl to install the latest Paddle and run python test_recognize_digits_mlp.py to train the model, then you will get the inference model in sub-directory recognize_digits_mlp.inference.model

After these steps, you can run the example using:

$ GLOG_v=3 ./paddle/inference/example --dirname=/home/liuyiqun01/PaddlePaddle/Paddle/python/paddle/v2/fluid/tests/book/recognize_digits_mlp.inference.model --feed_var_names="x" --fetch_var_names="fc_2.tmp_2"

You will get output as following:

$ GLOG_v=3 ./paddle/inference/example --dirname=/home/liuyiqun01/PaddlePaddle/Paddle/python/paddle/v2/fluid/tests/book/recognize_digits_mlp.inference.model --feed_var_names="x" --fetch_var_names="fc_2.tmp_2"
FLAGS_dirname: /home/liuyiqun01/PaddlePaddle/Paddle/python/paddle/v2/fluid/tests/book/recognize_digits_mlp.inference.model
FLAGS_feed_var_names: x
FLAGS_fetch_var_names: fc_2.tmp_2
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0103 10:38:54.855207   876 inference.cc:34] Using PicklingTools, loading model from /home/liuyiqun01/PaddlePaddle/Paddle/python/paddle/v2/fluid/tests/book/recognize_digits_mlp.inference.model/__model__
I0103 10:38:54.855599   876 inference.cc:38] program_desc_str's size: 2787
I0103 10:38:54.855901   876 inference.cc:95] parameter's name: fc_1.b_0
I0103 10:38:54.855973   876 inference.cc:95] parameter's name: fc_2.w_0
I0103 10:38:54.856034   876 inference.cc:95] parameter's name: fc_2.b_0
I0103 10:38:54.856109   876 inference.cc:95] parameter's name: fc_0.b_0
I0103 10:38:54.856165   876 inference.cc:95] parameter's name: fc_0.w_0
I0103 10:38:54.856223   876 inference.cc:95] parameter's name: fc_1.w_0
I0103 10:38:54.856287   876 inference.cc:129] feed var's name: x
I0103 10:38:54.856359   876 inference.cc:156] fetch var's name: fc_2.tmp_2
I0103 10:38:57.726599   876 scope.cc:43] Create variable fc_0.b_0
I0103 10:38:57.726647   876 executor.cc:93] Create Variable fc_0.b_0 global, which pointer is 0x479d7b0
I0103 10:38:57.726665   876 scope.cc:43] Create variable fc_2.b_0
I0103 10:38:57.726675   876 executor.cc:93] Create Variable fc_2.b_0 global, which pointer is 0x479d8b0
I0103 10:38:57.726683   876 scope.cc:43] Create variable fc_1.w_0
I0103 10:38:57.726691   876 executor.cc:93] Create Variable fc_1.w_0 global, which pointer is 0x479d9b0
I0103 10:38:57.726701   876 scope.cc:43] Create variable fc_0.w_0
I0103 10:38:57.726709   876 executor.cc:93] Create Variable fc_0.w_0 global, which pointer is 0x479dab0
I0103 10:38:57.726717   876 scope.cc:43] Create variable fc_2.w_0
I0103 10:38:57.726725   876 executor.cc:93] Create Variable fc_2.w_0 global, which pointer is 0x479dbb0
I0103 10:38:57.726733   876 scope.cc:43] Create variable fc_1.b_0
I0103 10:38:57.726752   876 executor.cc:93] Create Variable fc_1.b_0 global, which pointer is 0x479dcb0
I0103 10:38:57.726824   876 executor.cc:114] Op(load), inputs:{}, outputs:{Out[fc_1.b_0]}.
I0103 10:38:57.726979   876 executor.cc:114] Op(load), inputs:{}, outputs:{Out[fc_2.w_0]}.
I0103 10:38:57.727031   876 executor.cc:114] Op(load), inputs:{}, outputs:{Out[fc_2.b_0]}.
I0103 10:38:57.727074   876 executor.cc:114] Op(load), inputs:{}, outputs:{Out[fc_0.b_0]}.
I0103 10:38:57.727126   876 executor.cc:114] Op(load), inputs:{}, outputs:{Out[fc_0.w_0]}.
I0103 10:38:57.727329   876 executor.cc:114] Op(load), inputs:{}, outputs:{Out[fc_1.w_0]}.
I0103 10:38:57.727392   876 feed_fetch_method.h:28] SetFeedVariable name=feed index=0
I0103 10:38:57.727409   876 scope.cc:43] Create variable feed
I0103 10:38:57.727437   876 scope.cc:43] Create variable fetch
I0103 10:38:57.727449   876 executor.cc:93] Create Variable fetch global, which pointer is 0x479d6e0
I0103 10:38:57.727458   876 scope.cc:43] Create variable fc_1.tmp_1@GRAD
I0103 10:38:57.727468   876 executor.cc:98] Create Variable fc_1.tmp_1@GRAD locally, which pointer is 0x479d750
I0103 10:38:57.727478   876 scope.cc:43] Create variable fc_2.w_0@GRAD
I0103 10:38:57.727486   876 executor.cc:98] Create Variable fc_2.w_0@GRAD locally, which pointer is 0x4799390
I0103 10:38:57.727496   876 scope.cc:43] Create variable fc_1.tmp_2@GRAD
I0103 10:38:57.727505   876 executor.cc:98] Create Variable fc_1.tmp_2@GRAD locally, which pointer is 0x47996a0
I0103 10:38:57.727516   876 scope.cc:43] Create variable fc_2.b_0@GRAD
I0103 10:38:57.727526   876 executor.cc:98] Create Variable fc_2.b_0@GRAD locally, which pointer is 0x47997a0
I0103 10:38:57.727535   876 scope.cc:43] Create variable _generated_var_1
I0103 10:38:57.727543   876 executor.cc:98] Create Variable _generated_var_1 locally, which pointer is 0x47998a0
I0103 10:38:57.727552   876 scope.cc:43] Create variable fc_2.tmp_1@GRAD
I0103 10:38:57.727560   876 executor.cc:98] Create Variable fc_2.tmp_1@GRAD locally, which pointer is 0x47999a0
I0103 10:38:57.727571   876 scope.cc:43] Create variable _generated_var_0
I0103 10:38:57.727579   876 executor.cc:98] Create Variable _generated_var_0 locally, which pointer is 0x4799aa0
I0103 10:38:57.727589   876 scope.cc:43] Create variable fc_0.tmp_0
I0103 10:38:57.727597   876 executor.cc:98] Create Variable fc_0.tmp_0 locally, which pointer is 0x4799ba0
I0103 10:38:57.727605   876 scope.cc:43] Create variable accuracy_0_0_total
I0103 10:38:57.727614   876 executor.cc:93] Create Variable accuracy_0_0_total global, which pointer is 0x4799ca0
I0103 10:38:57.727625   876 scope.cc:43] Create variable fc_0.tmp_1
I0103 10:38:57.727633   876 executor.cc:98] Create Variable fc_0.tmp_1 locally, which pointer is 0x4799da0
I0103 10:38:57.727643   876 scope.cc:43] Create variable fc_0.tmp_1@GRAD
I0103 10:38:57.727651   876 executor.cc:98] Create Variable fc_0.tmp_1@GRAD locally, which pointer is 0x4799ea0
I0103 10:38:57.727663   876 scope.cc:43] Create variable accuracy_1.tmp_0
I0103 10:38:57.727670   876 executor.cc:98] Create Variable accuracy_1.tmp_0 locally, which pointer is 0x4799fa0
I0103 10:38:57.727681   876 executor.cc:93] Create Variable fc_1.b_0 global, which pointer is 0x479dcb0
I0103 10:38:57.727690   876 scope.cc:43] Create variable cross_entropy_0.tmp_0@GRAD
I0103 10:38:57.727699   876 executor.cc:98] Create Variable cross_entropy_0.tmp_0@GRAD locally, which pointer is 0x47991b0
I0103 10:38:57.727708   876 scope.cc:43] Create variable fc_2.tmp_1
I0103 10:38:57.727716   876 executor.cc:98] Create Variable fc_2.tmp_1 locally, which pointer is 0x47afc70
I0103 10:38:57.727725   876 scope.cc:43] Create variable fc_0.tmp_0@GRAD
I0103 10:38:57.727735   876 executor.cc:98] Create Variable fc_0.tmp_0@GRAD locally, which pointer is 0x47afd70
I0103 10:38:57.727743   876 scope.cc:43] Create variable fc_2.tmp_2
I0103 10:38:57.727751   876 executor.cc:98] Create Variable fc_2.tmp_2 locally, which pointer is 0x47afe70
I0103 10:38:57.727759   876 scope.cc:43] Create variable fc_1.tmp_0
I0103 10:38:57.727767   876 executor.cc:98] Create Variable fc_1.tmp_0 locally, which pointer is 0x47aff70
I0103 10:38:57.727777   876 executor.cc:93] Create Variable fc_2.w_0 global, which pointer is 0x479dbb0
I0103 10:38:57.727784   876 scope.cc:43] Create variable y
I0103 10:38:57.727792   876 executor.cc:98] Create Variable y locally, which pointer is 0x47b0070
I0103 10:38:57.727803   876 executor.cc:93] Create Variable feed global, which pointer is 0x479d550
I0103 10:38:57.727813   876 executor.cc:93] Create Variable fc_2.b_0 global, which pointer is 0x479d8b0
I0103 10:38:57.727820   876 scope.cc:43] Create variable fc_1.b_0@GRAD
I0103 10:38:57.727828   876 executor.cc:98] Create Variable fc_1.b_0@GRAD locally, which pointer is 0x47b0170
I0103 10:38:57.727838   876 scope.cc:43] Create variable learning_rate_0
I0103 10:38:57.727845   876 executor.cc:93] Create Variable learning_rate_0 global, which pointer is 0x47b0270
I0103 10:38:57.727854   876 scope.cc:43] Create variable fc_0.b_0@GRAD
I0103 10:38:57.727861   876 executor.cc:98] Create Variable fc_0.b_0@GRAD locally, which pointer is 0x47b0370
I0103 10:38:57.727870   876 scope.cc:43] Create variable fc_1.tmp_2
I0103 10:38:57.727879   876 executor.cc:98] Create Variable fc_1.tmp_2 locally, which pointer is 0x47b0470
I0103 10:38:57.727887   876 scope.cc:43] Create variable fc_1.w_0@GRAD
I0103 10:38:57.727898   876 executor.cc:98] Create Variable fc_1.w_0@GRAD locally, which pointer is 0x47b0570
I0103 10:38:57.727906   876 scope.cc:43] Create variable mean_0.tmp_0
I0103 10:38:57.727915   876 executor.cc:98] Create Variable mean_0.tmp_0 locally, which pointer is 0x47b0670
I0103 10:38:57.727924   876 scope.cc:43] Create variable velocity_5
I0103 10:38:57.727937   876 executor.cc:93] Create Variable velocity_5 global, which pointer is 0x47b0770
I0103 10:38:57.727948   876 scope.cc:43] Create variable velocity_3
I0103 10:38:57.727957   876 executor.cc:93] Create Variable velocity_3 global, which pointer is 0x479d6a0
I0103 10:38:57.727967   876 scope.cc:43] Create variable fc_0.tmp_2@GRAD
I0103 10:38:57.727977   876 executor.cc:98] Create Variable fc_0.tmp_2@GRAD locally, which pointer is 0x47b09d0
I0103 10:38:57.727985   876 scope.cc:43] Create variable accuracy_0.tmp_0
I0103 10:38:57.727993   876 executor.cc:98] Create Variable accuracy_0.tmp_0 locally, which pointer is 0x47b0ba0
I0103 10:38:57.728001   876 scope.cc:43] Create variable velocity_2
I0103 10:38:57.728009   876 executor.cc:93] Create Variable velocity_2 global, which pointer is 0x47b0ca0
I0103 10:38:57.728018   876 scope.cc:43] Create variable accuracy_1.tmp_2
I0103 10:38:57.728025   876 executor.cc:98] Create Variable accuracy_1.tmp_2 locally, which pointer is 0x47b0da0
I0103 10:38:57.728035   876 scope.cc:43] Create variable _generated_var_2
I0103 10:38:57.728044   876 executor.cc:98] Create Variable _generated_var_2 locally, which pointer is 0x47b0ea0
I0103 10:38:57.728052   876 scope.cc:43] Create variable velocity_1
I0103 10:38:57.728060   876 executor.cc:93] Create Variable velocity_1 global, which pointer is 0x47b0fa0
I0103 10:38:57.728070   876 scope.cc:43] Create variable fc_1.tmp_0@GRAD
I0103 10:38:57.728077   876 executor.cc:98] Create Variable fc_1.tmp_0@GRAD locally, which pointer is 0x47b10a0
I0103 10:38:57.728096   876 scope.cc:43] Create variable clip_0.tmp_0
I0103 10:38:57.728104   876 executor.cc:98] Create Variable clip_0.tmp_0 locally, which pointer is 0x47b11a0
I0103 10:38:57.728113   876 scope.cc:43] Create variable fc_0.tmp_2
I0103 10:38:57.728121   876 executor.cc:98] Create Variable fc_0.tmp_2 locally, which pointer is 0x47b12a0
I0103 10:38:57.728130   876 scope.cc:43] Create variable fc_0.w_0@GRAD
I0103 10:38:57.728138   876 executor.cc:98] Create Variable fc_0.w_0@GRAD locally, which pointer is 0x47b13a0
I0103 10:38:57.728149   876 scope.cc:43] Create variable learning_rate_3
I0103 10:38:57.728157   876 executor.cc:93] Create Variable learning_rate_3 global, which pointer is 0x47b14a0
I0103 10:38:57.728168   876 executor.cc:93] Create Variable fc_0.b_0 global, which pointer is 0x479d7b0
I0103 10:38:57.728178   876 scope.cc:43] Create variable velocity_0
I0103 10:38:57.728185   876 executor.cc:93] Create Variable velocity_0 global, which pointer is 0x47b15a0
I0103 10:38:57.728194   876 scope.cc:43] Create variable accuracy_1.tmp_1
I0103 10:38:57.728202   876 executor.cc:98] Create Variable accuracy_1.tmp_1 locally, which pointer is 0x47b16a0
I0103 10:38:57.728210   876 executor.cc:93] Create Variable fc_0.w_0 global, which pointer is 0x479dab0
I0103 10:38:57.728219   876 scope.cc:43] Create variable accuracy_0.tmp_1
I0103 10:38:57.728226   876 executor.cc:98] Create Variable accuracy_0.tmp_1 locally, which pointer is 0x47b17a0
I0103 10:38:57.728240   876 scope.cc:43] Create variable learning_rate_1
I0103 10:38:57.728251   876 executor.cc:93] Create Variable learning_rate_1 global, which pointer is 0x47b18a0
I0103 10:38:57.728260   876 scope.cc:43] Create variable learning_rate_2
I0103 10:38:57.728267   876 executor.cc:93] Create Variable learning_rate_2 global, which pointer is 0x47b19a0
I0103 10:38:57.728276   876 scope.cc:43] Create variable cast_0.tmp_0
I0103 10:38:57.728284   876 executor.cc:98] Create Variable cast_0.tmp_0 locally, which pointer is 0x47b1aa0
I0103 10:38:57.728293   876 scope.cc:43] Create variable fc_2.tmp_0@GRAD
I0103 10:38:57.728303   876 executor.cc:98] Create Variable fc_2.tmp_0@GRAD locally, which pointer is 0x47b1ba0
I0103 10:38:57.728312   876 scope.cc:43] Create variable fc_1.tmp_1
I0103 10:38:57.728320   876 executor.cc:98] Create Variable fc_1.tmp_1 locally, which pointer is 0x47b1ca0
I0103 10:38:57.728328   876 executor.cc:93] Create Variable fc_1.w_0 global, which pointer is 0x479d9b0
I0103 10:38:57.728338   876 scope.cc:43] Create variable cross_entropy_0.tmp_0
I0103 10:38:57.728345   876 executor.cc:98] Create Variable cross_entropy_0.tmp_0 locally, which pointer is 0x47b1da0
I0103 10:38:57.728353   876 scope.cc:43] Create variable fc_2.tmp_0
I0103 10:38:57.728361   876 executor.cc:98] Create Variable fc_2.tmp_0 locally, which pointer is 0x47b1ea0
I0103 10:38:57.728372   876 scope.cc:43] Create variable fc_2.tmp_2@GRAD
I0103 10:38:57.728382   876 executor.cc:98] Create Variable fc_2.tmp_2@GRAD locally, which pointer is 0x47b1fa0
I0103 10:38:57.728391   876 scope.cc:43] Create variable accuracy_0_1_correct
I0103 10:38:57.728399   876 executor.cc:93] Create Variable accuracy_0_1_correct global, which pointer is 0x47b20a0
I0103 10:38:57.728408   876 scope.cc:43] Create variable mean_0.tmp_0@GRAD
I0103 10:38:57.728418   876 executor.cc:98] Create Variable mean_0.tmp_0@GRAD locally, which pointer is 0x47b21a0
I0103 10:38:57.728426   876 scope.cc:43] Create variable learning_rate_5
I0103 10:38:57.728435   876 executor.cc:93] Create Variable learning_rate_5 global, which pointer is 0x47b22a0
I0103 10:38:57.728443   876 scope.cc:43] Create variable cast_1.tmp_0
I0103 10:38:57.728451   876 executor.cc:98] Create Variable cast_1.tmp_0 locally, which pointer is 0x47b23a0
I0103 10:38:57.728459   876 scope.cc:43] Create variable learning_rate_4
I0103 10:38:57.728467   876 executor.cc:93] Create Variable learning_rate_4 global, which pointer is 0x47b24a0
I0103 10:38:57.728478   876 scope.cc:43] Create variable x
I0103 10:38:57.728487   876 executor.cc:98] Create Variable x locally, which pointer is 0x47b25a0
I0103 10:38:57.728497   876 scope.cc:43] Create variable velocity_4
I0103 10:38:57.728504   876 executor.cc:93] Create Variable velocity_4 global, which pointer is 0x47b26a0
I0103 10:38:57.728525   876 executor.cc:114] Op(feed), inputs:{X[feed]}, outputs:{Out[x]}.
I0103 10:38:57.728540   876 feed_op.cc:44] Feed Var feed's 0 column to var x
I0103 10:38:57.728570   876 executor.cc:114] Op(mul), inputs:{X[x], Y[fc_0.w_0]}, outputs:{Out[fc_0.tmp_0]}.
I0103 10:38:57.728598   876 mul_op.cc:36] mul operator x.shape=1, 784 y.shape=784, 128 x_num_col_dims=1 y_num_col_dims=1
I0103 10:38:57.728878   876 executor.cc:114] Op(elementwise_add), inputs:{X[fc_0.tmp_0], Y[fc_0.b_0]}, outputs:{Out[fc_0.tmp_1]}.
I0103 10:38:57.728924   876 executor.cc:114] Op(relu), inputs:{X[fc_0.tmp_1]}, outputs:{Out[fc_0.tmp_2]}.
I0103 10:38:57.728962   876 executor.cc:114] Op(mul), inputs:{X[fc_0.tmp_2], Y[fc_1.w_0]}, outputs:{Out[fc_1.tmp_0]}.
I0103 10:38:57.728979   876 mul_op.cc:36] mul operator x.shape=1, 128 y.shape=128, 64 x_num_col_dims=1 y_num_col_dims=1
I0103 10:38:57.729017   876 executor.cc:114] Op(elementwise_add), inputs:{X[fc_1.tmp_0], Y[fc_1.b_0]}, outputs:{Out[fc_1.tmp_1]}.
I0103 10:38:57.729046   876 executor.cc:114] Op(relu), inputs:{X[fc_1.tmp_1]}, outputs:{Out[fc_1.tmp_2]}.
I0103 10:38:57.729073   876 executor.cc:114] Op(mul), inputs:{X[fc_1.tmp_2], Y[fc_2.w_0]}, outputs:{Out[fc_2.tmp_0]}.
I0103 10:38:57.729101   876 mul_op.cc:36] mul operator x.shape=1, 64 y.shape=64, 10 x_num_col_dims=1 y_num_col_dims=1
I0103 10:38:57.729131   876 executor.cc:114] Op(elementwise_add), inputs:{X[fc_2.tmp_0], Y[fc_2.b_0]}, outputs:{Out[fc_2.tmp_1]}.
I0103 10:38:57.729159   876 executor.cc:114] Op(softmax), inputs:{X[fc_2.tmp_1]}, outputs:{Out[fc_2.tmp_2]}.
I0103 10:38:57.729228   876 executor.cc:114] Op(fetch), inputs:{X[fc_2.tmp_2]}, outputs:{Out[fetch]}.
I0103 10:38:57.729252   876 fetch_op.cc:62] Fetch variable fc_2.tmp_2 to fetch
I0103 10:38:57.729266   876 scope.cc:28] Destroy variable cast_1.tmp_0
I0103 10:38:57.729275   876 scope.cc:28] Destroy variable mean_0.tmp_0@GRAD
I0103 10:38:57.729282   876 scope.cc:28] Destroy variable fc_2.tmp_2@GRAD
I0103 10:38:57.729292   876 scope.cc:28] Destroy variable x
I0103 10:38:57.729303   876 scope.cc:28] Destroy variable fc_1.tmp_1
I0103 10:38:57.729315   876 scope.cc:28] Destroy variable fc_2.tmp_0@GRAD
I0103 10:38:57.729322   876 scope.cc:28] Destroy variable cast_0.tmp_0
I0103 10:38:57.729331   876 scope.cc:28] Destroy variable accuracy_1.tmp_1
I0103 10:38:57.729339   876 scope.cc:28] Destroy variable fc_0.w_0@GRAD
I0103 10:38:57.729347   876 scope.cc:28] Destroy variable fc_0.tmp_2
I0103 10:38:57.729357   876 scope.cc:28] Destroy variable clip_0.tmp_0
I0103 10:38:57.729364   876 scope.cc:28] Destroy variable fc_1.tmp_0@GRAD
I0103 10:38:57.729372   876 scope.cc:28] Destroy variable _generated_var_2
I0103 10:38:57.729382   876 scope.cc:28] Destroy variable accuracy_1.tmp_2
I0103 10:38:57.729389   876 scope.cc:28] Destroy variable accuracy_0.tmp_0
I0103 10:38:57.729398   876 scope.cc:28] Destroy variable fc_0.tmp_2@GRAD
I0103 10:38:57.729408   876 scope.cc:28] Destroy variable _generated_var_1
I0103 10:38:57.729414   876 scope.cc:28] Destroy variable fc_2.tmp_1@GRAD
I0103 10:38:57.729423   876 scope.cc:28] Destroy variable fc_2.b_0@GRAD
I0103 10:38:57.729432   876 scope.cc:28] Destroy variable accuracy_0.tmp_1
I0103 10:38:57.729440   876 scope.cc:28] Destroy variable fc_1.tmp_2@GRAD
I0103 10:38:57.729449   876 scope.cc:28] Destroy variable accuracy_1.tmp_0
I0103 10:38:57.729456   876 scope.cc:28] Destroy variable fc_2.w_0@GRAD
I0103 10:38:57.729465   876 scope.cc:28] Destroy variable fc_2.tmp_0
I0103 10:38:57.729475   876 scope.cc:28] Destroy variable cross_entropy_0.tmp_0@GRAD
I0103 10:38:57.729482   876 scope.cc:28] Destroy variable fc_0.tmp_1
I0103 10:38:57.729492   876 scope.cc:28] Destroy variable fc_0.tmp_1@GRAD
I0103 10:38:57.729501   876 scope.cc:28] Destroy variable fc_1.tmp_2
I0103 10:38:57.729511   876 scope.cc:28] Destroy variable fc_1.w_0@GRAD
I0103 10:38:57.729519   876 scope.cc:28] Destroy variable fc_0.tmp_0
I0103 10:38:57.729528   876 scope.cc:28] Destroy variable _generated_var_0
I0103 10:38:57.729539   876 scope.cc:28] Destroy variable fc_1.tmp_1@GRAD
I0103 10:38:57.729548   876 scope.cc:28] Destroy variable cross_entropy_0.tmp_0
I0103 10:38:57.729557   876 scope.cc:28] Destroy variable fc_2.tmp_2
I0103 10:38:57.729565   876 scope.cc:28] Destroy variable y
I0103 10:38:57.729573   876 scope.cc:28] Destroy variable fc_1.tmp_0
I0103 10:38:57.729583   876 scope.cc:28] Destroy variable fc_1.b_0@GRAD
I0103 10:38:57.729593   876 scope.cc:28] Destroy variable fc_0.b_0@GRAD
I0103 10:38:57.729600   876 scope.cc:28] Destroy variable fc_0.tmp_0@GRAD
I0103 10:38:57.729609   876 scope.cc:28] Destroy variable fc_2.tmp_1
I0103 10:38:57.729619   876 scope.cc:28] Destroy variable mean_0.tmp_0
I0103 10:38:57.729634   876 feed_fetch_method.h:51] Fetch fetch with index 0 shape= 1, 10
I0103 10:38:57.729645   876 scope.cc:28] Destroy variable learning_rate_5
I0103 10:38:57.729655   876 scope.cc:28] Destroy variable accuracy_0_1_correct
I0103 10:38:57.729662   876 scope.cc:28] Destroy variable learning_rate_1
I0103 10:38:57.729670   876 scope.cc:28] Destroy variable learning_rate_2
I0103 10:38:57.729678   876 scope.cc:28] Destroy variable velocity_0
I0103 10:38:57.729686   876 scope.cc:28] Destroy variable learning_rate_3
I0103 10:38:57.729693   876 scope.cc:28] Destroy variable velocity_1
I0103 10:38:57.729701   876 scope.cc:28] Destroy variable velocity_2
I0103 10:38:57.729708   876 scope.cc:28] Destroy variable fc_0.b_0
I0103 10:38:57.729717   876 scope.cc:28] Destroy variable velocity_3
I0103 10:38:57.729727   876 scope.cc:28] Destroy variable velocity_5
I0103 10:38:57.729735   876 scope.cc:28] Destroy variable fc_1.w_0
I0103 10:38:57.729744   876 scope.cc:28] Destroy variable fc_0.w_0
I0103 10:38:57.729753   876 scope.cc:28] Destroy variable fc_2.b_0
I0103 10:38:57.729763   876 scope.cc:28] Destroy variable fc_2.w_0
I0103 10:38:57.729771   876 scope.cc:28] Destroy variable fc_1.b_0
I0103 10:38:57.729780   876 scope.cc:28] Destroy variable accuracy_0_0_total
I0103 10:38:57.729789   876 scope.cc:28] Destroy variable feed
I0103 10:38:57.729799   876 scope.cc:28] Destroy variable learning_rate_4
I0103 10:38:57.729806   876 scope.cc:28] Destroy variable fetch
I0103 10:38:57.729815   876 scope.cc:28] Destroy variable velocity_4
I0103 10:38:57.729822   876 scope.cc:28] Destroy variable learning_rate_0
dims_i: 1 10
result: 0.111568 0.133553 0.0713831 0.144068 0.12181 0.0988158 0.0724341 0.0937385 0.0917389 0.0608897

@Xreki Xreki force-pushed the core_inference_example branch from 0c588de to c9e09e9 Compare December 28, 2017 10:01
@Xreki Xreki changed the title [WIP] Add a simple C++ inference example for fluid Add a simple C++ inference example for fluid Dec 28, 2017
@Xreki Xreki force-pushed the core_inference_example branch from c9e09e9 to 332fa97 Compare December 28, 2017 11:12

namespace paddle {

void InferenceDesc::LoadInferenceModel(std::string& dirname) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Desc means description. It should be used only for the description of the internal data structure, like OpDesc describes operator.

It should not have Execute, Load, etc.

Maybe Inference or InferenceEngine is a better name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const T&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I know. The class's name will be designed carefully. I just write a simple example to understand the inferring process of fluid. All the codes will be rewritten in next PRs.

void InferenceDesc::LoadInferenceModel(std::string& dirname) {
#ifdef PADDLE_USE_PTOOLS
std::string model_filename = dirname + "/__model__";
LOG(INFO) << "Using PicklingTools, loading model from " << model_filename;
Copy link
Collaborator

@reyoung reyoung Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not support pickle in C++.

Maybe we should have a protobuf data structure for inference? I am not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with it and can't agree more.

public:
InferenceDesc() : program_(nullptr), load_program_(nullptr) {}
~InferenceDesc() {
if (!program_) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just delete program_; is OK.

In C++, delete ptr; is valid when ptr is nullptr, and will do nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

bool InferenceDesc::IsParameter(framework::VarDesc* var) {
if (var->Persistable()) {
Copy link
Collaborator

@reyoung reyoung Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very tricky. Not all persistable variable is a parameter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is better to have a protobuf structure for inference.

Copy link
Contributor Author

@Xreki Xreki Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In the inference process, we only need to load parameters from memory. This is right when no other persistable variables except parameters are used in the inference network.

As shown in the output of the example, there are many unused variables, we also need to optimize the inference program.

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent works!

However, maybe we can make a long-term plan for an inference SDK?

@Xreki Xreki force-pushed the core_inference_example branch from 332fa97 to bc1a542 Compare December 28, 2017 11:56
@Xreki
Copy link
Contributor Author

Xreki commented Dec 28, 2017

@reyoung Thanks for your review.
We are working on developing the inference library for fluid and will make a plan soon. This is the first PR for us to better understand how fluid works.

@Xreki Xreki force-pushed the core_inference_example branch from bc1a542 to 9b3f2c3 Compare December 28, 2017 12:19

int main(int argc, char* argv[]) {
std::string dirname =
"/home/work/liuyiqun/PaddlePaddle/Paddle/paddle/inference/"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use absolute/personal path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can upload this model, and download it by verifying MD5.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use absolute/personal path

Done.

Maybe you can upload this model, and download it by verifying MD5.

I think the current version of model is not stable and is not suitable to upload for testing.

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unitest for inference example?


int main(int argc, char* argv[]) {
std::string dirname =
"/home/work/liuyiqun/PaddlePaddle/Paddle/paddle/inference/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can upload this model, and download it by verifying MD5.

if (IsParameter(var)) {
LOG(INFO) << "parameter's name: " << var->Name();

// framework::VarDesc new_var = *var;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Xreki Xreki force-pushed the core_inference_example branch from 08749e2 to 5b3cf4e Compare January 3, 2018 09:33
@Xreki
Copy link
Contributor Author

Xreki commented Jan 3, 2018

Can we add a unitest for inference example?

I think after removing the dependency of Pickle, it will be easy to add this example as an unittest.

@Xreki Xreki added the 预测 原名Inference,包含Capi预测问题等 label Jan 5, 2018
Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge it first for developing faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
预测 原名Inference,包含Capi预测问题等
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants