C++ TensorRT batch inference gives weird results










1















Good day everyone!



I have a problem performing batch inference in TensorRT. When the batch size is 1 it works like a charm, but when I change it to any other number it gives out plain garbage.



Step by step, I downloaded TensorRT (5.0) and installed it on my Ubuntu 18.04 laptop with GTX755M. I then built the samples that went with it and tested it on sampleMNIST sample and it worked like a charm. I then proceeded to change every occurrence of mParams.batchSize to 10. Of course I also changed the size of allocated memory and modified result printing along. But after I recompiled the sample I got completely weird results - the output says 80% 7 20% 1 for every given input:



grim@shigoto:~/tensorrt/bin$ ./sample_mnist
Building and running a GPU inference engine for MNIST

Input:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@.*@@@@@@@@@@
@@@@@@@@@@@@@@@@.=@@@@@@@@@@
@@@@@@@@@@@@+@@@.=@@@@@@@@@@
@@@@@@@@@@@% #@@.=@@@@@@@@@@
@@@@@@@@@@@% #@@.=@@@@@@@@@@
@@@@@@@@@@@+ *@@:-@@@@@@@@@@
@@@@@@@@@@@= *@@= @@@@@@@@@@
@@@@@@@@@@@. #@@= @@@@@@@@@@
@@@@@@@@@@= =++.-@@@@@@@@@@
@@@@@@@@@@ =@@@@@@@@@@
@@@@@@@@@@ :*## =@@@@@@@@@@
@@@@@@@@@@:*@@@% =@@@@@@@@@@
@@@@@@@@@@@@@@@% =@@@@@@@@@@
@@@@@@@@@@@@@@@# =@@@@@@@@@@
@@@@@@@@@@@@@@@# =@@@@@@@@@@
@@@@@@@@@@@@@@@* *@@@@@@@@@@
@@@@@@@@@@@@@@@= #@@@@@@@@@@
@@@@@@@@@@@@@@@= #@@@@@@@@@@
@@@@@@@@@@@@@@@=.@@@@@@@@@@@
@@@@@@@@@@@@@@@++@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Output:

0:
1: ********
2:
3:
4:
5:
6:
7: **
8:
9:


This output repeats 10 times. I've tried this with different networks but results were similar, most of networks give 1 correct output and plain garbage the other 9 times. The complete sample can be found here. I've tried googling documentation but I can't understand what I'm doing wrong. Could you please tell me what am I doing wrong or how to perform batch inference in TensorRT?










share|improve this question


























    1















    Good day everyone!



    I have a problem performing batch inference in TensorRT. When the batch size is 1 it works like a charm, but when I change it to any other number it gives out plain garbage.



    Step by step, I downloaded TensorRT (5.0) and installed it on my Ubuntu 18.04 laptop with GTX755M. I then built the samples that went with it and tested it on sampleMNIST sample and it worked like a charm. I then proceeded to change every occurrence of mParams.batchSize to 10. Of course I also changed the size of allocated memory and modified result printing along. But after I recompiled the sample I got completely weird results - the output says 80% 7 20% 1 for every given input:



    grim@shigoto:~/tensorrt/bin$ ./sample_mnist
    Building and running a GPU inference engine for MNIST

    Input:

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@.*@@@@@@@@@@
    @@@@@@@@@@@@@@@@.=@@@@@@@@@@
    @@@@@@@@@@@@+@@@.=@@@@@@@@@@
    @@@@@@@@@@@% #@@.=@@@@@@@@@@
    @@@@@@@@@@@% #@@.=@@@@@@@@@@
    @@@@@@@@@@@+ *@@:-@@@@@@@@@@
    @@@@@@@@@@@= *@@= @@@@@@@@@@
    @@@@@@@@@@@. #@@= @@@@@@@@@@
    @@@@@@@@@@= =++.-@@@@@@@@@@
    @@@@@@@@@@ =@@@@@@@@@@
    @@@@@@@@@@ :*## =@@@@@@@@@@
    @@@@@@@@@@:*@@@% =@@@@@@@@@@
    @@@@@@@@@@@@@@@% =@@@@@@@@@@
    @@@@@@@@@@@@@@@# =@@@@@@@@@@
    @@@@@@@@@@@@@@@# =@@@@@@@@@@
    @@@@@@@@@@@@@@@* *@@@@@@@@@@
    @@@@@@@@@@@@@@@= #@@@@@@@@@@
    @@@@@@@@@@@@@@@= #@@@@@@@@@@
    @@@@@@@@@@@@@@@=.@@@@@@@@@@@
    @@@@@@@@@@@@@@@++@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@

    Output:

    0:
    1: ********
    2:
    3:
    4:
    5:
    6:
    7: **
    8:
    9:


    This output repeats 10 times. I've tried this with different networks but results were similar, most of networks give 1 correct output and plain garbage the other 9 times. The complete sample can be found here. I've tried googling documentation but I can't understand what I'm doing wrong. Could you please tell me what am I doing wrong or how to perform batch inference in TensorRT?










    share|improve this question
























      1












      1








      1


      1






      Good day everyone!



      I have a problem performing batch inference in TensorRT. When the batch size is 1 it works like a charm, but when I change it to any other number it gives out plain garbage.



      Step by step, I downloaded TensorRT (5.0) and installed it on my Ubuntu 18.04 laptop with GTX755M. I then built the samples that went with it and tested it on sampleMNIST sample and it worked like a charm. I then proceeded to change every occurrence of mParams.batchSize to 10. Of course I also changed the size of allocated memory and modified result printing along. But after I recompiled the sample I got completely weird results - the output says 80% 7 20% 1 for every given input:



      grim@shigoto:~/tensorrt/bin$ ./sample_mnist
      Building and running a GPU inference engine for MNIST

      Input:

      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@.*@@@@@@@@@@
      @@@@@@@@@@@@@@@@.=@@@@@@@@@@
      @@@@@@@@@@@@+@@@.=@@@@@@@@@@
      @@@@@@@@@@@% #@@.=@@@@@@@@@@
      @@@@@@@@@@@% #@@.=@@@@@@@@@@
      @@@@@@@@@@@+ *@@:-@@@@@@@@@@
      @@@@@@@@@@@= *@@= @@@@@@@@@@
      @@@@@@@@@@@. #@@= @@@@@@@@@@
      @@@@@@@@@@= =++.-@@@@@@@@@@
      @@@@@@@@@@ =@@@@@@@@@@
      @@@@@@@@@@ :*## =@@@@@@@@@@
      @@@@@@@@@@:*@@@% =@@@@@@@@@@
      @@@@@@@@@@@@@@@% =@@@@@@@@@@
      @@@@@@@@@@@@@@@# =@@@@@@@@@@
      @@@@@@@@@@@@@@@# =@@@@@@@@@@
      @@@@@@@@@@@@@@@* *@@@@@@@@@@
      @@@@@@@@@@@@@@@= #@@@@@@@@@@
      @@@@@@@@@@@@@@@= #@@@@@@@@@@
      @@@@@@@@@@@@@@@=.@@@@@@@@@@@
      @@@@@@@@@@@@@@@++@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@

      Output:

      0:
      1: ********
      2:
      3:
      4:
      5:
      6:
      7: **
      8:
      9:


      This output repeats 10 times. I've tried this with different networks but results were similar, most of networks give 1 correct output and plain garbage the other 9 times. The complete sample can be found here. I've tried googling documentation but I can't understand what I'm doing wrong. Could you please tell me what am I doing wrong or how to perform batch inference in TensorRT?










      share|improve this question














      Good day everyone!



      I have a problem performing batch inference in TensorRT. When the batch size is 1 it works like a charm, but when I change it to any other number it gives out plain garbage.



      Step by step, I downloaded TensorRT (5.0) and installed it on my Ubuntu 18.04 laptop with GTX755M. I then built the samples that went with it and tested it on sampleMNIST sample and it worked like a charm. I then proceeded to change every occurrence of mParams.batchSize to 10. Of course I also changed the size of allocated memory and modified result printing along. But after I recompiled the sample I got completely weird results - the output says 80% 7 20% 1 for every given input:



      grim@shigoto:~/tensorrt/bin$ ./sample_mnist
      Building and running a GPU inference engine for MNIST

      Input:

      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@.*@@@@@@@@@@
      @@@@@@@@@@@@@@@@.=@@@@@@@@@@
      @@@@@@@@@@@@+@@@.=@@@@@@@@@@
      @@@@@@@@@@@% #@@.=@@@@@@@@@@
      @@@@@@@@@@@% #@@.=@@@@@@@@@@
      @@@@@@@@@@@+ *@@:-@@@@@@@@@@
      @@@@@@@@@@@= *@@= @@@@@@@@@@
      @@@@@@@@@@@. #@@= @@@@@@@@@@
      @@@@@@@@@@= =++.-@@@@@@@@@@
      @@@@@@@@@@ =@@@@@@@@@@
      @@@@@@@@@@ :*## =@@@@@@@@@@
      @@@@@@@@@@:*@@@% =@@@@@@@@@@
      @@@@@@@@@@@@@@@% =@@@@@@@@@@
      @@@@@@@@@@@@@@@# =@@@@@@@@@@
      @@@@@@@@@@@@@@@# =@@@@@@@@@@
      @@@@@@@@@@@@@@@* *@@@@@@@@@@
      @@@@@@@@@@@@@@@= #@@@@@@@@@@
      @@@@@@@@@@@@@@@= #@@@@@@@@@@
      @@@@@@@@@@@@@@@=.@@@@@@@@@@@
      @@@@@@@@@@@@@@@++@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@

      Output:

      0:
      1: ********
      2:
      3:
      4:
      5:
      6:
      7: **
      8:
      9:


      This output repeats 10 times. I've tried this with different networks but results were similar, most of networks give 1 correct output and plain garbage the other 9 times. The complete sample can be found here. I've tried googling documentation but I can't understand what I'm doing wrong. Could you please tell me what am I doing wrong or how to perform batch inference in TensorRT?







      c++ machine-learning inference tensorrt






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 10:13









      Grim MapleGrim Maple

      1116




      1116






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Did you also modified the mnist.prototxt?



          Especially this part:



          input: "data"
          input_shape
          dim: 1
          dim: 1
          dim: 28
          dim: 28



          I think that should be:



          input: "data"
          input_shape
          dim: 10
          dim: 1
          dim: 28
          dim: 28






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297707%2fc-tensorrt-batch-inference-gives-weird-results%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Did you also modified the mnist.prototxt?



            Especially this part:



            input: "data"
            input_shape
            dim: 1
            dim: 1
            dim: 28
            dim: 28



            I think that should be:



            input: "data"
            input_shape
            dim: 10
            dim: 1
            dim: 28
            dim: 28






            share|improve this answer



























              0














              Did you also modified the mnist.prototxt?



              Especially this part:



              input: "data"
              input_shape
              dim: 1
              dim: 1
              dim: 28
              dim: 28



              I think that should be:



              input: "data"
              input_shape
              dim: 10
              dim: 1
              dim: 28
              dim: 28






              share|improve this answer

























                0












                0








                0







                Did you also modified the mnist.prototxt?



                Especially this part:



                input: "data"
                input_shape
                dim: 1
                dim: 1
                dim: 28
                dim: 28



                I think that should be:



                input: "data"
                input_shape
                dim: 10
                dim: 1
                dim: 28
                dim: 28






                share|improve this answer













                Did you also modified the mnist.prototxt?



                Especially this part:



                input: "data"
                input_shape
                dim: 1
                dim: 1
                dim: 28
                dim: 28



                I think that should be:



                input: "data"
                input_shape
                dim: 10
                dim: 1
                dim: 28
                dim: 28







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 13:27









                bpinayabpinaya

                14616




                14616





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297707%2fc-tensorrt-batch-inference-gives-weird-results%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3