Comments (6)
@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.
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.
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.
Hi @camhart did you convert it successfully and integrated it with android, can you please share the file and android repo.
from nsfw_model.
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.
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)
- Not trained on Dildos
- Input img/list
- How to inference use the. pb file of the inceptionv3 model?
- How i load this on Celery worker?
- How to disable spam? HOT 7
- Colab Script For Training
- Cannot download HOT 1
- Nude HOT 1
- Tflite - android studio
- 244 - 299 problem HOT 1
- cant run detection with nsfwjs
- Getting TypeError: Descriptors cannot not be created directly HOT 3
- Incorrect NSFW Classification for Civilization VI Leaders' Images
- ModuleNotFoundError: No module named 'tensorflow.python.training.tracking' HOT 1
- exit with code 4
- i can not pip install on mac m1 chip, with Python 3.9.18
- AttributeError: module 'tensorflow._api.v2.compat.v1' has no attribute 'estimator' HOT 4
- keras related issue
- ModuleNotFoundError: No module named 'tensorflow.python.tools'
- ValueError: saved_model_path must be the valid directory of a saved model to load.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nsfw_model.