Giter VIP home page Giter VIP logo

Comments (8)

bongobongo avatar bongobongo commented on May 17, 2024 1

Thanks a lot for your help.
It's working fine now.

from nsfwjs.

GantMan avatar GantMan commented on May 17, 2024

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.

GantMan avatar GantMan commented on May 17, 2024

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.

bongobongo avatar bongobongo commented on May 17, 2024

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.

GantMan avatar GantMan commented on May 17, 2024

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.

GantMan avatar GantMan commented on May 17, 2024

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.

bongobongo avatar bongobongo commented on May 17, 2024

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.

GantMan avatar GantMan commented on May 17, 2024

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)

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.