File tree Expand file tree Collapse file tree 6 files changed +5305
-0
lines changed Expand file tree Collapse file tree 6 files changed +5305
-0
lines changed Original file line number Diff line number Diff line change
1
+ # image-to-tensor
2
+
3
+ > Convert pixels to tensors
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
+
15
+ < script src ="./src/index.js "> </ script >
16
+ </ body >
17
+ </ html >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " image-to-tensor" ,
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
+ },
14
+ "devDependencies" : {
15
+ "@babel/core" : " 7.2.0" ,
16
+ "parcel-bundler" : " ^1.6.1"
17
+ },
18
+ "keywords" : []
19
+ }
Original file line number Diff line number Diff line change
1
+ import * as tf from '@tensorflow/tfjs' ;
2
+ import './styles.css' ;
3
+
4
+ const img = new Image ( ) ;
5
+ img . crossOrigin = 'anonymous' ;
6
+ img . src =
7
+ 'https://images.unsplash.com/flagged/photo-1572349854775-e5768e1afb74?ixlib=rb-1.2.1&auto=format&fit=crop&w=1267&q=80' ;
8
+
9
+ img . onload = ( event ) => {
10
+ const imgTensor = tf . browser . fromPixels ( event . target ) ;
11
+ imgTensor . print ( ) ;
12
+
13
+ document . getElementById ( 'app' ) . innerHTML = `
14
+ <code>TensorFlow version: ${ tf . version . tfjs } </code>
15
+ <h1>${ imgTensor . shape [ 1 ] } x${ imgTensor . shape [ 0 ] } </h1>
16
+ <canvas id="printCanvas"></canvas>
17
+ ` ;
18
+
19
+ const printCanvas = document . getElementById ( 'printCanvas' ) ;
20
+ tf . browser . toPixels ( imgTensor , printCanvas ) ;
21
+ } ;
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