infinitered / nsfwjs

NSFW detection on the client-side via TensorFlow.js
https://nsfwjs.com/
MIT License
7.94k stars 529 forks source link

type: "graph" vs size: 299 #831

Open ghnp5 opened 6 months ago

ghnp5 commented 6 months ago

Hello

If I'm using this model - https://github.com/infinitered/nsfwjs/tree/master/models/inception_v3

Is it incorrect that I'm loading it this way?

nsfw.load('file://./model/', { size: 299 });


I'm asking because I noticed this in the README:

Model InceptionV3 - [Graph](https://github.com/infinitered/nsfwjs/tree/master/models/mobilenet_v2_mid)

const model = nsfwjs.load("/path/to/different/model/", { type: "graph" });

But because the link is incorrect, I'm not sure which is which.

The correct link for InceptionV2 is here:

Model MobileNetV2Mid - [299x299](https://github.com/infinitered/nsfwjs/tree/master/models/inception_v3)

const model = nsfwjs.load("/path/to/different/model/", { size: 299 });

Thank you!

ghnp5 commented 6 months ago

After updating, I'm also trying to load by just calling:

const nsfw = require('nsfwjs');
(...)
_model_layer = await nsfw.load('InceptionV3');

But I'm getting:

nsfwjs | /dock/node_modules/nsfwjs/dist/cjs/index.js:158 nsfwjs | throw new Error("Could not load the model. Make sure you are importing the model.min.js bundle."); nsfwjs | ^ nsfwjs | nsfwjs | Error: Could not load the model. Make sure you are importing the model.min.js bundle. nsfwjs | at /dock/node_modules/nsfwjs/dist/cjs/index.js:158:27 nsfwjs | at step (/dock/node_modules/nsfwjs/dist/cjs/index.js:56:23) nsfwjs | at Object.throw (/dock/node_modules/nsfwjs/dist/cjs/index.js:37:53) nsfwjs | at rejected (/dock/node_modules/nsfwjs/dist/cjs/index.js:29:65) nsfwjs | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) nsfwjs | nsfwjs | Node.js v21.6.2

If I try using what's in the README, using "graph":

_model_layer = await nsfw.load('file://./model/', { type: "graph" });

I get:

nsfwjs | /dock/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:32096 nsfwjs | this.version = "".concat(graph.versions.producer, ".").concat(graph.versions.minConsumer); nsfwjs | ^ nsfwjs | nsfwjs | TypeError: Cannot read properties of undefined (reading 'producer') nsfwjs | at GraphModel.loadWithWeightMap (/dock/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:32096:49) nsfwjs | at GraphModel.loadSync (/dock/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:32063:21) nsfwjs | at /dock/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:32048:34

So, the only thing that works for me is if I use what I had originally:

_model_layer = await nsfw.load('file://./model/', { size: 299 });

I believe the README is still incorrect, even after the last update you made earlier after my comments in the PR.

Thanks.

AlexUrrutia commented 3 months ago

@ghnp5 same here ...