Unity-Technologies / barracuda-release

Other
564 stars 76 forks source link

Assertion failure - YOLOv7tiny #303

Closed neilachr closed 1 year ago

neilachr commented 1 year ago

Hi,

I know that Barracuda doesn't officially support YOLOv7, but I've read of successful implementations of YOLOv5 and was told v7 is based on 5, so I thought I'd give it a shot.

I'm using Unity 2021.2.18f and Barracuda 3.0.0.

I'm not 100% sure I'm passing the image properly in my C# code as I was getting a Reshape error creating a new Tensor when passing an image as a Texture2D. I found other code in these issues that transforms the Texture2D into a passable shape srcdata, but now I get the following error:

AssertionException: Assertion failure. Value was False Expected: True UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <8b27195d2ee14da7b6fd1e5435850f80>:0) UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at <8b27195d2ee14da7b6fd1e5435850f80>:0) UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) (at <8b27195d2ee14da7b6fd1e5435850f80>:0) Unity.Barracuda.Tensor..ctor (Unity.Barracuda.TensorShape shape, System.Single[] srcData, System.String name) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/Core/Tensor.cs:1696) Unity.Barracuda.Tensor..ctor (System.Int32 n, System.Int32 h, System.Int32 w, System.Int32 c, System.Single[] srcData, System.String name) (at Library/PackageCache/com.unity.barracuda@3.0.0/Barracuda/Runtime/Core/Tensor.cs:1672) MLModelController.Start () (at Assets/Scripts/MLModelController.cs:34)

Here is my model class code:

[SerializeField]
public Texture2D inputImg;
[SerializeField]
private NNModel model;

private Model m_RuntimeModel;

private IWorker w_engine;

void Start()
{
    //bool verbose = false;
    m_RuntimeModel = ModelLoader.Load(model);

    w_engine = WorkerFactory.CreateWorker(WorkerFactory.Type.ComputePrecompiled, m_RuntimeModel);

    //Tensor input = new Tensor(inputImg, 3);
    Tensor tensor = new Tensor(inputImg, 3);
    ITensorData tensorData = tensor.data;

    TensorShape shape = tensor.shape;

    var downdata = tensorData.Download(shape);

    Tensor input = new Tensor(1, 640, 640, 3, downdata);
    //w_engine.Execute(input);

    // See Input & Output layers
    //foreach (var layer in m_RuntimeModel.layers)
    //Debug.Log(layer.name + " does " + layer.type);

    //Tensor output = w_engine.Execute(input).PeekOutput();
    //var output = w_engine.PeekOutput();
    //Tensor output = w_engine.PeekOutput();
    //Debug.Log(output.shape);
    //input.Dispose();
    //Debug.Log(output);

}

private void OnDestroy()
{
    w_engine?.Dispose();

yolov7-tiny.onnx.zip

}

// Update is called once per frame
void Update()
{

}

The error appears to be on instantiation of the Tensor as I've remmed out the worker Execute call.

I have also included my ONNX model.

Any help is greatly appreciated!

neilachr commented 1 year ago

I was able to get it working by making some very simple changes.

I had watched this video tutorial on YouTube and remembered he mentioned something about changing the parameters of the image that you were using as input. Once I did this, the error disappeared and I was able to Execute and log output.

I also was able to remove the shape srcData step.

Now I just need to figure out how to pass video from the AR camera.

Hope this helps someone else in the future.

RoachNier commented 1 year ago

Hi neiachr, So grateful for your exploration and share! I am also deploying yolo models with barracuda and I have made that on Android. The model I used is yolov5. However, The inference time on Android with Vulkan is too long, only 3fps. Have you successfully tried the inference speed on mobiles, like Android and IPad ? How about their speed? Thank you !

dragan07-07 commented 1 year ago

Did you manage to solve Yolov7 through barracuda? @neilachr

neilachr commented 1 year ago

No, we ended up using YOLOv4. It works, but is slow.

I recently found this repo that works with YOLOv5 [4] and our ML dev says that 7 is based on 5 so it should work.

I will update if we get it working!


Neil Christensen razorbackmedia.com [5]

On 2023-01-24 06:11, dragan07-07 wrote:

Did you manage to solve Yolov7 through barracuda? @neilachr [1]

-- Reply to this email directly, view it on GitHub [2], or unsubscribe [3]. You are receiving this because you were mentioned.Message ID: @.***>

Links:

[1] https://github.com/neilachr [2] https://github.com/Unity-Technologies/barracuda-release/issues/303#issuecomment-1401927198 [3] https://github.com/notifications/unsubscribe-auth/AACKN5MDKRL7LNOE5WU5ECTWT7IJJANCNFSM6AAAAAAREUJE6M [4] https://github.com/egor-ulianov/yolov5-unity [5] http://www.razorbackmedia.com

dragan07-07 commented 1 year ago

@neilachr Thanks. Please inform me if you manage it.

Aurimasp commented 1 year ago

Hey, we fixed the the issues for the provided Yolov7 model, it should be available in the next release.

kolaszko commented 1 year ago

Hi @Aurimasp , do you have information about a date of the next release?