question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load model using asyncStorageIO API in react-native

See original GitHub issue

To get help from the community, we encourage using Stack Overflow and the tensorflow.js tag.

TensorFlow.js version

0.3.0

Browser version

React Native: v0.61.5

Describe the problem or feature request

I am getting the following error while loading a model using AsyncStorageIO API.

Row too big to fit into CursorWindow requiredPos=0, totalRows=1
* http://192.168.1.7:19001/index.bundle?platform=android&dev=true&minify=false&hot=false:203062:24 in convertError
* [native code]:null in map
- node_modules/@react-native-community/async-storage/src/AsyncStorage.native.js:97:32 in RCTAsyncStorage.multiGet$argument_1
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:483:4 in __invokeCallback
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:28 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:17 in __guard$argument_0
* [native code]:null in invokeCallbackAndReturnFlushedQueue

In my project, I have a model with json and weights which I have loaded using bundleResourceIO API. Then, I am updating the model using the given code and saving it with asyncStorageIO API. This flow goes well and good. But, I try to load the model using asyncStorageIO API, I get the previously described error.

 const optimizer = tf.train.adam();
      model.compile({
        optimizer: optimizer,
        loss: "categoricalCrossentropy",
        metrics: ["accuracy"],
      });
model
        .trainOnBatch(
          tf
            .tensor2d(imageTensors, [numOfElems, 784])
            .reshape([numOfElems, 28, 28, 1]),
          tf.tensor2d(labelTensors, [numOfElems, 10]).reshape([numOfElems, 10])
        )
        .then((d) => {
          console.log("Model updated");
          model
            .save(asyncStorageIO("mnist-model"))
            .then((res) => console.log("Model Saved", res))
            .catch((e) => console.log(e));
        });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
geetesh-guptacommented, Jul 15, 2020

Hi, thanks for your responses 😊. Currently due to time constraint, I created a different model with less layers that can work with the project, so reducing the size to 172 KB. But, when I will get time, I will try to incorporate the above suggested solutions and will respond back.

0reactions
nixoschucommented, Oct 15, 2021

Hey, sorry for bringing this up again, but I have the same problem as @geetesh-gupta on Android only. iOS works just fine.

For the first run, I download my model directly from the cloud using const model = tf.loadLayersModel(modelUri). Then, I save it on asyncStorage doing model.save(asyncStorageIO('custom-model')). For the second run and on, I have a logic to check if I have any model saved on the asyncStorage and load it if there is. This is working very nicely on iOS, though I’m facing the same problems that @geetesh-gupta reported on Android.

I have a 20MB sized TF custom model. I have updated my gradle.properties file, as @tafsiri suggested from the AsyncStorage docs, to have a max of 50 MB in the SQLite DB: AsyncStorage_db_size_in_MB=50, but even though, it looks like this is an inner limitation of SQLite that can only work with a maximum 2MB in the Cursor Window buffer.

Even though it feels like I can save the model in the first trial, when I try to load it I get this: [Error: Row too big to fit into CursorWindow requiredPos=0, totalRows=1]

And if I try to save again the Model with the same path Key (to overwrite it), then I get this: Out of memory stringify@[native code]

@tafsiri - right now, I’m trying to save/retrieve model to the FileSystem, using react-native-fs. Do you think this approach could work? Or do you have any other workaround suggestion?

Best regards.

Exact same for me, my model is 12MB

Read more comments on GitHub >

github_iconTop Results From Across the Web

asyncstorage not working in build mode in react native
in debug mode asyncstorage working perfectly fine but when build apk with this command. gradlew assembleRelease -x bundleReleaseJsAndAssets ...
Read more >
AsyncStorage - React Native
The AsyncStorage JavaScript code is a facade that provides a clear JavaScript API, real Error objects, and non-multi functions.
Read more >
How To Use React Native AsyncStorage - JScrambler Blog
AsyncStorage is a simple, asynchronous, unencrypted by default module that allows you to persist data offline in React Native apps.
Read more >
A guide to React Native's AsyncStorage - LogRocket Blog
AsyncStorage is an unencrypted and asynchronous data storage system in React Native that allows users to persist data offline.
Read more >
Storing and Getting Data from Async Storage in React Native
In this video, we look at storing and getting data from async storage in react native for our todo app. Part 2. GET...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found