Comments (8)
Thanks a lot for your help.
It's working fine now.
from nsfwjs.
Hi @bongobongo
The Readme has a section titled "How to use the module", which is located here:
https://github.com/infinitered/nsfwjs#how-to-use-the-module
The readme then goes on to describe the API of the module. Can you try these, and if they are not useful for you, could you elaborate on how you are limited?
from nsfwjs.
One more note bongo! I see you saying "web server" so if you're hosting with node (server side), you can use this library there as well. See the FAQ: https://github.com/infinitered/nsfwjs/wiki/FAQ:-NSFW-JS
from nsfwjs.
Okay, but if nsfwjs is just plain client side javascript, then I do not understand why the javascript files is not available here as it should be used on the client side.
Do I need node.js to make this work or not?
No node.js is available on the web-servers I use.
Just using this line client side:
import * as nsfwjs from 'nsfwjs';
gives this error in javascript:
"Unexpected token *"
from nsfwjs.
ok good just client side JavaScript.
No need for node if you're hosting the files for client JS.
Is your JavaScript es6+? Are you looking to use script tags? It sounds to me like you need a non NPM example.
from nsfwjs.
Here, I've made the simplest possible example: Please let me know if this helps.
https://github.com/infinitered/nsfwjs/blob/master/example/minimal_demo/index.html
<!-- Load TensorFlow.js. This is required -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"></script>
<!-- Load the NSFWJS library. -->
<script src="https://s3.amazonaws.com/ir_public/nsfwjscdn/bundle.js"></script>
<script>
const nsfwjs = require('nsfwjs')
const img = new Image()
img.crossOrigin = 'anonymous'
// some image here
img.src = 'https://i.imgur.com/Kwxetau.jpg'
// Load the model.
nsfwjs.load().then(model => {
// Classify the image.
model.classify(img).then(predictions => {
console.log('Predictions', predictions)
})
})
</script>
<pre>Checkout console.log output for results!</pre>
from nsfwjs.
This is getting closer to something I can use.
The code you provided do work, but:
What I need to do now is to be able to call model.classify in a separate function.
So I tried this:
const nsfwjs = require('nsfwjs')
const model = nsfwjs.load();
Then in function analyzeImage I put this code:
const img = new Image();
img.crossOrigin = 'anonymous';
img.src = 'http://localhost/atest-code/geocode/pixlab/images/35.jpg';
predictions = model.classify(img);
console.log('Predictions: ', predictions);
WHAT happens now is that I click a button which run the analyzeImage function, I get this error:
"model.classify is not a function"
So how do I use the "model.classify(img)" from within a function like this?
I would not like to load the model each time an image is classified, if possible to avoid.
from nsfwjs.
So the issue looks like scope.
One way to keep a reference to a variable is to fasten it on your global window object. Like
βwindow.model = nsfwjs.load()β
And you can later access it with window.model
from nsfwjs.
Related Issues (20)
- Android Client HOT 2
- [False Positive]: a little bit funny HOT 2
- Which model is the best atm? Resources hardware is not a problem. inception_v4?
- I really need to run this locally for batch processing local images any guides tutorials? HOT 2
- How to use the Inception V3 model in the npm package?
- when adding a frame to an nsfw picture...
- Problem detecting adult content from camera images
- Cant import nsfw in react Project HOT 2
- Logs spammed by tfjs-node launched twice
- Not work local model load HOT 3
- The accuracy is much less than the site HOT 1
- Broken with the recent file on next.js HOT 4
- Error connecting to cloudfront.net since this morning HOT 12
- Publish to npm out of sync HOT 3
- `console.warn` when `BASE_PATH` is used on load
- Remove GIF Support HOT 1
- False Positive HOT 1
- type: "graph" vs size: 299 HOT 1
- Mismatch in the published package content. HOT 1
- MobileNetV2Mid doesn't load HOT 3
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 nsfwjs.