Skip to content

Instantly share code, notes, and snippets.

View nkreeger's full-sized avatar

Nick Kreeger nkreeger

  • Minneapolis / St. Paul, MN
View GitHub Profile
@nkreeger
nkreeger / .env
Created October 25, 2018 21:58
.env Docker mesa template file
root=/{pwd}/docker/mesa
project=/{pwd}/docker/mesa/workspace
@nkreeger
nkreeger / Dockerfile
Last active November 27, 2018 17:18
Mesa build env Dockerfile
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
@nkreeger
nkreeger / docker-compose.yml
Last active November 12, 2018 03:48
Mesa-build Docker compose config
version: '2'
services:
rpi_env:
build:
context: .
dockerfile: Dockerfile
image: rpi_env:cpu
env_file:
- .env
# devices:
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';
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);
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});
// 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()
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':
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'}));
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