[Unity6 × Sentis 2.1.2] ToReadOnlyArray() / DownloadToArray() 使用時に発生するエラーについて
解決したいこと
Unity6でSentis 2.1.2を利用して、感情を認識して遊べるゲームを開発しています。
開発の過程で、ToReadOnlyArray()
メソッドを使ったコードを実装したところ、コンパイルエラーが発生しました。
エラーを解消するために、インターネットの記事を参考にしてDownloadToArray()
やDownloadToNativeArray()
に書き換えてみましたが、それでも同じようなエラーが発生してしまいました。
この問題について、Google検索やChatGPTなどの生成AIにも質問しましたが、具体的な解決策を見つけることができませんでした。
そのため、こちらに相談させていただきました。
発生している問題・エラー
Assets/Script/InitCam.cs(110,18): error CS1061: 'Tensor' does not contain a definition for 'DownloadToArray' and no accessible extension method 'DownloadToArray' accepting a first argument of type 'Tensor' could be found (are you missing a using directive or an assembly reference?)
Assets/Script/InitCam.cs(112,39): error CS1061: 'Tensor' does not contain a definition for 'DownloadToArray' and no accessible extension method 'DownloadToArray' accepting a first argument of type 'Tensor' could be found (are you missing a using directive or an assembly reference?)
該当するソースコード
void Update()
{
if (!isCameraInit)
return;
Graphics.Blit(webcamTexture, preRenderTexture);
RenderTexture.active = preRenderTexture;
preRenderTexture2D.ReadPixels(new Rect(0, 0, preRenderTexture.width, preRenderTexture.height), 0, 0);
preRenderTexture2D.Apply();
RenderTexture.active = null;
var inputTensor = TextureConverter.ToTensor(preRenderTexture2D);
worker.Schedule(inputTensor);
Tensor outputTensor = worker.PeekOutput() as Tensor<float>;
if (outputTensor != null)
{
int maxIndex = outputTensor
.DownloadToNativeArray() // ここ(110行目)
.ToList()
.IndexOf(outputTensor.DownloadToArray().Max()); // ここ(112行目)
predictedEmotion = emotionLabels[maxIndex];
Debug.Log($"Predicted Emotion: {predictedEmotion}");
}
outputTensor?.Dispose();
}
0 likes