Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to split the libtorch forward method's output?

How to split the libtorch forward method's output?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 522 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    donkey007
    wrote on last edited by donkey007
    #1

    hello, im new to this… i need help

    this is my c++ code

    // [0]Define the input tensor
    torch::Tensor veh_input2 = torch::tensor({
    {{5.006278301940284, 0.0786753188073942, 4.411626434845282, 0.09598564608132709, 4.52527292334112, 0.1367866935617143},
    {4.344146508992793, 0.034440922157513695, 4.472077232158242, 0.04202762418462361, 4.399348505369012, 0.05233431582289311},
    {5.800142409494782, 0.11272599320992382, 5.238293982154694, 0.15335229366842879, 4.269588880340237, 0.22455373622631702},
    {4.18455135464626, 0.03927927361417172, 4.165869740437117, 0.045566222570332576, 4.237983947536861, 0.055740630185644596}}
    });

    // [1]Run the model
    auto output = veh_model.forward({veh_input2});

    std::cout << "==========[1]============";
    std::cout << typeid(output).name() << std::endl;
    std::cout << output << std::endl;

    ============ program die here !! ===================

    // [2]Extract the outputs
    torch::Tensor mu_veh = output.toTuple()->elements()[0].toTensor();
    torch::Tensor sigma_veh = output.toTuple()->elements()[1].toTensor();

    @@@@@@@@@@@@ output @@@@@@@@@@@@@@@@

    and this is my output

    ==========[1]============
    typeid(output).name() ==> struct c10::IValue

    [(1,.,.) =
    5.3061 15.4691
    4.2534 15.5291
    5.9763 13.6928
    4.2134 15.4633
    [ CPUFloatType{1,4,2} ], (1,.,.) =
    2.5224 3.6053
    2.0312 4.4862
    2.6079 4.7206
    1.9234 4.2305
    [ CPUFloatType{1,4,2} ]]

    i want to access each value of tensor vector like “5.3061”
    why this c++ code didnt work?

    // [2]Extract the outputs
    torch::Tensor mu_veh = output.toTuple()->elements()[0].toTensor();
    torch::Tensor sigma_veh = output.toTuple()->elements()[1].toTensor();
    if you know, let me know thanks

    JonBJ 1 Reply Last reply
    0
    • D donkey007

      hello, im new to this… i need help

      this is my c++ code

      // [0]Define the input tensor
      torch::Tensor veh_input2 = torch::tensor({
      {{5.006278301940284, 0.0786753188073942, 4.411626434845282, 0.09598564608132709, 4.52527292334112, 0.1367866935617143},
      {4.344146508992793, 0.034440922157513695, 4.472077232158242, 0.04202762418462361, 4.399348505369012, 0.05233431582289311},
      {5.800142409494782, 0.11272599320992382, 5.238293982154694, 0.15335229366842879, 4.269588880340237, 0.22455373622631702},
      {4.18455135464626, 0.03927927361417172, 4.165869740437117, 0.045566222570332576, 4.237983947536861, 0.055740630185644596}}
      });

      // [1]Run the model
      auto output = veh_model.forward({veh_input2});

      std::cout << "==========[1]============";
      std::cout << typeid(output).name() << std::endl;
      std::cout << output << std::endl;

      ============ program die here !! ===================

      // [2]Extract the outputs
      torch::Tensor mu_veh = output.toTuple()->elements()[0].toTensor();
      torch::Tensor sigma_veh = output.toTuple()->elements()[1].toTensor();

      @@@@@@@@@@@@ output @@@@@@@@@@@@@@@@

      and this is my output

      ==========[1]============
      typeid(output).name() ==> struct c10::IValue

      [(1,.,.) =
      5.3061 15.4691
      4.2534 15.5291
      5.9763 13.6928
      4.2134 15.4633
      [ CPUFloatType{1,4,2} ], (1,.,.) =
      2.5224 3.6053
      2.0312 4.4862
      2.6079 4.7206
      1.9234 4.2305
      [ CPUFloatType{1,4,2} ]]

      i want to access each value of tensor vector like “5.3061”
      why this c++ code didnt work?

      // [2]Extract the outputs
      torch::Tensor mu_veh = output.toTuple()->elements()[0].toTensor();
      torch::Tensor sigma_veh = output.toTuple()->elements()[1].toTensor();
      if you know, let me know thanks

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @donkey007 said in How to split the libtorch forward method's output?:

      why this c++ code didnt work?

      What "doesn't work"? How should anyone in a Qt forum know what "the libtorch forward method's output" produces from

      auto output = veh_model.forward({veh_input2});
      std::cout << output << std::endl;
      

      ?

      D 1 Reply Last reply
      0
      • JonBJ JonB

        @donkey007 said in How to split the libtorch forward method's output?:

        why this c++ code didnt work?

        What "doesn't work"? How should anyone in a Qt forum know what "the libtorch forward method's output" produces from

        auto output = veh_model.forward({veh_input2});
        std::cout << output << std::endl;
        

        ?

        D Offline
        D Offline
        donkey007
        wrote on last edited by
        #3

        @JonB
        thanks for your answer!

        [(1,.,.) =
        5.3061 15.4691
        4.2534 15.5291
        5.9763 13.6928
        4.2134 15.4633
        [ CPUFloatType{1,4,2} ], (1,.,.) =
        2.5224 3.6053
        2.0312 4.4862
        2.6079 4.7206
        1.9234 4.2305
        [ CPUFloatType{1,4,2} ]]

        this is my " std::cout << output << std::endl; " output

        and i try slicing output like this

        torch::Tensor mu_veh = output.toTuple()->elements()[0].toTensor();
        torch::Tensor sigma_veh = output.toTuple()->elements()[1].toTensor();

        but this c++ code dosen't work...

        do you know why?

        JonBJ 1 Reply Last reply
        0
        • D donkey007

          @JonB
          thanks for your answer!

          [(1,.,.) =
          5.3061 15.4691
          4.2534 15.5291
          5.9763 13.6928
          4.2134 15.4633
          [ CPUFloatType{1,4,2} ], (1,.,.) =
          2.5224 3.6053
          2.0312 4.4862
          2.6079 4.7206
          1.9234 4.2305
          [ CPUFloatType{1,4,2} ]]

          this is my " std::cout << output << std::endl; " output

          and i try slicing output like this

          torch::Tensor mu_veh = output.toTuple()->elements()[0].toTensor();
          torch::Tensor sigma_veh = output.toTuple()->elements()[1].toTensor();

          but this c++ code dosen't work...

          do you know why?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @donkey007 No. Look at the torch::Tensor documentation.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved