0

I have a model which has 11 shards. For some reason, Chrome fails to load it when it has to perform more than 6 XHR requests. Safari loads all of them without a problem.

chrome fails with 6+ XHR requests

When I edit the model.json to only include 6 shards, the model loads. But of course without all the weights and fails to actually construct the model.

chrome succeeds with only 6 XHR requests

And, of course the script fails when it doesn't have all the needed weights...

The javascript code to load the model:

// index.html
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script>
<script src="main.js"></script>

// main.js
(function () {
    let result = document.getElementById('output');

    async function loadModel() {
        result.innerText = 'Loading model... ⏳';
        const m = await tf.loadLayersModel('model/model.json');
        result.innerText = 'Model loaded! ';
        return m;
    }

    const model = loadModel();
    console.log(model);
})();

Here is a summary of the Keras model. The model is converted from a Python Keras model to tensorflow js version.

tensorflowjs_converter --input_format keras \
'model.h5' \
'model/'
melledijkstra
  • 361
  • 3
  • 17
  • The images show clearly that you have an error in the console regarding the shape of the input your are passing to the model. Though there are some warnings for loading some map files, they are not causing the issue you have. – edkeveked Jun 08 '20 at 16:15
  • @edkeveked as I state, the second image is where I have edited the model.json and only retrieves 6 shards! it's just to show that the XHR requests all finish at that moment. But with 11 it fails! The problem is not the shape. – melledijkstra Jun 11 '20 at 13:27

1 Answers1

0

Browsers limit the max number of concurrent downloads to limit malicious use. You will need to wait for the first few to finish before requesting the other shards.

See this for more context: Max parallel http connections in a browser?

Jason Mayes
  • 301
  • 2
  • 8
  • Interesting! why would the requests not finish in Chrome? Maybe that is a tensorflow specific behaviour. Also interesting that Safari does work. – melledijkstra Jun 13 '20 at 21:04
  • 1
    Oh I see, you are using the TF load model to do this. Hmmm. That should handle this sort of thing as that is how we download our own models in 4MB chunks too. Can you send me a link to your live code so I can share with our team if I can replicate the issue on my side. – Jason Mayes Jun 17 '20 at 20:17
  • Yes, that's it. And it works until 6 shards, after that it fails. And the code to reproduce this is basically this notebook: https://colab.research.google.com/drive/1jDVPtvePS5kPgebrEA-pwTFOSvdOh11S?usp=sharing And the javascript code above is served on Github pages, maybe that also helps! Thank you for your help – melledijkstra Jun 21 '20 at 15:19