nsfwjs icon indicating copy to clipboard operation
nsfwjs copied to clipboard

trying to implement nsfwjs model in flutter web but getting same number from predicted array

Open anand654 opened this issue 4 years ago • 2 comments

label : help needed

i am trying to use this nsfwjs model in flutter web by taking reference from this repo github link : https://github.com/AseemWangoo/experiments_with_webtree/master/lib/ml

in this example the mobilenet model is working fine, so i tried to implement this code to nsfwjs model

added these script tag

the closest i got from the below javascript code is

`async function nsfwImageFilter() { const img = document.getElementById('img'); let result = []; const model = await tf.loadLayersModel('assets/model.json'); const pixel = tf.browser.fromPixels(img) const resized = tf.image.resizeBilinear(pixel,[299,299]) const casted = resized.cast('int32') const expanded = casted.expandDims(0)

const predictions= await model.predict(expanded).data();

for(var i = 0; i < predictions.length ; i++){ console.log(predictions[i]) result.push(predictions[i]); } return result; }`

output : [2.982787221427266e-14, 2.053509825745257e-30, 1, 0, 0]

pls help me understand where i am doing it wrong , because for every image the 3rd number of this array is always 1 or ~1

anand654 avatar Mar 28 '21 03:03 anand654

That's strange that it keeps thinking the right model is the 3rd option.

Which model are you using? The 299x299 I see. Have you tried the 224x224 model?

Also, why are you bringing in NSFWJS if you're writing the model.predict code yourself?

GantMan avatar Mar 30 '21 03:03 GantMan

iam sorry for not writing a reply for 11 days,

but nsfwjs tflite model is working great, so i moved my project from flutter web to flutter android & ios applications

this is the error iam getting when i use 224*224 model

Error: Error: layer: Improper config format: {"node":[{"name":"input","op":"Placeholder","attr":{"shape":{"shape":{"dim":[{"size":"-1"},{"size":"224"},{"size":"224"},{"size":"3"}]}},"dtype":{"type":"DTFLOAT"}}}
.
.
.
'className' and 'config' must set.

anand654 avatar Apr 10 '21 07:04 anand654