File tree Expand file tree Collapse file tree 6 files changed +5330
-0
lines changed Expand file tree Collapse file tree 6 files changed +5330
-0
lines changed Original file line number Diff line number Diff line change 1+ # [ nsfwjs] ( https://github.com/infinitered/nsfwjs )
2+
3+ > Classify images with ` nsfwjs `
4+
5+ ## Getting Started
6+
7+ ```
8+ yarn
9+ yarn start
10+ ```
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < title > TensorFlow Template</ title >
5+ < meta charset ="UTF-8 " />
6+ < link
7+ rel ="stylesheet "
8+ href ="./node_modules/modern-normalize/modern-normalize.css "
9+ />
10+ </ head >
11+
12+ < body >
13+ < div id ="app "> </ div >
14+ < h2 id ="message "> Detecting image…</ h2 >
15+ < img
16+ id ="image "
17+ crossorigin
18+ src ="https://images.unsplash.com/photo-1492632503949-a31d9972b400?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1267&q=80 "
19+ />
20+
21+ < script src ="./src/index.js "> </ script >
22+ </ body >
23+ </ html >
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " tensorflowjs-template" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.html" ,
6+ "scripts" : {
7+ "start" : " parcel index.html --open" ,
8+ "build" : " parcel build index.html"
9+ },
10+ "dependencies" : {
11+ "@tensorflow/tfjs" : " ^2.0.1" ,
12+ "modern-normalize" : " ^0.7.0" ,
13+ "nsfwjs" : " ^2.2.0"
14+ },
15+ "devDependencies" : {
16+ "@babel/core" : " 7.2.0" ,
17+ "parcel-bundler" : " ^1.6.1"
18+ },
19+ "keywords" : []
20+ }
Original file line number Diff line number Diff line change 1+ import * as tf from '@tensorflow/tfjs' ;
2+ import * as nsfwjs from 'nsfwjs' ;
3+ import './styles.css' ;
4+
5+ document . getElementById ( 'app' ) . innerHTML = `
6+ <code>TensorFlow version: ${ tf . version . tfjs } </code>
7+ ` ;
8+
9+ const targetImage = document . getElementById ( 'image' ) ;
10+ const targetText = document . getElementById ( 'message' ) ;
11+
12+ // Load model from my S3.
13+ // See the section hosting the model files on your site.
14+ nsfwjs . load ( ) . then ( function ( model ) {
15+ model . classify ( targetImage ) . then ( function ( predictions ) {
16+ // Classify the image
17+ targetText . innerHTML = `
18+ <ul>
19+ <li>${ predictions [ 0 ] . className } : ${ predictions [ 0 ] . probability } </li>
20+ <li>${ predictions [ 1 ] . className } : ${ predictions [ 1 ] . probability } </li>
21+ <li>${ predictions [ 2 ] . className } : ${ predictions [ 2 ] . probability } </li>
22+ <li>${ predictions [ 3 ] . className } : ${ predictions [ 3 ] . probability } </li>
23+ <li>${ predictions [ 4 ] . className } : ${ predictions [ 4 ] . probability } </li>
24+ </ul>
25+ ` ;
26+ } ) ;
27+ } ) ;
Original file line number Diff line number Diff line change 1+ body {
2+ padding : 20px 40px ;
3+ }
You can’t perform that action at this time.
0 commit comments