From 6a161a44280cec7dd0dac5e1ea58f786e0abc081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicola=CC=81s=20Lantean?= Date: Thu, 11 Jul 2024 14:00:59 -0300 Subject: [PATCH] fix: requested changes --- .fvmrc | 4 ++ .gitignore | 3 + CHANGELOG.md | 2 +- android/build.gradle | 4 +- android/settings.gradle | 2 +- android/src/main/AndroidManifest.xml | 2 +- .../TfliteFlutterProcessingPlugin.kt | 4 +- .../audio_classification/lib/classifier.dart | 6 +- example/audio_classification/lib/main.dart | 2 +- example/audio_classification/pubspec.lock | 2 +- example/audio_classification/pubspec.yaml | 8 +-- example/bert_question_answer/lib/bert_qa.dart | 4 +- example/bert_question_answer/pubspec.lock | 2 +- example/bert_question_answer/pubspec.yaml | 8 +-- .../android/settings.gradle | 3 +- .../classifier_test_helper.dart | 2 +- .../image_classification_test.dart | 2 +- .../image_classification/lib/classifier.dart | 2 +- .../lib/classifier_float.dart | 2 +- .../lib/classifier_quant.dart | 2 +- example/image_classification/lib/main.dart | 2 +- example/image_classification/pubspec.lock | 2 +- example/image_classification/pubspec.yaml | 6 +- .../lib/classifier.dart | 2 +- .../lib/classifier_task_lib.dart | 2 +- example/text_classification_task/pubspec.yaml | 9 +-- examples/image_classifier/lib/classifier.dart | 2 +- .../lib/classifier_float.dart | 2 +- .../lib/classifier_quant.dart | 2 +- examples/image_classifier/lib/main.dart | 2 +- .../SwiftTfliteFlutterProcessingPlugin.swift | 2 +- ios/Classes/TfliteFlutterProcessingPlugin.m | 6 +- ios/tflite_flutter_processing.podspec | 4 +- lib/src/audio/tensor_audio.dart | 40 +++++------- lib/src/common/ops/cast_op.dart | 6 +- lib/src/common/ops/dequantize_op.dart | 4 +- lib/src/common/ops/normailze_op.dart | 6 +- lib/src/common/ops/quantize_op.dart | 4 +- lib/src/common/processor.dart | 2 +- lib/src/common/sequential_processor.dart | 4 +- lib/src/common/tensor_operator.dart | 4 +- lib/src/common/tensor_processor.dart | 6 +- lib/src/image/base_image_container.dart | 5 +- lib/src/image/bounding_box_utils.dart | 4 +- lib/src/image/camera_image_container.dart | 6 +- lib/src/image/color_space_type.dart | 4 +- lib/src/image/image_container.dart | 8 +-- lib/src/image/image_conversions.dart | 4 +- lib/src/image/image_operator.dart | 4 +- lib/src/image/image_processor.dart | 12 ++-- lib/src/image/ops/resize_op.dart | 6 +- .../image/ops/resize_with_crop_or_pad_op.dart | 6 +- lib/src/image/ops/rot90_op.dart | 4 +- .../image/ops/tensor_operator_wrapper.dart | 10 +-- .../image/ops/transform_to_grayscale_op.dart | 4 +- lib/src/image/tensor_buffer_container.dart | 34 +++++----- lib/src/image/tensor_image.dart | 12 ++-- lib/src/label/label_util.dart | 4 +- lib/src/label/ops/label_axis_op.dart | 8 +-- lib/src/label/tensor_label.dart | 4 +- .../nl_classifier/bert_nl_classifier.dart | 62 +++++++++--------- .../text/nl_classifier/nl_classifer.dart | 42 ++++++------- .../bindings/text/nl_classifier/types.dart | 12 ++-- lib/src/task/bindings/text/qa/bert_qa.dart | 63 +++++++++++-------- lib/src/task/bindings/text/qa/types.dart | 6 +- .../nl_classifier/bert_nl_classifier.dart | 10 +-- .../bert_nl_classifier_options.dart | 5 +- .../text/nl_classifier/nl_classifier.dart | 10 +-- .../nl_classifier/nl_classifier_options.dart | 2 +- .../task/text/qa/bert_question_answerer.dart | 8 +-- lib/src/task/text/qa/question_answerer.dart | 2 +- lib/src/tensorbuffer/tensorbuffer.dart | 6 +- lib/src/tensorbuffer/tensorbufferfloat.dart | 2 +- lib/src/tensorbuffer/tensorbufferuint8.dart | 4 +- ...essing.dart => tflite_flutter_helper.dart} | 2 +- linux/CMakeLists.txt | 8 +-- .../tflite_flutter_processing_plugin.h | 4 +- linux/tflite_flutter_processing_plugin.cc | 26 ++++---- .../TfliteFlutterProcessingPlugin.swift | 2 +- macos/tflite_flutter_processing.podspec | 4 +- pubspec.lock | 56 ++++++++--------- pubspec.yaml | 23 ++++--- test/tfliteflutterhelper_test.dart | 26 ++++---- 83 files changed, 356 insertions(+), 353 deletions(-) create mode 100644 .fvmrc rename lib/{tflite_flutter_processing.dart => tflite_flutter_helper.dart} (98%) diff --git a/.fvmrc b/.fvmrc new file mode 100644 index 0000000..1d77e35 --- /dev/null +++ b/.fvmrc @@ -0,0 +1,4 @@ +{ + "flutter": "3.22.0", + "flavors": {} +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7d0c21c..ead43ac 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,6 @@ build/ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +# FVM Version Cache +.fvm/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ac55719..9550bb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# [0.4.1] - Moved to tflite flutter processor +# [0.4.0] - Moved to tflite flutter processor * Updated all libraries to support updated tflite_flutter package. * fixed bug in android preventing build diff --git a/android/build.gradle b/android/build.gradle index cd4d160..77d9e7b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,8 +1,8 @@ -group 'io.chaosdev.tflite_flutter_processing' +group 'com.xmartlabs.tflite_flutter_helper' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '2.0.0' repositories { google() jcenter() diff --git a/android/settings.gradle b/android/settings.gradle index 69059b0..fd73fe9 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1 +1 @@ -rootProject.name = 'tflite_flutter_processing' +rootProject.name = 'tflite_flutter_helper' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 7452853..ccefbc9 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ + package="com.xmartlabs.tflite_flutter_helper"> diff --git a/android/src/main/kotlin/io/chaosdev/tflite_flutter_processing/TfliteFlutterProcessingPlugin.kt b/android/src/main/kotlin/io/chaosdev/tflite_flutter_processing/TfliteFlutterProcessingPlugin.kt index 5b3b940..a595612 100644 --- a/android/src/main/kotlin/io/chaosdev/tflite_flutter_processing/TfliteFlutterProcessingPlugin.kt +++ b/android/src/main/kotlin/io/chaosdev/tflite_flutter_processing/TfliteFlutterProcessingPlugin.kt @@ -1,4 +1,4 @@ -package io.chaosdev.tflite_flutter_processing +package com.xmartlabs.tflite_flutter_helper import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.plugin.common.MethodCall @@ -37,7 +37,7 @@ enum class SoundStreamStatus { Stopped, } -const val METHOD_CHANNEL_NAME = "io.chaosdev.tflite_flutter_processing:methods" +const val METHOD_CHANNEL_NAME = "com.xmartlabs.tflite_flutter_helper:methods" /** TfliteFlutterProcessingPlugin */ class TfliteFlutterProcessingPlugin : FlutterPlugin, diff --git a/example/audio_classification/lib/classifier.dart b/example/audio_classification/lib/classifier.dart index 3b0b45a..0121d1e 100644 --- a/example/audio_classification/lib/classifier.dart +++ b/example/audio_classification/lib/classifier.dart @@ -4,7 +4,7 @@ import 'package:audio_classification/main.dart'; import 'package:flutter/services.dart'; import 'package:collection/collection.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class Classifier { late Interpreter interpreter; @@ -84,7 +84,9 @@ List getTopProbability(Map labeledProb) { var pq = PriorityQueue>(compare); pq.addAll(labeledProb.entries); var result = []; - while (pq.isNotEmpty && result.length < 5 && (pq.first.value > 0.1 || result.length < 3)) { + while (pq.isNotEmpty && + result.length < 5 && + (pq.first.value > 0.1 || result.length < 3)) { result.add(Category(pq.first.key, pq.first.value)); pq.removeFirst(); } diff --git a/example/audio_classification/lib/main.dart b/example/audio_classification/lib/main.dart index 458cceb..d4842ce 100644 --- a/example/audio_classification/lib/main.dart +++ b/example/audio_classification/lib/main.dart @@ -3,7 +3,7 @@ import 'dart:ui'; import 'package:audio_classification/classifier.dart'; import 'package:flutter/material.dart'; import 'package:random_color/random_color.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; void main() { runApp(MyApp()); diff --git a/example/audio_classification/pubspec.lock b/example/audio_classification/pubspec.lock index 229a990..23fd506 100644 --- a/example/audio_classification/pubspec.lock +++ b/example/audio_classification/pubspec.lock @@ -405,7 +405,7 @@ packages: url: "https://pub.dev" source: hosted version: "0.10.4" - tflite_flutter_processing: + tflite_flutter_helper: dependency: "direct main" description: path: "../.." diff --git a/example/audio_classification/pubspec.yaml b/example/audio_classification/pubspec.yaml index 0120cee..a320d9d 100644 --- a/example/audio_classification/pubspec.yaml +++ b/example/audio_classification/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -26,9 +26,8 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - tflite_flutter_processing: - path: - ../../ + tflite_flutter_helper: + path: ../../ random_color: ^1.0.6-nullsafety dev_dependencies: flutter_test: @@ -39,7 +38,6 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. diff --git a/example/bert_question_answer/lib/bert_qa.dart b/example/bert_question_answer/lib/bert_qa.dart index f60a8aa..e24a623 100644 --- a/example/bert_question_answer/lib/bert_qa.dart +++ b/example/bert_question_answer/lib/bert_qa.dart @@ -2,14 +2,14 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class BertQA { late final BertQuestionAnswerer bertQuestionAnswerer; final _modelPath = "lite-model_mobilebert_1_metadata_1.tflite"; - BertQA () { + BertQA() { createClassifier(); } diff --git a/example/bert_question_answer/pubspec.lock b/example/bert_question_answer/pubspec.lock index 7f8ce4a..7ec81b9 100644 --- a/example/bert_question_answer/pubspec.lock +++ b/example/bert_question_answer/pubspec.lock @@ -477,7 +477,7 @@ packages: url: "https://pub.dev" source: hosted version: "0.10.4" - tflite_flutter_processing: + tflite_flutter_helper: dependency: "direct main" description: path: "../.." diff --git a/example/bert_question_answer/pubspec.yaml b/example/bert_question_answer/pubspec.yaml index cfb34b8..65a33ba 100644 --- a/example/bert_question_answer/pubspec.yaml +++ b/example/bert_question_answer/pubspec.yaml @@ -3,7 +3,7 @@ description: Sample app for Bert Question Answer in Flutter # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -23,9 +23,8 @@ environment: dependencies: flutter: sdk: flutter - tflite_flutter_processing: - path: - ../../ + tflite_flutter_helper: + path: ../../ path_provider: riverpod: ^0.14.0+3 cupertino_icons: ^1.0.2 @@ -40,7 +39,6 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. diff --git a/example/image_classification/android/settings.gradle b/example/image_classification/android/settings.gradle index 567bb22..5c80b1b 100644 --- a/example/image_classification/android/settings.gradle +++ b/example/image_classification/android/settings.gradle @@ -20,7 +20,6 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "7.1.2" apply false -// id "org.jetbrains.kotlin.android" version "{kotlinVersion}" apply false } -include ":app" \ No newline at end of file +include ":app" diff --git a/example/image_classification/integration_test/classifier_test_helper.dart b/example/image_classification/integration_test/classifier_test_helper.dart index 16783b7..b536719 100644 --- a/example/image_classification/integration_test/classifier_test_helper.dart +++ b/example/image_classification/integration_test/classifier_test_helper.dart @@ -3,7 +3,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:imageclassification/classifier.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; abstract class ClassiferTest extends Classifier { @override diff --git a/example/image_classification/integration_test/image_classification_test.dart b/example/image_classification/integration_test/image_classification_test.dart index 70eab63..bc3e526 100644 --- a/example/image_classification/integration_test/image_classification_test.dart +++ b/example/image_classification/integration_test/image_classification_test.dart @@ -3,7 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:image/image.dart' as img; import 'package:imageclassification/classifier.dart'; import 'package:integration_test/integration_test.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; import 'classifier_test_helper.dart'; diff --git a/example/image_classification/lib/classifier.dart b/example/image_classification/lib/classifier.dart index 1a27446..07b644b 100644 --- a/example/image_classification/lib/classifier.dart +++ b/example/image_classification/lib/classifier.dart @@ -4,7 +4,7 @@ import 'package:image/image.dart'; import 'package:collection/collection.dart'; import 'package:logger/logger.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; abstract class Classifier { late Interpreter interpreter; diff --git a/example/image_classification/lib/classifier_float.dart b/example/image_classification/lib/classifier_float.dart index 62d0a47..78d6793 100644 --- a/example/image_classification/lib/classifier_float.dart +++ b/example/image_classification/lib/classifier_float.dart @@ -1,5 +1,5 @@ import 'package:imageclassification/classifier.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class ClassifierFloat extends Classifier { ClassifierFloat({int? numThreads}) : super(numThreads: numThreads); diff --git a/example/image_classification/lib/classifier_quant.dart b/example/image_classification/lib/classifier_quant.dart index ae796a5..1965cbd 100644 --- a/example/image_classification/lib/classifier_quant.dart +++ b/example/image_classification/lib/classifier_quant.dart @@ -1,5 +1,5 @@ import 'package:imageclassification/classifier.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class ClassifierQuant extends Classifier { ClassifierQuant({int numThreads: 1}) : super(numThreads: numThreads); diff --git a/example/image_classification/lib/main.dart b/example/image_classification/lib/main.dart index cfe8ad4..28d2533 100644 --- a/example/image_classification/lib/main.dart +++ b/example/image_classification/lib/main.dart @@ -5,7 +5,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:imageclassification/classifier.dart'; import 'package:imageclassification/classifier_quant.dart'; import 'package:logger/logger.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; void main() => runApp(MyApp()); diff --git a/example/image_classification/pubspec.lock b/example/image_classification/pubspec.lock index d2cb3d3..19bcd5a 100644 --- a/example/image_classification/pubspec.lock +++ b/example/image_classification/pubspec.lock @@ -556,7 +556,7 @@ packages: url: "https://pub.dev" source: hosted version: "0.10.4" - tflite_flutter_processing: + tflite_flutter_helper: dependency: "direct main" description: path: "../.." diff --git a/example/image_classification/pubspec.yaml b/example/image_classification/pubspec.yaml index a11497c..cba4d58 100644 --- a/example/image_classification/pubspec.yaml +++ b/example/image_classification/pubspec.yaml @@ -24,9 +24,8 @@ dependencies: logger: ^2.0.2+1 path_provider: - tflite_flutter_processing: - path: - ../../ + tflite_flutter_helper: + path: ../../ # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. @@ -45,7 +44,6 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. diff --git a/example/text_classification_task/lib/classifier.dart b/example/text_classification_task/lib/classifier.dart index 0335fb1..3be0778 100644 --- a/example/text_classification_task/lib/classifier.dart +++ b/example/text_classification_task/lib/classifier.dart @@ -1,4 +1,4 @@ -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; abstract class Classifier { List classify(String text); diff --git a/example/text_classification_task/lib/classifier_task_lib.dart b/example/text_classification_task/lib/classifier_task_lib.dart index 81ae802..c61f2d3 100644 --- a/example/text_classification_task/lib/classifier_task_lib.dart +++ b/example/text_classification_task/lib/classifier_task_lib.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; import 'classifier.dart'; diff --git a/example/text_classification_task/pubspec.yaml b/example/text_classification_task/pubspec.yaml index b9b3fa7..6d2f91d 100644 --- a/example/text_classification_task/pubspec.yaml +++ b/example/text_classification_task/pubspec.yaml @@ -1,6 +1,6 @@ name: text_classification_task description: Text Classification Example using task library -publish_to: 'none' +publish_to: "none" environment: sdk: ">=2.12.0 <3.0.0" @@ -9,9 +9,8 @@ environment: dependencies: flutter: sdk: flutter - tflite_flutter_processing: - path: - ../../ + tflite_flutter_helper: + path: ../../ path_provider: ^2.0.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. @@ -25,13 +24,11 @@ dev_dependencies: integration_test: sdk: flutter - # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. diff --git a/examples/image_classifier/lib/classifier.dart b/examples/image_classifier/lib/classifier.dart index 4b937d5..cd28916 100644 --- a/examples/image_classifier/lib/classifier.dart +++ b/examples/image_classifier/lib/classifier.dart @@ -4,7 +4,7 @@ import 'package:image/image.dart'; import 'package:collection/collection.dart'; import 'package:logger/logger.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; abstract class Classifier { late Interpreter interpreter; diff --git a/examples/image_classifier/lib/classifier_float.dart b/examples/image_classifier/lib/classifier_float.dart index 62d0a47..78d6793 100644 --- a/examples/image_classifier/lib/classifier_float.dart +++ b/examples/image_classifier/lib/classifier_float.dart @@ -1,5 +1,5 @@ import 'package:imageclassification/classifier.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class ClassifierFloat extends Classifier { ClassifierFloat({int? numThreads}) : super(numThreads: numThreads); diff --git a/examples/image_classifier/lib/classifier_quant.dart b/examples/image_classifier/lib/classifier_quant.dart index f674365..38e8f03 100644 --- a/examples/image_classifier/lib/classifier_quant.dart +++ b/examples/image_classifier/lib/classifier_quant.dart @@ -1,5 +1,5 @@ import 'package:imageclassification/classifier.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class ClassifierQuant extends Classifier { ClassifierQuant({int numThreads = 1}) : super(numThreads: numThreads); diff --git a/examples/image_classifier/lib/main.dart b/examples/image_classifier/lib/main.dart index cfe8ad4..28d2533 100644 --- a/examples/image_classifier/lib/main.dart +++ b/examples/image_classifier/lib/main.dart @@ -5,7 +5,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:imageclassification/classifier.dart'; import 'package:imageclassification/classifier_quant.dart'; import 'package:logger/logger.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; void main() => runApp(MyApp()); diff --git a/ios/Classes/SwiftTfliteFlutterProcessingPlugin.swift b/ios/Classes/SwiftTfliteFlutterProcessingPlugin.swift index 699bff8..a10bc9e 100644 --- a/ios/Classes/SwiftTfliteFlutterProcessingPlugin.swift +++ b/ios/Classes/SwiftTfliteFlutterProcessingPlugin.swift @@ -3,7 +3,7 @@ import UIKit public class SwiftTfliteFlutterProcessingPlugin: NSObject, FlutterPlugin { public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "tflite_flutter_processing", binaryMessenger: registrar.messenger()) + let channel = FlutterMethodChannel(name: "tflite_flutter_helper", binaryMessenger: registrar.messenger()) let instance = SwiftTfliteFlutterProcessingPlugin() registrar.addMethodCallDelegate(instance, channel: channel) } diff --git a/ios/Classes/TfliteFlutterProcessingPlugin.m b/ios/Classes/TfliteFlutterProcessingPlugin.m index 29c0c4a..6aa70ea 100644 --- a/ios/Classes/TfliteFlutterProcessingPlugin.m +++ b/ios/Classes/TfliteFlutterProcessingPlugin.m @@ -1,11 +1,11 @@ #import "TfliteFlutterProcessingPlugin.h" -#if __has_include() -#import +#if __has_include() +#import #else // Support project import fallback if the generated compatibility header // is not copied when this plugin is created as a library. // https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 -#import "tflite_flutter_processing-Swift.h" +#import "tflite_flutter_helper-Swift.h" #endif @implementation TfliteFlutterProcessingPlugin diff --git a/ios/tflite_flutter_processing.podspec b/ios/tflite_flutter_processing.podspec index 2d448d9..5b4d88c 100644 --- a/ios/tflite_flutter_processing.podspec +++ b/ios/tflite_flutter_processing.podspec @@ -1,9 +1,9 @@ # # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. -# Run `pod lib lint tflite_flutter_processing.podspec` to validate before publishing. +# Run `pod lib lint tflite_flutter_helper.podspec` to validate before publishing. # Pod::Spec.new do |s| - s.name = 'tflite_flutter_processing' + s.name = 'tflite_flutter_helper' s.version = '0.1.0' s.summary = 'A new Flutter project.' s.description = <<-DESC diff --git a/lib/src/audio/tensor_audio.dart b/lib/src/audio/tensor_audio.dart index a87f3df..3c2d381 100644 --- a/lib/src/audio/tensor_audio.dart +++ b/lib/src/audio/tensor_audio.dart @@ -3,14 +3,14 @@ import 'dart:typed_data'; import 'package:quiver/check.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/tflite_flutter_processing.dart'; +import 'package:tflite_flutter_helper/tflite_flutter_helper.dart'; class TensorAudio { static const String TAG = "TensorAudioDart"; late final FloatRingBuffer buffer; late final TensorAudioFormat format; - TensorAudio._(this.format, int sampleCount){ + TensorAudio._(this.format, int sampleCount) { this.buffer = FloatRingBuffer._(sampleCount * format.channelCount); } @@ -22,13 +22,12 @@ class TensorAudio { loadDoubleListOffset(src, 0, src.length); } - void loadDoubleListOffset(List src, int offsetInFloat, - int sizeInFloat) { + void loadDoubleListOffset( + List src, int offsetInFloat, int sizeInFloat) { checkArgument( sizeInFloat % format.channelCount == 0, message: - "Size ($sizeInFloat) needs to be a multiplier of the number of channels (${format - .channelCount})", + "Size ($sizeInFloat) needs to be a multiplier of the number of channels (${format.channelCount})", ); buffer.loadOffset(src, offsetInFloat, sizeInFloat); } @@ -56,10 +55,9 @@ class TensorAudio { } void loadListOffset(List src, int offsetInShort, int sizeInShort) { - checkArgument( - offsetInShort + sizeInShort <= src.length, - message: "Index out of range. offset ($offsetInShort) + size ($sizeInShort) should <= newData.length (${src - .length})"); + checkArgument(offsetInShort + sizeInShort <= src.length, + message: + "Index out of range. offset ($offsetInShort) + size ($sizeInShort) should <= newData.length (${src.length})"); List floatData = List.filled(sizeInShort, 0.0); for (int i = offsetInShort; i < sizeInShort; i++) { // Convert the data to PCM Float encoding i.e. values between -1 and 1 @@ -68,19 +66,14 @@ class TensorAudio { loadDoubleList(floatData); } - /// Returns a float {@link TensorBuffer} holding all the available audio samples in {@link /// android.media.AudioFormat#ENCODING_PCM_FLOAT} i.e. values are in the range of [-1, 1]. TensorBuffer get tensorBuffer { ByteBuffer byteBuffer = buffer.buffer; TensorBuffer tensorBuffer = - // TODO: Confirm Shape - TensorBuffer.createFixedSize( - [1, byteBuffer - .asFloat32List() - .length - ], - TensorType.float32); + // TODO: Confirm Shape + TensorBuffer.createFixedSize( + [1, byteBuffer.asFloat32List().length], TensorType.float32); tensorBuffer.loadBuffer(byteBuffer); return tensorBuffer; } @@ -105,8 +98,8 @@ class TensorAudioFormat { static TensorAudioFormat create(int channelCount, int sampleRate) { checkArgument(channelCount > 0, message: "Number of channels should be greater than 0"); - checkArgument( - sampleRate > 0, message: "Sample rate should be greater than 0"); + checkArgument(sampleRate > 0, + message: "Sample rate should be greater than 0"); return TensorAudioFormat._(channelCount, sampleRate); } @@ -136,8 +129,7 @@ class FloatRingBuffer { checkArgument( offset + size <= newData.length, message: - "Index out of range. offset ($offset) + size ($size) should <= newData.length (${newData - .length})", + "Index out of range. offset ($offset) + size ($size) should <= newData.length (${newData.length})", ); // If buffer can't hold all the data, only keep the most recent data of size buffer.length if (size > _buffer.length) { @@ -164,9 +156,7 @@ class FloatRingBuffer { ByteBuffer get buffer { // TODO: Make sure there is no endianness issue - return Float32List - .fromList(_buffer) - .buffer; + return Float32List.fromList(_buffer).buffer; } int get capacity => _buffer.length; diff --git a/lib/src/common/ops/cast_op.dart b/lib/src/common/ops/cast_op.dart index 067938c..bd6f361 100644 --- a/lib/src/common/ops/cast_op.dart +++ b/lib/src/common/ops/cast_op.dart @@ -1,7 +1,7 @@ import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_operator.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_operator.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Casts a [TensorBuffer] to a specified data type. class CastOp implements TensorOperator { diff --git a/lib/src/common/ops/dequantize_op.dart b/lib/src/common/ops/dequantize_op.dart index beb524c..71dec76 100644 --- a/lib/src/common/ops/dequantize_op.dart +++ b/lib/src/common/ops/dequantize_op.dart @@ -1,5 +1,5 @@ -import 'package:tflite_flutter_processing/src/common/ops/normailze_op.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_operator.dart'; +import 'package:tflite_flutter_helper/src/common/ops/normailze_op.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_operator.dart'; /// Dequantizes a [TensorBuffer] with given [zeroPoint] and [scale]. /// diff --git a/lib/src/common/ops/normailze_op.dart b/lib/src/common/ops/normailze_op.dart index 23df2b4..4487e58 100644 --- a/lib/src/common/ops/normailze_op.dart +++ b/lib/src/common/ops/normailze_op.dart @@ -1,7 +1,7 @@ import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_operator.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_operator.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Normalizes a [TensorBuffer] with given mean and stddev: output = (input - mean) / stddev. class NormalizeOp implements TensorOperator { diff --git a/lib/src/common/ops/quantize_op.dart b/lib/src/common/ops/quantize_op.dart index 2dffbb4..b1fac6f 100644 --- a/lib/src/common/ops/quantize_op.dart +++ b/lib/src/common/ops/quantize_op.dart @@ -1,5 +1,5 @@ -import 'package:tflite_flutter_processing/src/common/ops/normailze_op.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_operator.dart'; +import 'package:tflite_flutter_helper/src/common/ops/normailze_op.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_operator.dart'; /// Quantizes a [TensorBuffer] with given [zeroPoint] and [scale]. /// diff --git a/lib/src/common/processor.dart b/lib/src/common/processor.dart index 9238ed3..57315e9 100644 --- a/lib/src/common/processor.dart +++ b/lib/src/common/processor.dart @@ -1,4 +1,4 @@ -import 'package:tflite_flutter_processing/src/common/operator.dart'; +import 'package:tflite_flutter_helper/src/common/operator.dart'; /// Processes [T] object with prepared [Operator]. abstract class Processor { diff --git a/lib/src/common/sequential_processor.dart b/lib/src/common/sequential_processor.dart index 67466ce..7e64022 100644 --- a/lib/src/common/sequential_processor.dart +++ b/lib/src/common/sequential_processor.dart @@ -1,5 +1,5 @@ -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/image/image_processor.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/image/image_processor.dart'; import 'operator.dart'; import 'processor.dart'; import 'package:meta/meta.dart'; diff --git a/lib/src/common/tensor_operator.dart b/lib/src/common/tensor_operator.dart index 361e3c8..88d3041 100644 --- a/lib/src/common/tensor_operator.dart +++ b/lib/src/common/tensor_operator.dart @@ -1,5 +1,5 @@ -import 'package:tflite_flutter_processing/src/common/operator.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/operator.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Applies some operation on TensorBuffers. abstract class TensorOperator extends Operator { diff --git a/lib/src/common/tensor_processor.dart b/lib/src/common/tensor_processor.dart index 82827cf..8c4c393 100644 --- a/lib/src/common/tensor_processor.dart +++ b/lib/src/common/tensor_processor.dart @@ -1,6 +1,6 @@ -import 'package:tflite_flutter_processing/src/common/operator.dart'; -import 'package:tflite_flutter_processing/src/common/sequential_processor.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/operator.dart'; +import 'package:tflite_flutter_helper/src/common/sequential_processor.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// TensorProcessor is a helper class for preprocessing and postprocessing tensors. It could /// transform a [TensorBuffer] to another by executing a chain of [TensorOperator]. diff --git a/lib/src/image/base_image_container.dart b/lib/src/image/base_image_container.dart index baee08f..1226d26 100644 --- a/lib/src/image/base_image_container.dart +++ b/lib/src/image/base_image_container.dart @@ -1,11 +1,10 @@ import 'package:camera/camera.dart'; import 'package:image/image.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/image/color_space_type.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/color_space_type.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; abstract class BaseImageContainer { - /// Performs deep copy of the {@link ImageContainer}. */ BaseImageContainer clone(); diff --git a/lib/src/image/bounding_box_utils.dart b/lib/src/image/bounding_box_utils.dart index e601f82..ebe1397 100644 --- a/lib/src/image/bounding_box_utils.dart +++ b/lib/src/image/bounding_box_utils.dart @@ -2,8 +2,8 @@ import 'dart:ui'; import 'package:flutter/rendering.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Helper class for converting values that represents bounding boxes into rectangles. /// diff --git a/lib/src/image/camera_image_container.dart b/lib/src/image/camera_image_container.dart index f7afda4..d818d73 100644 --- a/lib/src/image/camera_image_container.dart +++ b/lib/src/image/camera_image_container.dart @@ -2,9 +2,9 @@ import 'package:camera/camera.dart'; import 'package:image/image.dart'; import 'package:quiver/check.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/image/color_space_type.dart'; -import 'package:tflite_flutter_processing/src/image/base_image_container.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/color_space_type.dart'; +import 'package:tflite_flutter_helper/src/image/base_image_container.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; class CameraImageContainer extends BaseImageContainer { late final CameraImage cameraImage; diff --git a/lib/src/image/color_space_type.dart b/lib/src/image/color_space_type.dart index 7e87f4c..8415966 100644 --- a/lib/src/image/color_space_type.dart +++ b/lib/src/image/color_space_type.dart @@ -1,7 +1,7 @@ import 'package:image/image.dart'; import 'package:quiver/check.dart'; -import 'package:tflite_flutter_processing/src/image/image_conversions.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/image_conversions.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; abstract class ColorSpaceType { // The first element of the normalizaed shape. diff --git a/lib/src/image/image_container.dart b/lib/src/image/image_container.dart index 5eab344..5136aca 100644 --- a/lib/src/image/image_container.dart +++ b/lib/src/image/image_container.dart @@ -1,10 +1,10 @@ import 'package:camera/camera.dart'; import 'package:image/image.dart' as img; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/image/base_image_container.dart'; -import 'package:tflite_flutter_processing/src/image/image_conversions.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; -import 'package:tflite_flutter_processing/src/image/color_space_type.dart'; +import 'package:tflite_flutter_helper/src/image/base_image_container.dart'; +import 'package:tflite_flutter_helper/src/image/image_conversions.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/color_space_type.dart'; class ImageContainer extends BaseImageContainer { late final img.Image _image; diff --git a/lib/src/image/image_conversions.dart b/lib/src/image/image_conversions.dart index d03be03..d4030cf 100644 --- a/lib/src/image/image_conversions.dart +++ b/lib/src/image/image_conversions.dart @@ -1,7 +1,7 @@ import 'package:image/image.dart' as img; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/image/color_space_type.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/color_space_type.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Implements some stateless image conversion methods. /// diff --git a/lib/src/image/image_operator.dart b/lib/src/image/image_operator.dart index d808712..42264c8 100644 --- a/lib/src/image/image_operator.dart +++ b/lib/src/image/image_operator.dart @@ -1,7 +1,7 @@ import 'dart:math'; -import 'package:tflite_flutter_processing/src/common/operator.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/common/operator.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; /// Operates a TensorImage object. Used in ImageProcessor. abstract class ImageOperator extends Operator { diff --git a/lib/src/image/image_processor.dart b/lib/src/image/image_processor.dart index ae2316a..8c8e39e 100644 --- a/lib/src/image/image_processor.dart +++ b/lib/src/image/image_processor.dart @@ -1,12 +1,12 @@ import 'dart:math'; import 'dart:ui'; -import 'package:tflite_flutter_processing/src/common/operator.dart'; -import 'package:tflite_flutter_processing/src/common/sequential_processor.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_operator.dart'; -import 'package:tflite_flutter_processing/src/image/ops/tensor_operator_wrapper.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/common/operator.dart'; +import 'package:tflite_flutter_helper/src/common/sequential_processor.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_operator.dart'; +import 'package:tflite_flutter_helper/src/image/ops/tensor_operator_wrapper.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; import 'image_operator.dart'; import 'ops/rot90_op.dart'; diff --git a/lib/src/image/ops/resize_op.dart b/lib/src/image/ops/resize_op.dart index 4f5b1b3..144eda9 100644 --- a/lib/src/image/ops/resize_op.dart +++ b/lib/src/image/ops/resize_op.dart @@ -1,8 +1,8 @@ import 'package:image/image.dart' show Image, copyResize, Interpolation; import 'dart:math' show Point; -import 'package:tflite_flutter_processing/src/image/image_operator.dart'; -import 'package:tflite_flutter_processing/src/image/ops/resize_with_crop_or_pad_op.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/image/image_operator.dart'; +import 'package:tflite_flutter_helper/src/image/ops/resize_with_crop_or_pad_op.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; /// As a computation unit for processing images, it can resize an image to user-specified size. /// diff --git a/lib/src/image/ops/resize_with_crop_or_pad_op.dart b/lib/src/image/ops/resize_with_crop_or_pad_op.dart index 43eb1ad..b8abfa4 100644 --- a/lib/src/image/ops/resize_with_crop_or_pad_op.dart +++ b/lib/src/image/ops/resize_with_crop_or_pad_op.dart @@ -1,9 +1,9 @@ import 'dart:math' show Point; import 'package:image/image.dart' show Image, drawPixel; import 'dart:math'; -import 'package:tflite_flutter_processing/src/image/image_operator.dart'; -import 'package:tflite_flutter_processing/src/image/ops/resize_op.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/image/image_operator.dart'; +import 'package:tflite_flutter_helper/src/image/ops/resize_op.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; import 'package:tuple/tuple.dart'; /// As a computation unit for processing images, it could resize image to predefined size. diff --git a/lib/src/image/ops/rot90_op.dart b/lib/src/image/ops/rot90_op.dart index 5dbd5c5..be9389d 100644 --- a/lib/src/image/ops/rot90_op.dart +++ b/lib/src/image/ops/rot90_op.dart @@ -1,7 +1,7 @@ import 'dart:math' show Point; import 'package:image/image.dart' show Image, copyRotate; -import 'package:tflite_flutter_processing/src/image/image_operator.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/image/image_operator.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; /// Rotates image by multiples of 90 degree. class Rot90Op extends ImageOperator { diff --git a/lib/src/image/ops/tensor_operator_wrapper.dart b/lib/src/image/ops/tensor_operator_wrapper.dart index 51323d3..1d02f88 100644 --- a/lib/src/image/ops/tensor_operator_wrapper.dart +++ b/lib/src/image/ops/tensor_operator_wrapper.dart @@ -1,10 +1,10 @@ import 'dart:math'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_operator.dart'; -import 'package:tflite_flutter_processing/src/image/image_operator.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_operator.dart'; +import 'package:tflite_flutter_helper/src/image/image_operator.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// The adapter that makes a TensorOperator able to run with TensorImage. /// diff --git a/lib/src/image/ops/transform_to_grayscale_op.dart b/lib/src/image/ops/transform_to_grayscale_op.dart index 4411702..32dab2e 100644 --- a/lib/src/image/ops/transform_to_grayscale_op.dart +++ b/lib/src/image/ops/transform_to_grayscale_op.dart @@ -1,7 +1,7 @@ import 'dart:math'; import 'package:image/image.dart' as imageLib; -import 'package:tflite_flutter_processing/src/image/image_operator.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/image/image_operator.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; class TransformToGrayscaleOp extends ImageOperator { @override diff --git a/lib/src/image/tensor_buffer_container.dart b/lib/src/image/tensor_buffer_container.dart index acb475f..48c69e7 100644 --- a/lib/src/image/tensor_buffer_container.dart +++ b/lib/src/image/tensor_buffer_container.dart @@ -2,9 +2,9 @@ import 'package:camera/camera.dart'; import 'package:image/image.dart'; import 'package:quiver/check.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/image/color_space_type.dart'; -import 'package:tflite_flutter_processing/src/image/base_image_container.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/color_space_type.dart'; +import 'package:tflite_flutter_helper/src/image/base_image_container.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; class TensorBufferContainer implements BaseImageContainer { late final TensorBuffer _buffer; @@ -20,11 +20,14 @@ class TensorBufferContainer implements BaseImageContainer { /// /// @throws IllegalArgumentException if the shape of the {@link TensorBuffer} does not match the /// specified color space type, or if the color space type is not supported - static TensorBufferContainer create(TensorBuffer buffer, ColorSpaceType colorSpaceType) { + static TensorBufferContainer create( + TensorBuffer buffer, ColorSpaceType colorSpaceType) { checkArgument( - colorSpaceType == ColorSpaceType.RGB || colorSpaceType == ColorSpaceType.GRAYSCALE, - message: "Only ColorSpaceType.RGB and ColorSpaceType.GRAYSCALE are supported. Use" - + " `create(TensorBuffer, ImageProperties)` for other color space types."); + colorSpaceType == ColorSpaceType.RGB || + colorSpaceType == ColorSpaceType.GRAYSCALE, + message: + "Only ColorSpaceType.RGB and ColorSpaceType.GRAYSCALE are supported. Use" + + " `create(TensorBuffer, ImageProperties)` for other color space types."); return TensorBufferContainer._( buffer, @@ -33,12 +36,12 @@ class TensorBufferContainer implements BaseImageContainer { colorSpaceType.getWidth(buffer.getShape())); } - TensorBufferContainer._( - TensorBuffer buffer, ColorSpaceType colorSpaceType, int height, int width) { - checkArgument( - colorSpaceType != ColorSpaceType.YUV_420_888, - message: "The actual encoding format of YUV420 is required. Choose a ColorSpaceType from: NV12," - + " NV21, YV12, YV21. Use YUV_420_888 only when loading an android.media.Image."); + TensorBufferContainer._(TensorBuffer buffer, ColorSpaceType colorSpaceType, + int height, int width) { + checkArgument(colorSpaceType != ColorSpaceType.YUV_420_888, + message: + "The actual encoding format of YUV420 is required. Choose a ColorSpaceType from: NV12," + + " NV21, YV12, YV21. Use YUV_420_888 only when loading an android.media.Image."); colorSpaceType.assertNumElements(buffer.getFlatSize(), height, width); this._buffer = buffer; @@ -77,7 +80,9 @@ class TensorBufferContainer implements BaseImageContainer { // performance considerations. During image processing, users may need to set and get the // TensorBuffer many times. // Otherwise, create another one with the expected data type. - return _buffer.getDataType() == dataType ? _buffer : TensorBuffer.createFrom(_buffer, dataType); + return _buffer.getDataType() == dataType + ? _buffer + : TensorBuffer.createFrom(_buffer, dataType); } @override @@ -104,5 +109,4 @@ class TensorBufferContainer implements BaseImageContainer { ColorSpaceType get colorSpaceType { return _colorSpaceType; } - } diff --git a/lib/src/image/tensor_image.dart b/lib/src/image/tensor_image.dart index 100f729..64f08d2 100644 --- a/lib/src/image/tensor_image.dart +++ b/lib/src/image/tensor_image.dart @@ -4,11 +4,11 @@ import 'dart:typed_data'; import 'package:image/image.dart'; import 'package:quiver/check.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/image/base_image_container.dart'; -import 'package:tflite_flutter_processing/src/image/color_space_type.dart'; -import 'package:tflite_flutter_processing/src/image/image_container.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_buffer_container.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/image/base_image_container.dart'; +import 'package:tflite_flutter_helper/src/image/color_space_type.dart'; +import 'package:tflite_flutter_helper/src/image/image_container.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_buffer_container.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// [TensorImage] is the wrapper class for [Image] object. When using image processing utils in /// Flutter Helper library, it's common to convert image objects in variant types to TensorImage at @@ -171,7 +171,7 @@ class TensorImage { /// It's essentially a short cut for [getTensorBuffer.getBuffer()]. /// /// Throws [StateError] if the TensorImage never loads data. - ByteBuffer get buffer { + ByteBuffer get buffer { return tensorBuffer.buffer; } diff --git a/lib/src/label/label_util.dart b/lib/src/label/label_util.dart index 2e3fe43..7b3d62e 100644 --- a/lib/src/label/label_util.dart +++ b/lib/src/label/label_util.dart @@ -1,5 +1,5 @@ -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Label operation utils. class LabelUtil { diff --git a/lib/src/label/ops/label_axis_op.dart b/lib/src/label/ops/label_axis_op.dart index 8797330..8b97a71 100644 --- a/lib/src/label/ops/label_axis_op.dart +++ b/lib/src/label/ops/label_axis_op.dart @@ -1,8 +1,8 @@ import 'package:meta/meta.dart'; -import 'package:tflite_flutter_processing/src/common/file_util.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/label/tensor_label.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/file_util.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/label/tensor_label.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Labels TensorBuffer with axisLabels for outputs. /// diff --git a/lib/src/label/tensor_label.dart b/lib/src/label/tensor_label.dart index 4b9836c..751db17 100644 --- a/lib/src/label/tensor_label.dart +++ b/lib/src/label/tensor_label.dart @@ -1,8 +1,8 @@ import 'dart:typed_data'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; import 'category.dart'; diff --git a/lib/src/task/bindings/text/nl_classifier/bert_nl_classifier.dart b/lib/src/task/bindings/text/nl_classifier/bert_nl_classifier.dart index 08034cb..bf2d125 100644 --- a/lib/src/task/bindings/text/nl_classifier/bert_nl_classifier.dart +++ b/lib/src/task/bindings/text/nl_classifier/bert_nl_classifier.dart @@ -3,49 +3,51 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'types.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/dlib.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/dlib.dart'; // ignore_for_file: non_constant_identifier_names, camel_case_types // Creates BertBertNLClassifier from model path and options, returns nullptr if the // file doesn't exist or is not a well formatted TFLite model path. -Pointer Function(Pointer modelPath, - Pointer options) -BertNLClassifierFromFileAndOptions = tflitelib - .lookup>( - 'BertNLClassifierFromFileAndOptions') - .asFunction(); +Pointer Function( + Pointer modelPath, Pointer options) + BertNLClassifierFromFileAndOptions = tflitelib + .lookup>( + 'BertNLClassifierFromFileAndOptions') + .asFunction(); -typedef _BertNLClassifierFromFileAndOptions_native_t = Pointer Function( - Pointer modelPath, - Pointer options); +typedef _BertNLClassifierFromFileAndOptions_native_t + = Pointer Function(Pointer modelPath, + Pointer options); // Creates BertNLClassifier from model path and default options, returns nullptr // if the file doesn't exist or is not a well formatted TFLite model path. Pointer Function(Pointer modelPath) -BertNLClassifierFromFile = tflitelib - .lookup>( - 'BertNLClassifierFromFile') - .asFunction(); + BertNLClassifierFromFile = tflitelib + .lookup>( + 'BertNLClassifierFromFile') + .asFunction(); -typedef _BertNLClassifierFromFile_native_t = Pointer Function( - Pointer modelPath); +typedef _BertNLClassifierFromFile_native_t = Pointer + Function(Pointer modelPath); // Invokes the encapsulated TFLite model and classifies the input text. -Pointer Function(Pointer classifier, - Pointer text) -BertNLClassifierClassify = tflitelib - .lookup>( - 'BertNLClassifierClassify') - .asFunction(); +Pointer Function( + Pointer classifier, Pointer text) + BertNLClassifierClassify = tflitelib + .lookup>( + 'BertNLClassifierClassify') + .asFunction(); -typedef _BertNLClassifierClassify_native_t = Pointer Function(Pointer classifier, - Pointer text); +typedef _BertNLClassifierClassify_native_t = Pointer Function( + Pointer classifier, Pointer text); // Deletes BertNLClassifer instance -void Function(Pointer) BertNLClassifierDelete = tflitelib - .lookup>( - 'BertNLClassifierDelete') - .asFunction(); - -typedef _BertNLClassifierDelete_native_t = Void Function(Pointer); \ No newline at end of file +void Function(Pointer) BertNLClassifierDelete = + tflitelib + .lookup>( + 'BertNLClassifierDelete') + .asFunction(); + +typedef _BertNLClassifierDelete_native_t = Void Function( + Pointer); diff --git a/lib/src/task/bindings/text/nl_classifier/nl_classifer.dart b/lib/src/task/bindings/text/nl_classifier/nl_classifer.dart index 1869f7d..a58648e 100644 --- a/lib/src/task/bindings/text/nl_classifier/nl_classifer.dart +++ b/lib/src/task/bindings/text/nl_classifier/nl_classifer.dart @@ -3,38 +3,38 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'types.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/dlib.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/dlib.dart'; // ignore_for_file: non_constant_identifier_names, camel_case_types // Creates NLClassifier from model path and options, returns nullptr if the file // doesn't exist or is not a well formatted TFLite model path. -Pointer Function(Pointer modelPath, - Pointer options) -NLClassifierFromFileAndOptions = tflitelib - .lookup>( - 'NLClassifierFromFileAndOptions') - .asFunction(); +Pointer Function( + Pointer modelPath, Pointer options) + NLClassifierFromFileAndOptions = tflitelib + .lookup>( + 'NLClassifierFromFileAndOptions') + .asFunction(); -typedef _NLClassifierFromFileAndOptions_native_t = Pointer Function( - Pointer modelPath, - Pointer options); +typedef _NLClassifierFromFileAndOptions_native_t + = Pointer Function( + Pointer modelPath, Pointer options); // Invokes the encapsulated TFLite model and classifies the input text. -Pointer Function(Pointer classifier, - Pointer text) -NLClassifierClassify = tflitelib - .lookup>( - 'NLClassifierClassify') - .asFunction(); +Pointer Function( + Pointer classifier, Pointer text) + NLClassifierClassify = tflitelib + .lookup>( + 'NLClassifierClassify') + .asFunction(); -typedef _NLClassifierClassify_native_t = Pointer Function(Pointer classifier, - Pointer text); +typedef _NLClassifierClassify_native_t = Pointer Function( + Pointer classifier, Pointer text); // Deletes NLClassifer instance void Function(Pointer) NLClassifierDelete = tflitelib - .lookup>( - 'NLClassifierDelete') + .lookup>('NLClassifierDelete') .asFunction(); -typedef _NLClassifierDelete_native_t = Void Function(Pointer); \ No newline at end of file +typedef _NLClassifierDelete_native_t = Void Function( + Pointer); diff --git a/lib/src/task/bindings/text/nl_classifier/types.dart b/lib/src/task/bindings/text/nl_classifier/types.dart index 94902df..5ce2fa4 100644 --- a/lib/src/task/bindings/text/nl_classifier/types.dart +++ b/lib/src/task/bindings/text/nl_classifier/types.dart @@ -2,9 +2,9 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -class TfLiteNLClassifier extends Opaque {} +final class TfLiteNLClassifier extends Opaque {} -class TfLiteNLClassifierOptions extends Struct { +final class TfLiteNLClassifierOptions extends Struct { @Int32() external int inputTensorIndex; @@ -40,23 +40,23 @@ class TfLiteNLClassifierOptions extends Struct { } } -class TfLiteCategories extends Struct { +final class TfLiteCategories extends Struct { @Int32() external int size; external Pointer categories; } -class TfLiteCategory extends Struct { +final class TfLiteCategory extends Struct { external Pointer text; @Double() external double score; } -class TfLiteBertNLClassifier extends Opaque {} +final class TfLiteBertNLClassifier extends Opaque {} -class TfLiteBertNLClassifierOptions extends Struct { +final class TfLiteBertNLClassifierOptions extends Struct { @Int32() external int maxSeqLen; diff --git a/lib/src/task/bindings/text/qa/bert_qa.dart b/lib/src/task/bindings/text/qa/bert_qa.dart index 7724a3a..c0f87a0 100644 --- a/lib/src/task/bindings/text/qa/bert_qa.dart +++ b/lib/src/task/bindings/text/qa/bert_qa.dart @@ -3,45 +3,54 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'types.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/dlib.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/dlib.dart'; // ignore_for_file: non_constant_identifier_names, camel_case_types // Creates BertQuestionAnswerer from model path, returns nullptr if the file // doesn't exist or is not a well formatted TFLite model path. Pointer Function(Pointer modelPath) -BertQuestionAnswererFromFile = tflitelib - .lookup>( - 'BertQuestionAnswererFromFile') - .asFunction(); + BertQuestionAnswererFromFile = tflitelib + .lookup>( + 'BertQuestionAnswererFromFile') + .asFunction(); -typedef _BertQuestionAnswererFromFile_native_t = Pointer Function( - Pointer modelPath); +typedef _BertQuestionAnswererFromFile_native_t + = Pointer Function(Pointer modelPath); // Invokes the encapsulated TFLite model and answers a question based on // context. -Pointer Function(Pointer questionAnswerer, - Pointer context, Pointer question) -BertQuestionAnswererAnswer = tflitelib - .lookup>( - 'BertQuestionAnswererAnswer') - .asFunction(); - -typedef _BertQuestionAnswererAnswer_native_t = Pointer Function(Pointer questionAnswerer, - Pointer context, Pointer question); +Pointer Function( + Pointer questionAnswerer, + Pointer context, + Pointer question) BertQuestionAnswererAnswer = + tflitelib + .lookup>( + 'BertQuestionAnswererAnswer') + .asFunction(); + +typedef _BertQuestionAnswererAnswer_native_t + = Pointer Function( + Pointer questionAnswerer, + Pointer context, + Pointer question); // Deletes BertQuestionAnswerer instance -void Function(Pointer) BertQuestionAnswererDelete = tflitelib - .lookup>( - 'BertQuestionAnswererDelete') - .asFunction(); +void Function(Pointer) BertQuestionAnswererDelete = + tflitelib + .lookup>( + 'BertQuestionAnswererDelete') + .asFunction(); -typedef _BertQuestionAnswererDelete_native_t = Void Function(Pointer); +typedef _BertQuestionAnswererDelete_native_t = Void Function( + Pointer); // Deletes BertQuestionAnswererQaAnswers instance -void Function(Pointer) BertQuestionAnswererQaAnswersDelete = tflitelib - .lookup>( - 'BertQuestionAnswererQaAnswersDelete') - .asFunction(); - -typedef _BertQuestionAnswererQaAnswersDelete_native_t = Void Function(Pointer); +void Function(Pointer) BertQuestionAnswererQaAnswersDelete = + tflitelib + .lookup>( + 'BertQuestionAnswererQaAnswersDelete') + .asFunction(); + +typedef _BertQuestionAnswererQaAnswersDelete_native_t = Void Function( + Pointer); diff --git a/lib/src/task/bindings/text/qa/types.dart b/lib/src/task/bindings/text/qa/types.dart index 0f7255d..dcfb676 100644 --- a/lib/src/task/bindings/text/qa/types.dart +++ b/lib/src/task/bindings/text/qa/types.dart @@ -2,9 +2,9 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -class TfLiteBertQuestionAnswerer extends Opaque {} +final class TfLiteBertQuestionAnswerer extends Opaque {} -class TfLiteQaAnswer extends Struct { +final class TfLiteQaAnswer extends Struct { @Int32() external int start; @Int32() @@ -15,7 +15,7 @@ class TfLiteQaAnswer extends Struct { external Pointer text; } -class TfLiteQaAnswers extends Struct { +final class TfLiteQaAnswers extends Struct { @Int32() external int size; diff --git a/lib/src/task/text/nl_classifier/bert_nl_classifier.dart b/lib/src/task/text/nl_classifier/bert_nl_classifier.dart index 9981e16..9ab517d 100644 --- a/lib/src/task/text/nl_classifier/bert_nl_classifier.dart +++ b/lib/src/task/text/nl_classifier/bert_nl_classifier.dart @@ -2,11 +2,11 @@ import 'dart:ffi'; import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:quiver/check.dart'; -import 'package:tflite_flutter_processing/src/common/file_util.dart'; -import 'package:tflite_flutter_processing/src/label/category.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/nl_classifier/bert_nl_classifier.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/nl_classifier/types.dart'; -import 'package:tflite_flutter_processing/src/task/text/nl_classifier/bert_nl_classifier_options.dart'; +import 'package:tflite_flutter_helper/src/common/file_util.dart'; +import 'package:tflite_flutter_helper/src/label/category.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/nl_classifier/bert_nl_classifier.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/nl_classifier/types.dart'; +import 'package:tflite_flutter_helper/src/task/text/nl_classifier/bert_nl_classifier_options.dart'; /// Classifier API for NLClassification tasks with Bert models, categorizes string into different /// classes. The API expects a Bert based TFLite model with metadata populated. diff --git a/lib/src/task/text/nl_classifier/bert_nl_classifier_options.dart b/lib/src/task/text/nl_classifier/bert_nl_classifier_options.dart index 94a9c36..c64eff2 100644 --- a/lib/src/task/text/nl_classifier/bert_nl_classifier_options.dart +++ b/lib/src/task/text/nl_classifier/bert_nl_classifier_options.dart @@ -2,7 +2,7 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:quiver/check.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/nl_classifier/types.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/nl_classifier/types.dart'; /// Options to configure BertNLClassifier. class BertNLClassifierOptions { @@ -16,7 +16,8 @@ class BertNLClassifierOptions { /// Creates a new options instance. factory BertNLClassifierOptions() { - final optionsPtr = TfLiteBertNLClassifierOptions.allocate(DEFAULT_MAX_SEQ_LEN); + final optionsPtr = + TfLiteBertNLClassifierOptions.allocate(DEFAULT_MAX_SEQ_LEN); return BertNLClassifierOptions._(optionsPtr); } diff --git a/lib/src/task/text/nl_classifier/nl_classifier.dart b/lib/src/task/text/nl_classifier/nl_classifier.dart index 80488ce..8a55dd4 100644 --- a/lib/src/task/text/nl_classifier/nl_classifier.dart +++ b/lib/src/task/text/nl_classifier/nl_classifier.dart @@ -2,11 +2,11 @@ import 'dart:ffi'; import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:quiver/check.dart'; -import 'package:tflite_flutter_processing/src/common/file_util.dart'; -import 'package:tflite_flutter_processing/src/label/category.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/nl_classifier/nl_classifer.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/nl_classifier/types.dart'; -import 'package:tflite_flutter_processing/src/task/text/nl_classifier/nl_classifier_options.dart'; +import 'package:tflite_flutter_helper/src/common/file_util.dart'; +import 'package:tflite_flutter_helper/src/label/category.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/nl_classifier/nl_classifer.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/nl_classifier/types.dart'; +import 'package:tflite_flutter_helper/src/task/text/nl_classifier/nl_classifier_options.dart'; /// Classifier API for natural language classification tasks, categorizes string into different /// classes. diff --git a/lib/src/task/text/nl_classifier/nl_classifier_options.dart b/lib/src/task/text/nl_classifier/nl_classifier_options.dart index 3a7cf0c..d24f776 100644 --- a/lib/src/task/text/nl_classifier/nl_classifier_options.dart +++ b/lib/src/task/text/nl_classifier/nl_classifier_options.dart @@ -2,7 +2,7 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:quiver/check.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/nl_classifier/types.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/nl_classifier/types.dart'; /// Options to identify input and output tensors of the model. /// diff --git a/lib/src/task/text/qa/bert_question_answerer.dart b/lib/src/task/text/qa/bert_question_answerer.dart index 490e8f8..ce1e155 100644 --- a/lib/src/task/text/qa/bert_question_answerer.dart +++ b/lib/src/task/text/qa/bert_question_answerer.dart @@ -2,12 +2,12 @@ import 'dart:ffi'; import 'dart:io'; import 'package:quiver/check.dart'; -import 'package:tflite_flutter_processing/src/common/file_util.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/qa/bert_qa.dart'; -import 'package:tflite_flutter_processing/src/task/bindings/text/qa/types.dart'; +import 'package:tflite_flutter_helper/src/common/file_util.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/qa/bert_qa.dart'; +import 'package:tflite_flutter_helper/src/task/bindings/text/qa/types.dart'; import 'package:ffi/ffi.dart'; -import 'package:tflite_flutter_processing/src/task/text/qa/question_answerer.dart'; +import 'package:tflite_flutter_helper/src/task/text/qa/question_answerer.dart'; import 'qa_answer.dart'; diff --git a/lib/src/task/text/qa/question_answerer.dart b/lib/src/task/text/qa/question_answerer.dart index e961312..287aa8c 100644 --- a/lib/src/task/text/qa/question_answerer.dart +++ b/lib/src/task/text/qa/question_answerer.dart @@ -1,4 +1,4 @@ -import 'package:tflite_flutter_processing/src/task/text/qa/qa_answer.dart'; +import 'package:tflite_flutter_helper/src/task/text/qa/qa_answer.dart'; /// API to answer questions based on context. */ abstract class QuestionAnswerer { diff --git a/lib/src/tensorbuffer/tensorbuffer.dart b/lib/src/tensorbuffer/tensorbuffer.dart index f4d350e..925734d 100644 --- a/lib/src/tensorbuffer/tensorbuffer.dart +++ b/lib/src/tensorbuffer/tensorbuffer.dart @@ -1,10 +1,10 @@ import 'dart:typed_data'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; import 'package:meta/meta.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbufferfloat.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbufferuint8.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbufferfloat.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbufferuint8.dart'; /// Represents the data buffer for either a model's input or its output. abstract class TensorBuffer { diff --git a/lib/src/tensorbuffer/tensorbufferfloat.dart b/lib/src/tensorbuffer/tensorbufferfloat.dart index d2cc184..09a5923 100644 --- a/lib/src/tensorbuffer/tensorbufferfloat.dart +++ b/lib/src/tensorbuffer/tensorbufferfloat.dart @@ -1,5 +1,5 @@ import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; import 'tensorbuffer.dart'; diff --git a/lib/src/tensorbuffer/tensorbufferuint8.dart b/lib/src/tensorbuffer/tensorbufferuint8.dart index 17e6d21..df026f3 100644 --- a/lib/src/tensorbuffer/tensorbufferuint8.dart +++ b/lib/src/tensorbuffer/tensorbufferuint8.dart @@ -1,8 +1,8 @@ import 'dart:math'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/support_preconditions.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/common/support_preconditions.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; /// Represents data buffer with 8-bit unsigned integer values. class TensorBufferUint8 extends TensorBuffer { diff --git a/lib/tflite_flutter_processing.dart b/lib/tflite_flutter_helper.dart similarity index 98% rename from lib/tflite_flutter_processing.dart rename to lib/tflite_flutter_helper.dart index 4b3b747..558dd9d 100644 --- a/lib/tflite_flutter_processing.dart +++ b/lib/tflite_flutter_helper.dart @@ -8,7 +8,7 @@ /// input and output of TFLite Models. /// /// API is similar to the TensorFlow Lite Android Support Library. -library tflite_flutter_processing; +library tflite_flutter_helper; export 'src/common/ops/cast_op.dart'; export 'src/common/ops/dequantize_op.dart'; diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 30a9eaf..ab79340 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.10) -set(PROJECT_NAME "tflite_flutter_processing") +set(PROJECT_NAME "tflite_flutter_helper") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed -set(PLUGIN_NAME "tflite_flutter_processing_plugin") +set(PLUGIN_NAME "tflite_flutter_helper_plugin") add_library(${PLUGIN_NAME} SHARED - "tflite_flutter_processing_plugin.cc" + "tflite_flutter_helper_plugin.cc" ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES @@ -19,7 +19,7 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) # List of absolute paths to libraries that should be bundled with the plugin -set(tflite_flutter_processing_bundled_libraries +set(tflite_flutter_helper_bundled_libraries "" PARENT_SCOPE ) diff --git a/linux/include/tflite_flutter_processing/tflite_flutter_processing_plugin.h b/linux/include/tflite_flutter_processing/tflite_flutter_processing_plugin.h index 395a94a..c52ecc3 100644 --- a/linux/include/tflite_flutter_processing/tflite_flutter_processing_plugin.h +++ b/linux/include/tflite_flutter_processing/tflite_flutter_processing_plugin.h @@ -16,9 +16,9 @@ typedef struct { GObjectClass parent_class; } TfliteFlutterHelperPluginClass; -FLUTTER_PLUGIN_EXPORT GType tflite_flutter_processing_plugin_get_type(); +FLUTTER_PLUGIN_EXPORT GType tflite_flutter_helper_plugin_get_type(); -FLUTTER_PLUGIN_EXPORT void tflite_flutter_processing_plugin_register_with_registrar( +FLUTTER_PLUGIN_EXPORT void tflite_flutter_helper_plugin_register_with_registrar( FlPluginRegistrar* registrar); G_END_DECLS diff --git a/linux/tflite_flutter_processing_plugin.cc b/linux/tflite_flutter_processing_plugin.cc index 5547d43..36b0fdd 100644 --- a/linux/tflite_flutter_processing_plugin.cc +++ b/linux/tflite_flutter_processing_plugin.cc @@ -1,4 +1,4 @@ -#include "include/tflite_flutter_processing/tflite_flutter_processing_plugin.h" +#include "include/tflite_flutter_helper/tflite_flutter_helper_plugin.h" #include #include @@ -7,17 +7,17 @@ #include #define TFLITE_FLUTTER_PROCESSING_PLUGIN(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), tflite_flutter_processing_plugin_get_type(), \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), tflite_flutter_helper_plugin_get_type(), \ TfliteFlutterHelperPlugin)) struct _TfliteFlutterHelperPlugin { GObject parent_instance; }; -G_DEFINE_TYPE(TfliteFlutterHelperPlugin, tflite_flutter_processing_plugin, g_object_get_type()) +G_DEFINE_TYPE(TfliteFlutterHelperPlugin, tflite_flutter_helper_plugin, g_object_get_type()) // Called when a method call is received from Flutter. -static void tflite_flutter_processing_plugin_handle_method_call( +static void tflite_flutter_helper_plugin_handle_method_call( TfliteFlutterHelperPlugin* self, FlMethodCall* method_call) { g_autoptr(FlMethodResponse) response = nullptr; @@ -37,30 +37,30 @@ static void tflite_flutter_processing_plugin_handle_method_call( fl_method_call_respond(method_call, response, nullptr); } -static void tflite_flutter_processing_plugin_dispose(GObject* object) { - G_OBJECT_CLASS(tflite_flutter_processing_plugin_parent_class)->dispose(object); +static void tflite_flutter_helper_plugin_dispose(GObject* object) { + G_OBJECT_CLASS(tflite_flutter_helper_plugin_parent_class)->dispose(object); } -static void tflite_flutter_processing_plugin_class_init(TfliteFlutterHelperPluginClass* klass) { - G_OBJECT_CLASS(klass)->dispose = tflite_flutter_processing_plugin_dispose; +static void tflite_flutter_helper_plugin_class_init(TfliteFlutterHelperPluginClass* klass) { + G_OBJECT_CLASS(klass)->dispose = tflite_flutter_helper_plugin_dispose; } -static void tflite_flutter_processing_plugin_init(TfliteFlutterHelperPlugin* self) {} +static void tflite_flutter_helper_plugin_init(TfliteFlutterHelperPlugin* self) {} static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call, gpointer user_data) { TfliteFlutterHelperPlugin* plugin = TFLITE_FLUTTER_PROCESSING_PLUGIN(user_data); - tflite_flutter_processing_plugin_handle_method_call(plugin, method_call); + tflite_flutter_helper_plugin_handle_method_call(plugin, method_call); } -void tflite_flutter_processing_plugin_register_with_registrar(FlPluginRegistrar* registrar) { +void tflite_flutter_helper_plugin_register_with_registrar(FlPluginRegistrar* registrar) { TfliteFlutterHelperPlugin* plugin = TFLITE_FLUTTER_PROCESSING_PLUGIN( - g_object_new(tflite_flutter_processing_plugin_get_type(), nullptr)); + g_object_new(tflite_flutter_helper_plugin_get_type(), nullptr)); g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); g_autoptr(FlMethodChannel) channel = fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar), - "tflite_flutter_processing", + "tflite_flutter_helper", FL_METHOD_CODEC(codec)); fl_method_channel_set_method_call_handler(channel, method_call_cb, g_object_ref(plugin), diff --git a/macos/Classes/TfliteFlutterProcessingPlugin.swift b/macos/Classes/TfliteFlutterProcessingPlugin.swift index 4f1f37e..5d11978 100644 --- a/macos/Classes/TfliteFlutterProcessingPlugin.swift +++ b/macos/Classes/TfliteFlutterProcessingPlugin.swift @@ -3,7 +3,7 @@ import FlutterMacOS public class TfliteFlutterProcessingPlugin: NSObject, FlutterPlugin { public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "tflite_flutter_processing", binaryMessenger: registrar.messenger) + let channel = FlutterMethodChannel(name: "tflite_flutter_helper", binaryMessenger: registrar.messenger) let instance = TfliteFlutterProcessingPlugin() registrar.addMethodCallDelegate(instance, channel: channel) } diff --git a/macos/tflite_flutter_processing.podspec b/macos/tflite_flutter_processing.podspec index c6e6560..c86836c 100644 --- a/macos/tflite_flutter_processing.podspec +++ b/macos/tflite_flutter_processing.podspec @@ -1,9 +1,9 @@ # # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. -# Run `pod lib lint tflite_flutter_processing.podspec` to validate before publishing. +# Run `pod lib lint tflite_flutter_helper.podspec` to validate before publishing. # Pod::Spec.new do |s| - s.name = 'tflite_flutter_processing' + s.name = 'tflite_flutter_helper' s.version = '0.0.1' s.summary = 'A new Flutter project.' s.description = <<-DESC diff --git a/pubspec.lock b/pubspec.lock index 99c35d9..b665298 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -29,26 +29,26 @@ packages: dependency: "direct main" description: name: camera - sha256: "9499cbc2e51d8eb0beadc158b288380037618ce4e30c9acbc4fae1ac3ecb5797" + sha256: "2170a943dcb67be2af2c6bcda8775e74b41d4c02d6a4eb10bdc832ee185c4eea" url: "https://pub.dev" source: hosted - version: "0.10.5+9" - camera_android: + version: "0.11.0+1" + camera_android_camerax: dependency: transitive description: - name: camera_android - sha256: "351429510121d179b9aac5a2e8cb525c3cd6c39f4d709c5f72dfb21726e52371" + name: camera_android_camerax + sha256: "7c03940cb8c92eb5b184952674a07cc4a73c6ba2b3568aad70255ad4cb913660" url: "https://pub.dev" source: hosted - version: "0.10.8+16" + version: "0.6.7+1" camera_avfoundation: dependency: transitive description: name: camera_avfoundation - sha256: "7d0763dfcbf060f56aa254a68c103210280bee9e97bbe4fdef23e257a4f70ab9" + sha256: "95c2f40b4d06cdb0fd2ad893c762d1f2c931a5e370793ec34c939eb4fcbf96bb" url: "https://pub.dev" source: hosted - version: "0.9.14" + version: "0.9.17" camera_platform_interface: dependency: transitive description: @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: camera_web - sha256: f18ccfb33b2a7c49a52ad5aa3f07330b7422faaecbdfd9b9fe8e51182f6ad67d + sha256: b9235ec0a2ce949daec546f1f3d86f05c3921ed31c7d9ab6b7c03214d152fc2d url: "https://pub.dev" source: hosted - version: "0.3.2+4" + version: "0.3.4" characters: dependency: transitive description: @@ -156,10 +156,10 @@ packages: dependency: "direct main" description: name: image - sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e" + sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8" url: "https://pub.dev" source: hosted - version: "4.1.7" + version: "4.2.0" js: dependency: transitive description: @@ -172,26 +172,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" matcher: dependency: transitive description: @@ -212,10 +212,10 @@ packages: dependency: "direct main" description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.12.0" path: dependency: transitive description: @@ -228,10 +228,10 @@ packages: dependency: "direct main" description: name: path_provider - sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b + sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" path_provider_android: dependency: transitive description: @@ -369,10 +369,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" tflite_flutter: dependency: "direct main" description: @@ -409,10 +409,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.1" web: dependency: transitive description: @@ -446,5 +446,5 @@ packages: source: hosted version: "6.5.0" sdks: - dart: ">=3.3.0 <4.0.0" - flutter: ">=3.16.6" + dart: ">=3.4.0 <4.0.0" + flutter: ">=3.22.0" diff --git a/pubspec.yaml b/pubspec.yaml index e33cb6c..f547aad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ -name: tflite_flutter_processing +name: tflite_flutter_helper description: Easy, fast processing and manipulation input and output of TensorFlow Lite Models. -version: 0.4.1 -homepage: https://www.github.com/lucasoskorep/tflite_flutter_processing +version: 0.4.0 +homepage: https://www.github.com/xmartlabs/tflite_flutter_helper environment: - sdk: '>=2.18.0 <4.0.0' - flutter: ">=2.0.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.22.0" dependencies: flutter: @@ -22,18 +22,17 @@ dev_dependencies: flutter_test: sdk: flutter - flutter: plugin: platforms: android: - package: io.chaosdev.tflite_flutter_processing - pluginClass: TfliteFlutterProcessingPlugin + package: com.xmartlabs.tflite_flutter_helper + pluginClass: TfliteFlutterHelperPlugin ios: - pluginClass: TfliteFlutterProcessingPlugin + pluginClass: TfliteFlutterHelperPlugin linux: - pluginClass: TfliteFlutterProcessingPlugin + pluginClass: TfliteFlutterHelperPlugin macos: - pluginClass: TfliteFlutterProcessingPlugin + pluginClass: TfliteFlutterHelperPlugin windows: - pluginClass: TfliteFlutterProcessingPlugin \ No newline at end of file + pluginClass: TfliteFlutterHelperPlugin diff --git a/test/tfliteflutterhelper_test.dart b/test/tfliteflutterhelper_test.dart index 5fafd4b..4470e15 100644 --- a/test/tfliteflutterhelper_test.dart +++ b/test/tfliteflutterhelper_test.dart @@ -5,17 +5,17 @@ import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:image/image.dart'; import 'package:tflite_flutter/tflite_flutter.dart'; -import 'package:tflite_flutter_processing/src/common/file_util.dart'; -import 'package:tflite_flutter_processing/src/common/ops/normailze_op.dart'; -import 'package:tflite_flutter_processing/src/common/tensor_processor.dart'; -import 'package:tflite_flutter_processing/src/image/image_processor.dart'; -import 'package:tflite_flutter_processing/src/image/ops/resize_op.dart'; -import 'package:tflite_flutter_processing/src/image/ops/resize_with_crop_or_pad_op.dart'; -import 'package:tflite_flutter_processing/src/image/ops/rot90_op.dart'; -import 'package:tflite_flutter_processing/src/image/tensor_image.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbuffer.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbufferfloat.dart'; -import 'package:tflite_flutter_processing/src/tensorbuffer/tensorbufferuint8.dart'; +import 'package:tflite_flutter_helper/src/common/file_util.dart'; +import 'package:tflite_flutter_helper/src/common/ops/normailze_op.dart'; +import 'package:tflite_flutter_helper/src/common/tensor_processor.dart'; +import 'package:tflite_flutter_helper/src/image/image_processor.dart'; +import 'package:tflite_flutter_helper/src/image/ops/resize_op.dart'; +import 'package:tflite_flutter_helper/src/image/ops/resize_with_crop_or_pad_op.dart'; +import 'package:tflite_flutter_helper/src/image/ops/rot90_op.dart'; +import 'package:tflite_flutter_helper/src/image/tensor_image.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbuffer.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbufferfloat.dart'; +import 'package:tflite_flutter_helper/src/tensorbuffer/tensorbufferuint8.dart'; const int h = 100; const int w = 150; @@ -160,8 +160,8 @@ void main() { test('load pixels', () { late TensorImage tensorImage = TensorImage(); - tensorImage.loadRgbPixels( - image.getBytes(order: ChannelOrder.rgb), [inputHeight, inputWidth, 3]); + tensorImage.loadRgbPixels(image.getBytes(order: ChannelOrder.rgb), + [inputHeight, inputWidth, 3]); expect(tensorImage.image.height, inputHeight); expect(tensorImage.image.width, inputWidth);