tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

tfjs-tflite: iOS Out of memory error with Cross-Origin Policy

Open Jove125 opened this issue 2 years ago • 1 comments

Hi,

According to this recomendations, it is necessary setting up cross-origin isolation: https://github.com/tensorflow/tfjs/tree/master/tfjs-backend-wasm#setting-up-cross-origin-isolation

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

After these settings, neural networks on a desktop PC and on android devices begin to work much faster. But the following error occurs on the iPhone (tested on iPhone 6S and 13 Max Pro). How can it be avoided?

Unhandled Promise Rejection: RangeError: Out of memory
promiseEmptyOnRejected — tflite_web_api_cc_threaded.js:287
promiseReactionJob

0

if to remove the server cross-origin settings, then everything works on the iPhone, but slowly.

html code to reproduce error:

<script src="./node_modules/@tensorflow/tfjs-core/dist/tf-core.min.js"></script>
<script src="./node_modules/@tensorflow/tfjs-backend-cpu/dist/tf-backend-cpu.min.js"></script>
<script src="./node_modules/@tensorflow/tfjs-tflite/dist/tf-tflite.min.js"></script>

<script>
var promise = tflite.loadTFLiteModel(modelPath, {numThreads: 4});
</script>

Jove125 avatar Jan 28 '24 21:01 Jove125

This issue still persists one year after with TensorFlow.js version 4.22.0 on iOS Safari browser.

Any update on this issue?

I've reproduced this issue with the following steps:

  1. Cloned a repo,
  2. Started a https server with Cross-Origin Policy on location "e2e/benchmarks",
  3. Opened a web page on an iOS Safari browser,
  4. Selected MobileNetV3 model with tflite backend,
  5. Pressed "Run benchmark",
  6. Message "Error: Out of memory..." occurred.

This issue does not happen on Windows with Firefox and Edge (chromium) browsers. I've also tested this on a Samsung Galaxy S24, S22 and Google Pixel 6 on mobile Chrome browser and there was not a single issue.

If it is not a problem with TensorFlow.js but Safari is there a known workaround for an iOS Safari?

Jukyy avatar Jan 31 '25 10:01 Jukyy