nsfwjs
nsfwjs copied to clipboard
Different scores from browser and server recognition under the same model
The image I used is this one: https://www.pixiv.net/artworks/80908440 The model uses this: https://github.com/infinitered/nsfwjs/tree/master/example/nsfw_demo/public/model
The result returned on https://nsfwjs.com/ is:
But the result I get using the model on the server is:
{
"className": "Drawing",
"probability": 0.8200194835662842
},
{
"className": "Hentai",
"probability": 0.17648540437221527
},
{
"className": "Porn",
"probability": 0.002067374065518379
},
{
"className": "Neutral",
"probability": 0.0013537625782191753
},
{
"className": "Sexy",
"probability": 0.00007402057235594839
}
The code used in the backend is the sample code in the README.md。
_model = await nsfw.load('/model/', { size: 299 })
I'm not very familiar with tensorflow,I wonder why I get different results, it seems that the browser recognition is more accurate. How can I get more accurate results in the server ?
So the code from the readme needs to be update to use TSNode which will encode the images the same.
Try: https://js.tensorflow.org/api_node/3.18.0/
Let me know if that matches
So the code from the readme needs to be update to use TSNode which will encode the images the same.
Try: https://js.tensorflow.org/api_node/3.18.0/
Let me know if that matches
I try to change const image = await convert(req.file.buffer)
to const image = await tf.node.decodeJpeg(req.file.buffer)
in the sample code, the result obtained is:
{
"className": "Drawing",
"probability": 0.8348554968833923
},
{
"className": "Hentai",
"probability": 0.16166625916957855
},
{
"className": "Porn",
"probability": 0.0019792686216533184
},
{
"className": "Neutral",
"probability": 0.0014262152835726738
},
{
"className": "Sexy",
"probability": 0.00007269137859111652
}
There doesn't seem to be a big change in the results , I'm not very familiar with these, not sure if what I've modified is as you said
i had the same problem. and I noticed that the detection changes completely if the image has a slight difference in resolution. I used a 500x500 image to test and then I tested the same image but reduced to 400x400. detection dropped dramatically (from ~0.90 to ~0.60).
a very big difference for the same image with minimal size difference
Hello @GantMan,
I have the same issue. I think server-side nsfwjs not working (or tutorial not working). I have tested with;
- 3 models
- Your convert function and tf decodeImage
- tfjs-node version 3.18.0
Results are not same with nsfwjs.com. It's not about %1-2 difference, they are totally different. If you want anything, I can test it to help fix the issue.
Best regards.
This seems like it must be a bug with tfjs-node - I can't think of anything specifically that is causing the issue.
Can you check on tfjs-node for differences?
In 2023, this issue still exists. Does anyone have any ideas or solutions?