This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root=/{pwd}/docker/mesa | |
project=/{pwd}/docker/mesa/workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:stretch-backports | |
LABEL maintainer="Nick Kreeger <kreeger@google.com>" | |
# Fix locale in debian | |
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ | |
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 | |
ENV LANG en_US.utf8 | |
# Add arm arch for build packages | |
RUN dpkg --add-architecture armhf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
rpi_env: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
image: rpi_env:cpu | |
env_file: | |
- .env | |
# devices: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/scripts/install.js b/scripts/install.js | |
index 6587991..3af5a6f 100644 | |
--- a/scripts/install.js | |
+++ b/scripts/install.js | |
@@ -37,10 +37,11 @@ const CPU_DARWIN = 'libtensorflow_r1_10_darwin.tar.gz'; | |
const CPU_LINUX = 'libtensorflow_r1_10_linux_cpu.tar.gz'; | |
const GPU_LINUX = 'libtensorflow_r1_10_linux_gpu.tar.gz'; | |
const CPU_WINDOWS = 'libtensorflow_r1_10_windows_cpu.zip'; | |
+const GPU_WINDOWS = 'libtensorflow_r1_10_windows_gpu.zip'; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateHeatmap() { | |
rects.data(generateHeatmapData()); | |
rects | |
.attr('x', (coord) => { return scaleX(coord.x) * CONSTANTS.HEATMAP_SIZE; }) | |
.attr('y', (coord) => { return scaleY(coord.y) * CONSTANTS.HEATMAP_SIZE; }) | |
.attr('width', CONSTANTS.HEATMAP_SIZE) | |
.attr('height', CONSTANTS.HEATMAP_SIZE) | |
.style('fill', (coord) => { | |
if (coord.strike) { | |
return strikeColorScale(coord.value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function predictZone() { | |
const predictions = model.predictOnBatch(predictionMatrix.data); | |
const values = predictions.dataSync(); | |
// Sort each value so the higher prediction is the first element in the array: | |
const results = []; | |
let index = 0; | |
for (let i = 0; i < values.length; i++) { | |
let list = []; | |
list.push({value: values[index++], strike: 0}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Trains and reports loss+accuracy for one batch of training data: | |
async function trainBatch(index) { | |
const history = await model.fit(batches[index].x, batches[index].y, { | |
epochs: 1, | |
shuffle: false, | |
validationData: [batches[index].x, batches[index].y], | |
batchSize: CONSTANTS.BATCH_SIZE | |
}); | |
// Don't block the UI frame by using tf.nextFrame() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = []; | |
csvData.forEach((values) => { | |
// 'logit' data uses the 5 fields: | |
const x = []; | |
x.push(parseFloat(values.px)); | |
x.push(parseFloat(values.pz)); | |
x.push(parseFloat(values.sz_top)); | |
x.push(parseFloat(values.sz_bot)); | |
x.push(parseFloat(values.left_handed_batter)); | |
// The label is simply 'is strike' or 'is ball': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const model = tf.sequential(); | |
// Two fully connected layers with dropout between each: | |
model.add(tf.layers.dense({units: 24, activation: 'relu', inputShape: [5]})); | |
model.add(tf.layers.dropout({rate: 0.01})); | |
model.add(tf.layers.dense({units: 16, activation: 'relu'})); | |
model.add(tf.layers.dropout({rate: 0.01})); | |
// Only two classes: "strike" and "ball": | |
model.add(tf.layers.dense({units: 2, activation: 'softmax'})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
px | pz | sz_top | sz_bot | left_handed_batter | is_strike | |
---|---|---|---|---|---|---|
0.53911291447047 | 2.58721257326413 | 3.621919456338947 | 1.6849794648356244 | 1 | 1 | |
0.185253995350261 | 1.5635593603608 | 3.7237799447316 | 1.8320068318667317 | 0 | 1 | |
0.803388018408266 | 2.26077819347672 | 3.6227808116418068 | 1.6855622410347877 | 0 | 1 | |
0.93011705400413 | 2.41483140448302 | 3.6523741032464905 | 1.777227990061938 | 1 | 1 | |
0.627323597921344 | 2.40464482128051 | 3.5789796232592153 | 1.707844742390911 | 0 | 1 | |
0.27398840848321 | 3.39084709206671 | 3.5627386518120403 | 1.641478162459645 | 1 | 1 | |
0.63449599239141 | 1.98240225645648 | 3.5317091900453974 | 1.693213715035089 | 1 | 1 |