flutter-tflite icon indicating copy to clipboard operation
flutter-tflite copied to clipboard

The method 'UnmodifiableUint8ListView' isn't defined for the class 'Tensor'.

Open andresgd7 opened this issue 1 year ago • 5 comments

Im using tflite_flutter-0.10.4 but UnmodifiableUint8ListView was deprecated from typed_data some while ago: image

https://api.dart.dev/stable/2.13.4/dart-typed_data/dart-typed_data-library.html

When i try to run my code in android i get this:

../../../../AppData/Local/Pub/Cache/hosted/pub.dev/tflite_flutter-0.10.4/lib/src/tensor.dart:58:12: Error: The method 'UnmodifiableUint8ListView' isn't defined for the class 'Tensor'.
 - 'Tensor' is from 'package:tflite_flutter/src/tensor.dart' ('../../../../AppData/Local/Pub/Cache/hosted/pub.dev/tflite_flutter-0.10.4/lib/src/tensor.dart').
Try correcting the name to the name of an existing method, or defining a method named 'UnmodifiableUint8ListView'.
    return UnmodifiableUint8ListView(

any fix?

andresgd7 avatar Jul 23 '24 21:07 andresgd7

I have a temporary fix until it is fixed in the package. Change the package locally in your pub-cache. In the conflicting line, change the getter to this:

Uint8List get data {
    final data = cast<Uint8>(tfliteBinding.TfLiteTensorData(_tensor));
    return data.asTypedList(tfliteBinding.TfLiteTensorByteSize(_tensor)).asUnmodifiableView();
  }

That worked for me :)

ptgms avatar Jul 24 '24 22:07 ptgms

Thanks bro!

andresgd7 avatar Jul 25 '24 00:07 andresgd7

@ptgms I have shared your response on stack : https://stackoverflow.com/questions/78789213/the-method-unmodifiableuint8listview-isnt-defined-for-the-class-tensor/78842046#78842046

mehdigriche avatar Aug 07 '24 06:08 mehdigriche

Thank you very much! Do you know how to use tflite_flutter_helper with this version of tflite_flutter? It seems like this helper library might be deprecated, but it was very useful for image processing.

AntoineChauviere avatar Aug 23 '24 14:08 AntoineChauviere

Commit abac02b49b577be2853d4d6da64c7127fea7b6c8 seems to fix this, only a new version of this package is needed.

CaptainDario avatar Sep 11 '24 12:09 CaptainDario

The error was resolved in 0.11.0, so I guess this can be closed.

Guziq avatar Oct 24 '24 09:10 Guziq

Thanks everyone for the answers, this will be closed now.

andresgd7 avatar Oct 24 '24 16:10 andresgd7

I am unable to bump from 0.9.5 because of dependency conflicts. The temporary change did not work as is... throwing:

Error: The getter 'tfliteBinding' isn't defined for the class 'Tensor'.

I had to remove the tfliteBinding object to get it to work.

/// Underlying data buffer as bytes.
Uint8List get data {
  final data = cast<Uint8>(tfLiteTensorData(_tensor));
  return data.asTypedList(tfLiteTensorByteSize(_tensor)).asUnmodifiableView();
}

charlieforward9 avatar Nov 06 '24 02:11 charlieforward9