GithubHelp home page GithubHelp logo

Comments (6)

arkty avatar arkty commented on July 30, 2024 1

@camhart may be you will find this helpful. As @TechnikEmpire said, TFLite file is already included in the latest model.
All you need is to configure image processor params for this model. Input has type float32[1,224,224,3],so we need to resize image and normalize it.

val image: Bitmap // your image

private val imageProcessor = ImageProcessor.Builder()
        .add(ResizeOp(224, 224, ResizeOp.ResizeMethod.NEAREST_NEIGHBOR))
        .add(NormalizeOp(0f, 255f))
        .build()

val buffer = TensorImage(DataType.FLOAT32).let {
        it.load(image)
        imageProcessor.process(it)
}.tensorBuffer

val outputs = model.process(buffer).outputFeature0AsTensorBuffer

You can find more details in project NsfwDetectHelper.kt

from nsfw_model.

camhart avatar camhart commented on July 30, 2024

https://www.tensorflow.org/lite/convert/cmdline_examples

Has some helpful examples, but they go a bit over my head. Anyone have any suggestions how to convert NSFWJS models to tflite? I'd err on the side of speed over accuracy (assuming the drop in accuracy isn't too significant).

This makes me think I should use the quantized model and then run something similar to the following:

tflite_convert \
  --output_file=/tmp/foo.tflite \
  --graph_def_file=/tmp/some_quantized_graph.pb \    //this would be the NSFWJS quantized model
  --inference_type=QUANTIZED_UINT8 \                       // keep this the same
  --input_arrays=input \                                                  // not sure here--would this stay the same?
  --output_arrays=MobilenetV1/Predictions/Reshape_1 \    //not sure here--would this stay the same?
  --mean_values=128 \                                                          //not sure
  --std_dev_values=127                                                         //not sure

from nsfw_model.

camhart avatar camhart commented on July 30, 2024

Using https://lutzroeder.github.io/netron/ my guess would be input_1 may be the input_array and dense_3 would be the output_array. However when I try this I get the following:

ValueError: Invalid tensors 'dense_3' were found.

Edit: Looks like it's dense_3/Softmax

from nsfw_model.

MuhammadIbrahimSE avatar MuhammadIbrahimSE commented on July 30, 2024

Hi @camhart did you convert it successfully and integrated it with android, can you please share the file and android repo.

from nsfw_model.

TechnikEmpire avatar TechnikEmpire commented on July 30, 2024

In the latest model, there is a TFLite model already in there. You can simply open the model(s) in Netron and see what the input names are and what the output layer is.

With regards to your accuracy issue, don't apply mean substraction and ensure the scale is 255. I ran into this as well converting the model to another inference engine.

from nsfw_model.

colindean avatar colindean commented on July 30, 2024

If this is still a problem, please provide the version of nsfw_detector that you're using, your Python version, your Python platform, and a code example of how you're invoking nsfw_detector, and reopen the issue.

from nsfw_model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.