Coder Social home page Coder Social logo

shaqian / tflite-react-native Goto Github PK

View Code? Open in Web Editor NEW
286.0 15.0 109.0 64.74 MB

React Native library for TensorFlow Lite

Home Page: https://www.npmjs.com/package/tflite-react-native

License: MIT License

Java 38.23% JavaScript 13.92% Python 2.38% Ruby 1.22% Objective-C 4.69% Objective-C++ 39.39% C++ 0.18%
react react-native tensorflow tflite yolo

tflite-react-native's Introduction

tflite-react-native

A React Native library for accessing TensorFlow Lite API. Supports Classification, Object Detection, Deeplab and PoseNet on both iOS and Android.

Table of Contents

Installation

$ npm install tflite-react-native --save

iOS (only)

TensorFlow Lite is installed using CocoaPods:

  1. Initialize Pod:

    cd ios
    pod init
    
  2. Open Podfile and add:

    target '[your project's name]' do
    	pod 'TensorFlowLite', '1.12.0'
    end
    
  3. Install:

    pod install
    

Automatic link

$ react-native link tflite-react-native

Manual link

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulestflite-react-native and add TfliteReactNative.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libTfliteReactNative.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.reactlibrary.TfliteReactNativePackage; to the imports at the top of the file
  • Add new TfliteReactNativePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':tflite-react-native'
    project(':tflite-react-native').projectDir = new File(rootProject.projectDir,   '../node_modules/tflite-react-native/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':tflite-react-native')
    

Add models to the project

iOS

In XCode, right click on the project folder, click Add Files to "xxx"..., select the model and label files.

Android

  1. In Android Studio (1.0 & above), right-click on the app folder and go to New > Folder > Assets Folder. Click Finish to create the assets folder.

  2. Place the model and label files at app/src/main/assets.

  3. In android/app/build.gradle, add the following setting in android block.

    aaptOptions {
        noCompress 'tflite'
    }

Usage

import Tflite from 'tflite-react-native';

let tflite = new Tflite();

Load model:

tflite.loadModel({
  model: 'models/mobilenet_v1_1.0_224.tflite',// required
  labels: 'models/mobilenet_v1_1.0_224.txt',  // required
  numThreads: 1,                              // defaults to 1  
},
(err, res) => {
  if(err)
    console.log(err);
  else
    console.log(res);
});

Image classification:

tflite.runModelOnImage({
  path: imagePath,  // required
  imageMean: 128.0, // defaults to 127.5
  imageStd: 128.0,  // defaults to 127.5
  numResults: 3,    // defaults to 5
  threshold: 0.05   // defaults to 0.1
},
(err, res) => {
  if(err)
    console.log(err);
  else
    console.log(res);
});
  • Output fomart:
{
  index: 0,
  label: "person",
  confidence: 0.629
}

Object detection:

SSD MobileNet

tflite.detectObjectOnImage({
  path: imagePath,
  model: 'SSDMobileNet',
  imageMean: 127.5,
  imageStd: 127.5,
  threshold: 0.3,       // defaults to 0.1
  numResultsPerClass: 2,// defaults to 5
},
(err, res) => {
  if(err)
    console.log(err);
  else
    console.log(res);
});

Tiny YOLOv2

tflite.detectObjectOnImage({
  path: imagePath,
  model: 'YOLO',
  imageMean: 0.0,
  imageStd: 255.0,
  threshold: 0.3,        // defaults to 0.1
  numResultsPerClass: 2, // defaults to 5
  anchors: [...],        // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828]
  blockSize: 32,         // defaults to 32 
},
(err, res) => {
  if(err)
    console.log(err);
  else
    console.log(res);
});
  • Output fomart:

x, y, w, h are between [0, 1]. You can scale x, w by the width and y, h by the height of the image.

{
  detectedClass: "hot dog",
  confidenceInClass: 0.123,
  rect: {
    x: 0.15,
    y: 0.33,
    w: 0.80,
    h: 0.27
  }
}

Deeplab

tflite.runSegmentationOnImage({
  path: imagePath,
  imageMean: 127.5,      // defaults to 127.5
  imageStd: 127.5,       // defaults to 127.5
  labelColors: [...],    // defaults to https://github.com/shaqian/tflite-react-native/blob/master/index.js#L59
  outputType: "png",     // defaults to "png"
},
(err, res) => {
  if(err)
    console.log(err);
  else
    console.log(res);
});
  • Output format:

    The output of Deeplab inference is Uint8List type. Depending on the outputType used, the output is:

    • (if outputType is png) byte array of a png image

    • (otherwise) byte array of r, g, b, a values of the pixels

PoseNet

Model is from StackOverflow thread.

tflite.runPoseNetOnImage({
  path: imagePath,
  imageMean: 127.5,      // defaults to 127.5
  imageStd: 127.5,       // defaults to 127.5
  numResults: 3,         // defaults to 5
  threshold: 0.8,        // defaults to 0.5
  nmsRadius: 20,         // defaults to 20 
},
(err, res) => {
  if(err)
    console.log(err);
  else
    console.log(res);
});
  • Output format:

x, y are between [0, 1]. You can scale x by the width and y by the height of the image.

[ // array of poses/persons
  { // pose #1
    score: 0.6324902,
    keypoints: {
      0: {
        x: 0.250,
        y: 0.125,
        part: nose,
        score: 0.9971070
      },
      1: {
        x: 0.230,
        y: 0.105,
        part: leftEye,
        score: 0.9978438
      }
      ......
    }
  },
  { // pose #2
    score: 0.32534285,
    keypoints: {
      0: {
        x: 0.402,
        y: 0.538,
        part: nose,
        score: 0.8798978
      },
      1: {
        x: 0.380,
        y: 0.513,
        part: leftEye,
        score: 0.7090239
      }
      ......
    }
  },
  ......
]

Release resources:

tflite.close();

Example

Refer to the example.

tflite-react-native's People

Contributors

ojiofong avatar shaqian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tflite-react-native's Issues

On iOS switching to RN60.0 causes error: React/RCTDefines.h file not found

Switching to RN60.0 the library is not working. I added to Libraries the TfliteReactNative.xcodeproj file and added libTfliteReactNative.a to Build phases. After the build fails, with this issue.

The changes in the switch from RN59.10 to RN60.0 version can be seen here:
https://react-native-community.github.io/upgrade-helper/?from=0.59.10&to=0.60.0

For anyone helping solve the issue:

  • /react-native/React/Base/RCTBridgeModule.h:10:9: 'React/RCTDefines.h' file not found
    • {PROJECT_PATH}/node_modules/tflite-react-native/ios/TfliteReactNative.mm:2:9: In file included from {PROJECT_PATH}/node_modules/tflite-react-native/ios/TfliteReactNative.mm:2:
    • {PROJECT_PATH}/node_modules/tflite-react-native/ios/TfliteReactNative.h:3:9: In file included from {PROJECT_PATH}/node_modules/tflite-react-native/ios/TfliteReactNative.h:3:

On Android things work just as they should.

My guess on the issue:
When we switch to RN60.0 podfile, we lost some of it's includes, and tflite-react-native library on some of these React-Core pods files. But still I don't know what is missing and how to correct it.

Error: Unable to resolve module './LogBoxImages/chevron-left.png' from 'node_modules\react-native\Libraries\LogBox\UI\LogBoxInspectorHeader.js'

Hi, I am facing below mentioned error while trying to run "tflite-react-native\example" using "react-native run-android" with my Android phone connected using USB cable and with USB debugging "on"

image

image

Below is my package.json file in tflite-react-native\example folder:

{
"name": "example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.3",
"react-native": "^0.63.3",
"react-native-image-picker": "0.28.0",
"tflite-react-native": "0.0.5"
},
"devDependencies": {
"babel-core": "7.0.0-bridge.0",
"babel-jest": "24.1.0",
"jest": "24.1.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}

Kindly suggest.

Null is not an object evaluating (TfliteReactNative.loadModel)

Screenshot 2020-07-13 at 12 03 51 PM

dependencies": { "react": "16.13.1", "react-native": "0.63.0", "react-native-image-picker": "^2.3.2", "tflite-react-native": "0.0.5"

target 'TFDemo' do
pod 'TensorFlowLite', '1.12.0'
config = use_native_modules!

/**

Hey Folks ,
I'm facing this issue . Is this a bug or i'm missing any things

Results in ios and android is different for a same model

I am running example app on ios/android devices, using same model, same input image in both side, but the results is not same.

Generally the sequence of topN for Mobilenet is same, but the confidence percentage is a bit off, like testing a train image on android it says 69% but in ios it says 73%

I am also testing on some custom model on image classification as well, we result is more off in that case. In android it says 51%/49% and on ios it says 90%/10%

Is it the code of transforming the image to bitmap is a bit different on ios/android so the result is different?

Support for YOLO v3

First of all, thanks for creating this awesome package. Great work 🎉

Does this package supports YOLO V3 ?

I tried running the tiny YOLO V2 model from demo project. It works well.

When we tried to run YOLO3 keras model converted to tflite, we are not getting result/ detection.

P.S the same converted model is yielding result when we tried to run on standalone server.

tflite object is empty after loading model

Hello!

I followed all the instructions to load a model and I don't get an error. Here is my code for loading a model:

    let tflite = new Tflite();
    tflite.loadModel({
      model: 'models/model.tflite',// required
      labels: 'models/labels.txt',  // required
      numThreads: 1,
      async: false                              // defaults to 1  
    },
    (err, res) => {
      if(err) {
        console.log(err);
      }
      else {
        console.log(res);
        console.log(tflite);
      }
    });

As you can see in the success else block, I console log the tflite object. But it's empty. I figured the loadmodel method would populate it with something?

But in the log, all I get is Tflite {}

Is this correct? Because I am unable to then make calls on image classification with this tflite object I have.

Thanks ahead of time

Access predicted probabilities for image classification

Hi
I've successfully tried your package using my own model for image classification case.
However as you pointed out in the README, the result is a single prediction :

{
  "index": 0,
  "label": "person",
  "confidence": 0.629
}

I would like to know where I should modify your code to get all predicted probabilities. e.g. something like this :

[
{
  "index": 0,
  "label": "person",
  "confidence": 0.6
},
{
  "index": 1,
  "label": "cat",
  "confidence": 0.3
}
{
  "index": 2,
  "label": "dog",
  "confidence": 0.1
}
]

Thanks in advance

TypeError: null is not an object (evaluating 'TfliteReactNative.loadModel')

I am developing an app for ios with react-native CLI, and I am facing a problem loading the model.
I've tried every solution possible on the internet, but it still doesn't work, unfortunately.
Linking is working properly, I've tried manual linking and automatic.
I have my model in src/models.
And in Xcode, it's under MyProject > models.

This is my code:

const initModel = () => {
  const tflite = new Tflite();
  console.log('started initialization of TENSOR FLOW LITE');
  tflite.loadModel(
    {
      model: 'models/model.tflite', // required
      labels: 'models/labels.txt', // required
      numThreads: 1,
      async: false, // defaults to 1
    },
    (err, res) => {
      if (err) {
        console.log(err);
      } else {
        res.runModelOnImage(
          {
            path: pictureUrl, // required
            imageMean: 128.0, // defaults to 127.5
            imageStd: 128.0, // defaults to 127.5
            numResults: 3, // defaults to 5
            threshold: 0.05, // defaults to 0.1
          },
          (err, res) => {
            if (err) console.log(err);
            else setPrediction(res);
          },
        );
      }
    },
  );
};

useEffect(() => {
  initModel();
}, []);

Podfile:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'


target 'ai_app' do
  config = use_native_modules!
  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
    )
    
  pod 'TensorFlowLite', '1.12.0'
  pod 'TfliteReactNative', :path => '../node_modules/tflite-react-native/ios'

  # target 'ai_appTests' do
  #   inherit! :complete
  #   # Pods for testing
  # end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

Metro.config:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  resolver: {
    assetExts: ['tflite', 'txt','png'],
  },
};

Building is successful on Xcode.

Thanks in advance.

Can not run the example app on Android device

I'm trying to build the example app in this repo. When I run react-native run-android without any options, the app successfully runs on the Android emulator, but it fails with --deviceId option to run it on a real Android device. Is there any solution?

Here is the log.

$ git clone https://github.com/shaqian/tflite-react-native.git
$ cd tflite-react-native/example
$ npm install
$ react-native run-android --deviceId XXXXXXXXXXXXX

Starting JS server...
Building the app...

> Configure project :app
WARNING: The specified Android SDK Build Tools version (28.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '28.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-image-picker
WARNING: The specified Android SDK Build Tools version (28.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '28.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :tflite-react-native
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :tflite-react-native:compileDebugJavaWithJavac
Note: /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/src/main/java/com/reactlibrary/TfliteReactNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
bundle: Writing bundle output to: /Users/john/development/tflite-react-native/example/android/app/build/generated/assets/react/release/index.android.bundle
bundle: Done writing bundle output

> Task :tflite-react-native:compileReleaseJavaWithJavac
Note: /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/src/main/java/com/reactlibrary/TfliteReactNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :tflite-react-native:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':tflite-react-native:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  Output:  error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
  error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:7: error: resource android:attr/colorError not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:11: error: resource android:attr/colorError not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:15: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:954: error: resource android:attr/fontStyle not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:955: error: resource android:attr/font not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:956: error: resource android:attr/fontWeight not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:957: error: resource android:attr/fontVariationSettings not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:958: error: resource android:attr/ttcIndex not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:1039: error: resource android:attr/startX not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:1042: error: resource android:attr/startY not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:1045: error: resource android:attr/endX not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:1048: error: resource android:attr/endY not found.
  /Users/john/development/tflite-react-native/example/node_modules/tflite-react-native/android/build/intermediates/res/merged/release/values/values.xml:1056: error: resource android:attr/offset not found.
  error: failed linking references.

  Command: /Users/john/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/a4f31520f4d94325cc40dcb108789e7e/aapt2-3.2.1-4818971-osx/aapt2 link -I\
          /Users/john/Library/Android/sdk/platforms/android-23/android.jar\
          --manifest\ ...
...

My environment

  • tflite-react-native: 0.0.5
  • Platform: Mac OS X 10.13.6
  • Android version (real device): 8.0.0
  • Android version (emulator): 8.0.0
$ react-native info

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
      Memory: 47.34 MB / 8.00 GB
      Shell: 5.5.1 - /usr/local/bin/zsh
    Binaries:
      Node: 10.13.0 - ~/.nodebrew/current/bin/node
      Yarn: 1.17.3 - ~/.nodebrew/current/bin/yarn
      npm: 6.4.1 - ~/.nodebrew/current/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 24, 25, 26, 28, 29
        Build Tools: 28.0.3, 29.0.0, 29.0.2
        System Images: android-26 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.5 AI-191.8026.42.35.5900203
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.4 => 0.58.4 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Thanks.

iOS: null is not an object evaluating TfliteReactNative.loadmodel

First of all, thanks for this awesome project. Had this working on Android but not quite on iOS. The home screen with the buttons shows up. However, clicking on a button results in error: null is not an object evaluating TfliteReactNative.loadmodel

The only change I made was in the Pod file to get the build to succeed.

Pod file:

platform :ios, '9.0'

target 'example' do
  pod 'TensorFlowLite', '1.12.0'
  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'

  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

end

My npm version is 6.5.0

Need help with resolving this. Thanks.

Error

Getting length=2; index=3 error while executing runModelOnImage function

here is my package.json file:
"dependencies": {
"@react-native-async-storage/async-storage": "^1.15.9",
"@react-native-firebase/app": "^12.9.2",
"@react-native-firebase/ml": "^12.9.2",
"@tensorflow/tfjs-react-native": "^0.7.0",
"react": "17.0.2",
"react-native": "0.66.1",
"react-native-camera": "^4.2.1",
"react-native-firebase-mlkit": "^0.6.2",
"react-native-fs": "^2.18.0",
"react-native-image-picker": "^4.1.2",
"react-native-permissions": "^3.1.0",
"react-native-vision-object-detection": "0.0.8",
"tflite-react-native": "0.0.5"
}

Help nedded.

Unable to load tflite model in iOS.

Hi, I am trying to add this library to my project. For android given instructions are working. But for iOS i tried many ways to add library but i am getting null is not an object evaluating (TfliteReactNative.loadModel).

I tried below ways induvidually and failed to load model.

  1. Xcode -> MyProject -> ProjectFolder -> Right Click -> Add filed to "My project" -> Disabled Copy items if needed and Enabled Create groups -> Selected models folder(which contains model.tflite and label.txt files).
  2. Xcode -> MyProject -> ProjectFolder -> Right Click -> Add filed to "My project" -> Enabled Copy items if needed and enabled Create groups -> Selected models folder(which contains model.tflite and label.txt files).
  3. Tried to add Directly .tflite and .txt without models folder with above 2 steps.
  4. Drag ad dropping models folder/ files.

Where am i going wrong? Please anyone help me out.

My configurations are:
macOS - 10.15.7
react-native - 0.64.2
tflite-react-native - 0.0.5

pods:
TensorFlowLite (1.13.1)
TfliteReactNative (0.0.4)

Thanks in advance.

detectObjectOnImage for model with 1 class detects maximum 10 occurences

Hi,

Thank you for this library!
I am using my own trained object-detection model (using "SSD Inception v1 coco" as a starting point).
I have only 1 class, and the goal is to count the number of occurences of that item in a picture.

My issue is the following: running the tflite model returns only a maximum of 10 occurences.
Even if I set 'numResultsPerClass' to a number higher than 10, I still get only a maximum of 10 occurences:

My code:

tflite.detectObjectOnImage( { path: imagePath, model: 'SSDMobileNet', imageMean: 127.5, imageStd: 127.5, threshold: 0.5, numResultsPerClass: 60 }, (err: Error, res: any) => { if (err) { reject(err); } else { resolve(res); } } );

Could you please help me find what is causing this?
Thanks!

Warning: Configure project :tflite-react-native

The following warning comes when I include tflite in react native project for android.

WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.2.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

Error on tensor allocations (TFLite_Detection_PostProcess)

Hi,

I'm getting this error on loading model. First I used my trained tflite file, then I downloaded original tensorflow tflite example from website and it gives same error.
Not sure is it related with me but do you guys have any idea?

image

EXC_BAD_ACCESS error on IOS

I'm using custom SSD model (I tried my own and three other models that were trained by users)

They work fine in Android, but in IOS it fails here:

if (interpreter->AllocateTensors() != kTfLiteOk) {
    callback(@[@"Failed to allocate tensors!"]);
  }

With EXC_BAD_ACCESS

When I use ssd_mobilenet.tflite from model Zoo IOS does not throw error

getting a dependency conflict when installing tflite-react-native

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react-native
npm ERR! react-native@"0.71.8" from the root project
npm ERR! peer react-native@"*" from @react-native-community/[email protected]
npm ERR! node_modules/@react-native-community/geolocation
npm ERR! @react-native-community/geolocation@"^3.0.6" from the root project
npm ERR! 13 more (@react-native-community/masked-view, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native@"^0.41.2" from [email protected]
npm ERR! node_modules/tflite-react-native
npm ERR! tflite-react-native@"^0.0.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react-native
npm ERR! peer react-native@"^0.41.2" from [email protected]
npm ERR! node_modules/tflite-react-native
npm ERR! tflite-react-native@"^0.0.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\PC\AppData\Local\

Inconsistent results in model classification

First of all thank you for your code!

I've converted a classification model to tflite and I'm trying to run it using your lib but the results do not match. I've already verified the conversion (running the .tflite in Python) and it's ok. Thus I believe it could be a pre-processing fault.

I don't know much about Java but from what I've understood from your code it does the following:

  1. Loads the image given a path (in RGB)
  2. Resizes it to the model's input size (implicit determined from the .tflite)
  3. Subtracts the specified mean and divides by the std
  4. Runs the .tflite on the image
  5. Gets the TopK results and filters by the given threshold

Is my assessment correct? The TopK is applied on the raw logits or softmaxed?

My model only needs a RGB 299x299x3 image, where mean and std are 127.5 but even so I cannot reproduce the results.

Thank you for your time

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.