Skip to content

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

@anand654

Description

@anand654

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
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.3.0/dist/tf.min.js"></script>
<script src="https://unpkg.com/nsfwjs@2.3.0/dist/nsfwjs.min.js"></script>

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions