Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Errors with Tensorflowsharp output = runner.Run() on Android

Discussion in 'AI & Navigation Previews' started by lindyrock, Apr 16, 2019.

  1. lindyrock

    lindyrock

    Joined:
    Apr 12, 2019
    Posts:
    6
    I've written a YOLO object detection model that tests out properly when inferenced in Python or with TFSharp in Visual Studio only. It's a Yolo v3, so i've added nodes to the graph to convert the anchor box output into boxes, scores, and classes, and these use some of the less basic operations like TFGraph.Tile, TFGraph.NonMaxSuppressionV2, TFGraph.Squeeze. All of these seem to be supported by libtensorflow and the TensorFlowSharp.dll.

    But when I run via an Android full build or in ARCore Instant Preview, I'm not getting usable results at all. I have errors and I have unexpected behavior.

    The errors are:
    upload_2019-4-16_10-41-37.png

    and the unexpected behavior is that, in Debug mode if I set a breakpoint after the runner.Run() command below, I cannot even access the GetValue() method. I receive "Cannot find a match for GetValue" in the interactive console.

    Code (CSharp):
    1. public TFTensor[] Detect(TFTensor imageTensor, TFTensor shape)
    2.         {
    3.             var runner = this.sess.GetRunner();
    4.             runner.AddInput(this.graph["input_1"][0], imageTensor).
    5.                 AddInput(this.graph["image_shape"][0], shape).Fetch(
    6.                 this.graph["boxes"][0],  //(bottom left (y, x), top right (y, x))
    7.                 this.graph["scores"][0],
    8.                 this.graph["classes"][0]);
    9.             TFTensor[] output = runner.Run();
    10.             var boxes = (float[,])output[0].GetValue(jagged: false);
    11.             var scores = (float[])output[1].GetValue(jagged: false);
    12.             var classes = (float[])output[2].GetValue(jagged: false);
    13.             Debug.Log(classes);
    14.  
    15.             return output;
    16.         }
    My path forward right now will be to just switch to Barracuda. But for time efficiency, it would be a big step forward if there's a simple fix to get this Tensorflowsharp version running on Android.

    * [Edit] the boxes, scores, and classes variables are just there in the code so I can inspect them. They actually don't successfully initialize past 'null'.