Skip to content

Commit

Permalink
Merge pull request #376 from asus4/fix-signature-runner
Browse files Browse the repository at this point in the history
Fix signature runner crash
  • Loading branch information
asus4 authored Oct 17, 2024
2 parents dd7577d + bd29e2e commit 8a6f71f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Assets/Samples/VideoClassification/VideoClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public VideoClassification(Options options)
try
{
runner = new SignatureRunner(SIGNATURE_KEY, FileUtil.LoadFile(options.modelPath), interpreterOptions);
runner.AllocateSignatureTensors();
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public static void LogIOInfo(this SignatureRunner runner)
}
sb.AppendLine();

int signatureInputCount = runner.GetSignatureInputCount();
int signatureInputCount = (int)runner.GetSignatureInputCount();
for (int i = 0; i < signatureInputCount; i++)
{
string name = runner.GetSignatureInputName(i);
sb.AppendLine($"Signature Input [{i}]: {name},\t info: {runner.GetSignatureInputInfo(name)}");
}
sb.AppendLine();

int signatureOutputCount = runner.GetSignatureOutputCount();
int signatureOutputCount = (int)runner.GetSignatureOutputCount();
for (int i = 0; i < signatureOutputCount; i++)
{
string name = runner.GetSignatureOutputName(i);
Expand Down
10 changes: 5 additions & 5 deletions Packages/com.github.asus4.tflite/Runtime/SignatureRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public string GetSignatureKey(int index)
return ToString(TfLiteInterpreterGetSignatureKey(InterpreterPointer, index));
}

public int GetSignatureInputCount()
public ulong GetSignatureInputCount()
{
return TfLiteSignatureRunnerGetInputCount(runner);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public override void Invoke()
ThrowIfError(TfLiteSignatureRunnerInvoke(runner));
}

public int GetSignatureOutputCount()
public ulong GetSignatureOutputCount()
{
return TfLiteSignatureRunnerGetOutputCount(runner);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ private void Initialize(string signatureName)

private Dictionary<string, int> CreateMap(bool isInput)
{
int signatureCount = isInput ? GetSignatureInputCount() : GetSignatureOutputCount();
int signatureCount = (int)(isInput ? GetSignatureInputCount() : GetSignatureOutputCount());
int tensorCount = isInput ? GetInputTensorCount() : GetOutputTensorCount();
Assert.AreEqual(signatureCount, tensorCount);

Expand Down Expand Up @@ -270,7 +270,7 @@ private Dictionary<string, int> CreateMap(bool isInput)
private static extern TfLiteSignatureRunner TfLiteInterpreterGetSignatureRunner(TfLiteInterpreter interpreter, string signature_name);

[DllImport(TensorFlowLibrary)]
private static extern int TfLiteSignatureRunnerGetInputCount(TfLiteSignatureRunner signature_runner);
private static extern ulong TfLiteSignatureRunnerGetInputCount(TfLiteSignatureRunner signature_runner);

[DllImport(TensorFlowLibrary)]
private static extern IntPtr TfLiteSignatureRunnerGetInputName(TfLiteSignatureRunner signature_runner, int input_index);
Expand All @@ -290,7 +290,7 @@ private static extern Status TfLiteSignatureRunnerResizeInputTensor(
private static extern Status TfLiteSignatureRunnerInvoke(TfLiteSignatureRunner signature_runner);

[DllImport(TensorFlowLibrary)]
private static extern int TfLiteSignatureRunnerGetOutputCount(TfLiteSignatureRunner signature_runner);
private static extern ulong TfLiteSignatureRunnerGetOutputCount(TfLiteSignatureRunner signature_runner);

[DllImport(TensorFlowLibrary)]
private static extern IntPtr TfLiteSignatureRunnerGetOutputName(TfLiteSignatureRunner signature_runner, int output_index);
Expand Down

0 comments on commit 8a6f71f

Please sign in to comment.