Unity-Technologies / barracuda-release

Other
564 stars 76 forks source link

Question about how to use lstm in barracuda #310

Closed lsh235s closed 1 year ago

lsh235s commented 1 year ago

Hello, this is my first time using barrcuda.

I am moving a simple AI project to unity barrcuda and I have successfully completed image recognition. Next, I have a question because I am having difficulties applying a simpler lstm project to barrcuda.

The onnx model was converted and applied, but I couldn't get the same accuracy as python. I don't know if this is my mistake or a problem with barrcuda because there are also few example samples for lstm.

I will share from model creation to input method. Any help if I'm doing something wrong is appreciated.

print(x_valid[0].shape) print(y_valid[0].shape) hist = model.fit(x_train, y_train, batch_size = batch, epochs = epoch, verbose = 1, validation_data=(x_valid, y_valid)) model.evaluate(x_valid, y_valid, verbose = 1)


- unity input : shape (1,1,2,50)

float[,] jaggedArray = new float [50, 2]{{-0.3925894f, 0.28424934f},
{-0.37861034f, 0.28424934f}, ...... {-0.19908297f, -0.49931842f}, {-0.19908297f, -0.49931842f}};

Tensor inputTensorFrames = new Tensor(1,1,2,50);

  for(int i =0; i< jaggedArray.GetLength(0) ; i++){
      inputTensorFrames[0, 0, 0, i] = jaggedArray[i,0];
      inputTensorFrames[0, 0, 1, i] = jaggedArray[i,1];
  }

  worker.Execute(inputTensorFrames);


<img width="766" alt="스크린샷 2023-01-17 오후 4 03 28" src="https://user-images.githubusercontent.com/23042799/212832164-84212939-b753-4b88-8671-8acbf8588ed7.png">

[strokeA.onnx.zip](https://github.com/Unity-Technologies/barracuda-release/files/10432236/strokeA.onnx.zip)
lsh235s commented 1 year ago

This is due to the use of models trained by methods other than ML-agents.