Platform
Resources
Pricing
Sign in
Get started
ohtaman
Workspace
Fork
Published
By
ohtaman
Edited
Jun 2, 2018
Fork of
Visualizing activations of MobileNet with TensorFlow.js
•
1 fork
1 star
Insert cell
Insert cell
Insert cell
viewof
imgSrc
=
{
// Hint: imgur.com has relaxed CORS policies.
const
catSrc
=
'https://raw.githubusercontent.com/tensorflow/tfjs-examples/master/mobilenet/cat.jpg'
;
const
input
=
html
`<input type=text style='width:600px; height: 20px; font-size: 14px'>`
;
input
.
value
=
catSrc
;
return
input
;
}
Insert cell
Insert cell
viewof
webcam
=
html
`<input type=checkbox value=1>`
Insert cell
source
=
{
if
(
webcam
)
{
const
vid
=
html
`<video autoplay="true" id="vid" width=224 height=224></video>`
;
navigator
.
getUserMedia
(
{
video
:
true
}
,
(
stream
)
=>
{
vid
.
src
=
window
.
URL
.
createObjectURL
(
stream
)
;
}
,
(
)
=>
{
}
)
;
return
vid
;
}
else
{
const
img
=
new
Image
(
)
;
img
.
setAttribute
(
'crossorigin'
,
'anonymous'
)
;
img
.
width
=
224
;
img
.
height
=
224
;
img
.
src
=
imgSrc
;
return
img
;
}
}
Insert cell
Insert cell
tf
=
require
(
'@tensorflow/tfjs@0.10.3'
)
Insert cell
model
=
await
tf
.
loadModel
(
'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json'
)
Insert cell
Insert cell
logits
=
{
while
(
true
)
{
yield
tf
.
tidy
(
(
)
=>
{
let
offset
=
tf
.
scalar
(
127.5
)
let
img
=
tf
.
fromPixels
(
source
)
let
inputs
=
img
.
cast
(
'float32'
)
.
sub
(
offset
)
.
div
(
offset
)
.
reshape
(
[
1
,
224
,
224
,
3
]
)
return
model
.
predict
(
inputs
)
.
dataSync
(
)
}
)
}
}
Insert cell
maxProb
=
Math
.
max
.
apply
(
null
,
logits
)
Insert cell
topClass
=
IMAGENET_CLASSES
[
logits
.
indexOf
(
maxProb
)
]
Insert cell
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
imgSrc
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
webcam
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
source
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tf
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
model
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
logits
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
maxProb
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
topClass
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
IMAGENET_CLASSES
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML