Skip to content

Instantly share code, notes, and snippets.

View zmjjmz's full-sized avatar

Zachary Jablons zmjjmz

View GitHub Profile
@zmjjmz
zmjjmz / model_store.py
Created December 7, 2017 17:28
Admittedly janky model.
def keras_avgpool_linear_pad_endtoend(word_map_emb_pair, pad_length,
n_classes, random_seed, oov_thresh=0.9, embed_config={}, model_config={}):
# expect these in the order filter_embeddings returns them
# nastyyy
word_ind_map, embedding_mat = word_map_emb_pair
numpy.random.seed(random_seed)
inp = keras.layers.Input(shape=(1,), name='text', dtype='string')
# assume word_ind_map and embedding_mat has been fucked with according
@zmjjmz
zmjjmz / export_simple.py
Created December 7, 2017 17:26
TF serving export code
def export_keras_model_simple(model, export_dir, version, input_name_map={}, output_name_map={}, model_name=None, conflict_policy='fail',
exclude_outputs=[], verbose=True):
# only supports one input / one output models
# version is supposed to be an uint!
model_format = 'keras'
version_str = str(version)
if datautil.is_valid_path(model):
if verbose:
@zmjjmz
zmjjmz / tfserving_weight_repro.py
Last active November 20, 2017 23:59
Quick script showing that TF serving is serving weights incorrectly with, at least, the Keras embedding layer.
from __future__ import division
import os
import sys
import subprocess
import time
import numpy as np
import tensorflow
from tensorflow.python.tools import inspect_checkpoint
for line in norm_lines:
a = np.cos(line[1])
b = np.sin(line[1])
x0 = a*line[0]
y0 = b*line[0]
#print(a, b)
#print(line[1]*180/np.pi)
#line_func = lambda t: (x0 + b*t, y0 - a*t)
#norm_line_seg = np.hstack([line_func(segment_length), line_func(-1*segment_length)])
norm_line_seg = [x0 - segment_length*b,
a = np.cos(norm_lines[:,1])
b = np.sin(norm_lines[:,1])
x0 = a*norm_lines[:,0]
y0 = b*norm_lines[:,0]
norm_line_segs = np.vstack([x0-segment_length*b,
y0+segment_length*a,
x0+segment_length*b,
y0-segment_length*a]).T
norm_line_segs = np.vectorize(int)(norm_line_segs)
@zmjjmz
zmjjmz / keybase.md
Created February 19, 2014 05:16
verification thingy for keybase.io

Keybase proof

I hereby claim:

  • I am zmjjmz on github.
  • I am zach (https://keybase.io/zach) on keybase.
  • I have the public key with fingerprint 2184 B50B 782E 9A0F 0915  016B 4C67 75A0 5B06 0619

To claim this, I am signing this object: