nsfwjs icon indicating copy to clipboard operation
nsfwjs copied to clipboard

Supporting model load from indexeddb

Open morganric opened this issue 5 years ago • 2 comments

https://github.com/infinitered/nsfwjs/blob/ebcd41c46087a3f42c6577f96acc53d7a934b068/src/index.ts#L68

Hello, it seems, although not explicit I can save the model to different schemas by referencing the underlying "model" attribute in the model returned by nsfwjs.load() e.g.

nsfwjs.load(path).then(function (newModel) { console.log("path", path); if(newModel) { newModel.model.save('indexeddb://' + SOME_KEY); } }).catch(error => { console.error('onRejected function called: ' + error.message); })

However, I am unable to then reload the model from say an indexeddb location using:

nsfwjs.load('indexeddb://' + SOME_KEY) as the line above in the code just checks for a string, assumes it's a url or relative path, rather than another schema location and them appends 'model.js'.

I think tf.js supports loading and saving to other schemas, it'd be cool if NSFWJS followed suit ...

morganric avatar Oct 24 '20 21:10 morganric

Agreed. I think the best plan of action would be URL unless it detects something like indexeddb: or even localstorage:

Would you be interested in providing the PR with updated docs/tests/code?

GantMan avatar Oct 25 '20 03:10 GantMan

reference for whomever provides the code: https://www.tensorflow.org/js/guide/save_load

GantMan avatar Oct 25 '20 03:10 GantMan