Skip to content

Commit d320351

Browse files
jimbojwNikhil Thorat
authored and
Nikhil Thorat
committedMar 29, 2018
Webcam demo style (tensorflow#40)
* implementing updated webcam demo UI style * Making loading message visible * changing status hide from visibility:hidden to display:none * Implementing glow controls
1 parent a4aede3 commit d320351

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed
 

‎webcam-transfer-learning/index.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
<!-- Top -->
3333
<div id="pacman-container">
3434
<div id="logo">
35-
<div id="status">Loading mobilenet...</div>
3635
<div id="logo-l">
3736
<div id="logo-b">
3837
</div>
3938
</div>
4039
</div>
4140
</div>
4241

42+
<div id="status">Loading mobilenet...</div>
43+
4344
<div class="controller-panels" id="controller" style="display:none">
4445

4546
<div class="panel training-panel">
@@ -154,9 +155,7 @@
154155
</div><!-- ./panel-cell -->
155156

156157
</div><!-- /.panel-row -->
157-
158158
<div class="panel-row panel-row-middle">
159-
160159
<div class="panel-cell panel-cell-left">
161160
<div class="thumb-box">
162161
<div class="thumb-box-outer">

‎webcam-transfer-learning/styles.css

+18-1
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ header b {
4949
font-weight: 400;
5050
}
5151

52+
/** Loading message. */
53+
#status {
54+
color: #f8f8f8;
55+
font-weight: 300;
56+
margin: 12px 0;
57+
text-align: center;
58+
}
59+
5260
/* Rules for the pacman game. */
5361
#pacman-container {
5462
background: black;
55-
padding: 25px 0;
63+
padding: 25px 0 40px;
5664
}
5765
#logo {
5866
background: url('https://storage.googleapis.com/tfjs-examples/assets/webcam-transfer-learning/bck.png');
@@ -66,6 +74,8 @@ header b {
6674
#logo #pcm-c {
6775
border-top: none;
6876
margin: 0 auto;
77+
position: relative;
78+
top: 20px;
6979
}
7080
#logo-l {
7181
background: #990;
@@ -282,6 +292,13 @@ header b {
282292
display: inline-block;
283293
padding: 9px;
284294
position: relative;
295+
transition: box-shadow 0.3s;
296+
}
297+
[data-active="up"] .panel-row-top .thumb-box-outer,
298+
[data-active="down"] .panel-row-bottom .thumb-box-outer,
299+
[data-active="left"] .panel-cell-left .thumb-box-outer,
300+
[data-active="right"] .panel-cell-right .thumb-box-outer {
301+
box-shadow: 0 0 4px 4px #ffaa00;
285302
}
286303
.thumb-box-inner {
287304
border: 1px solid #585858;

‎webcam-transfer-learning/ui.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
import * as tf from '@tensorflow/tfjs';
1818

1919
const CONTROLS = ['up', 'down', 'left', 'right'];
20-
const CONTROL_LABELS = ['↑', '↓', '←', '→'];
2120
const CONTROL_CODES = [38, 40, 37, 39];
2221

2322
export function init() {
2423
document.getElementById('controller').style.display = '';
25-
statusElement.style.visibility = 'hidden';
24+
statusElement.style.display = 'none';
2625
}
2726

2827
// Set hyper params from UI values.
@@ -45,7 +44,7 @@ export function startPacman() {
4544

4645
export function predictClass(classId) {
4746
google.pacman.keyPressed(CONTROL_CODES[classId]);
48-
status(CONTROL_LABELS[classId]);
47+
document.body.setAttribute('data-active', CONTROLS[classId]);
4948
}
5049

5150
export function isPredicting() {
@@ -55,10 +54,6 @@ export function donePredicting() {
5554
statusElement.style.visibility = 'hidden';
5655
}
5756

58-
export function status(msg) {
59-
statusElement.innerText = msg;
60-
}
61-
6257
export let addExampleHandler;
6358
export function setExampleHandler(handler) {
6459
addExampleHandler = handler;
@@ -80,9 +75,11 @@ async function handler(label) {
8075
const total = document.getElementById(className + '-total');
8176
while (mouseDown) {
8277
addExampleHandler(label);
78+
document.body.setAttribute('data-active', CONTROLS[label]);
8379
total.innerText = totals[label]++;
8480
await tf.nextFrame();
8581
}
82+
document.body.removeAttribute('data-active');
8683
}
8784

8885
upButton.addEventListener('mousedown', () => handler(0));

0 commit comments

Comments
 (0)
Please sign in to comment.