Search Unity

Question model with 1D tensor as an input generates wrong result

Discussion in 'Barracuda' started by chris0956231181, Apr 7, 2022.

  1. chris0956231181

    chris0956231181

    Joined:
    Aug 10, 2019
    Posts:
    4
    I am trying to use a model from Pytorch in Unity. I successfully converted it to onnx (the onnx results are almost the same as pytorch model's when I test it in python).

    This is how I define the onnx model during the export:

    Code (Boo):
    1.  
    2. dummy_input = torch.randn(1,636).to(device)
    3. torch.onnx.export(model,                     # model being run
    4.                  dummy_input,                # model input (or a tuple for multiple inputs)
    5.                   "./onnx/model_A.onnx",     # where to save the model (can be a file or file-like object)
    6.                   export_params=True,        # store the trained parameter weights inside the model file
    7.                   opset_version=10,          # the ONNX version to export the model to
    8.                   do_constant_folding=True,  # whether to execute constant folding for optimization
    9.                   input_names = ['input'],   # the model's input names
    10.                   output_names = ['output'], # the model's output names
    11.                   dynamic_axes={'input' : {0 : 'batch_size', 1: 'vertices'},    # variable length axes
    12.                                 'output' : {0 : 'batch_size',1: 'blendshape_values'}})
    13.  
    this is how I define input tensor inside unity:

    Code (CSharp):
    1.  
    2. var inputTensorA = new Tensor(1, 636, input); # i tried this
    3. var inputTensorB = new Tensor( new int[]{1,1,636,1,1,1,1,1}, input,"",true); # i also tried this
    4.  
    I tried putting the 636 in different dimensions as well. I tried all the combinations that came to my mind, however the model's output is always wrong. The model itself is very simple - just a few fully connected layers. What am I doing wrong? How to debug it?
     
  2. Interwinner

    Interwinner

    Joined:
    Jan 4, 2023
    Posts:
    3
    please try rounding in python.
    unity can not calculate precisely float 64.
     
  3. Bill_Cullen

    Bill_Cullen

    Unity Technologies

    Joined:
    Sep 2, 2021
    Posts:
    6
    Hey guys, I would like to invite you the new version of Barracuda, which is called Sentis, and is currently in a private beta. If you can DM me your email addresses, and please signup with the same emails on https://create.unity.com/ai-beta, then I am happy to invite you!

    In the meantime, here is the documentation