Skip to content

Instantly share code, notes, and snippets.

View zmjjmz's full-sized avatar

Zachary Jablons zmjjmz

View GitHub Profile
@zmjjmz
zmjjmz / keras_multiout_traditional_partial.py
Created August 22, 2018 21:28
Example of conditional outputs for estimators (partial)
# just the fn from model_store that takes:
model_builder = model_class(model_artifacts, **model_parameters)
model_builder.build_model(inp_placeholder)
# dict of tensors like {'softmax':softmax_layer, 'oov_code':oov_code}
tensors = model_builder.give_outputs()
if mode == tensorflow.estimator.ModeKeys.PREDICT:
return tensorflow.estimator.EstimatorSpec(
mode=mode,
predictions=tensors,
@zmjjmz
zmjjmz / keras_learningphase_leak.py
Created May 18, 2018 22:15
Keras learning phase leak
import os
import psutil
import numpy
import tensorflow
from tensorflow.python.keras._impl import keras
from tensorflow.python.keras._impl.keras.backend import _GRAPH_LEARNING_PHASES
print("Tensorflow version: {0}".format(tensorflow.VERSION))
@zmjjmz
zmjjmz / endtoend_estimator_keras_repro_2.py
Created January 26, 2018 20:41
keras export outputs issue
from __future__ import division
import os
import numpy
import tensorflow as tf
from tensorflow.python.estimator.export.export_output import PredictOutput
from tensorflow.python.estimator.export.export import build_raw_serving_input_receiver_fn
from tensorflow.python.saved_model import signature_constants
from tensorflow.python import debug as tf_debug
@zmjjmz
zmjjmz / endtoend_estimator_keras_repro.py
Created January 26, 2018 16:33
Keras estimator bug repro
from __future__ import division
import os
import numpy
import tensorflow
from tensorflow.python.keras._impl import keras
from tensorflow.python.estimator.export.export_output import PredictOutput
from tensorflow.python.estimator.export.export import build_raw_serving_input_receiver_fn
from tensorflow.python.saved_model import signature_constants
@zmjjmz
zmjjmz / endtoend_estimator_keras_repro.py
Created January 25, 2018 03:06
keras estimator weirdness.
from __future__ import division
import urlparse
import os
import numpy
import boto3
import tensorflow
from tensorflow.python.keras._impl import keras
from tensorflow.python.estimator.export.export_output import PredictOutput
from __future__ import division
import urlparse
import os
import numpy
import boto3
import tensorflow
from tensorflow.python.keras._impl import keras
from tensorflow.python.estimator.export.export_output import PredictOutput
@zmjjmz
zmjjmz / tfweight_repro_good.txt
Created December 20, 2017 19:05
tf weight repro no global
Using TensorFlow backend.
2017-12-20 14:04:22.144670: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
output from keras
[[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]]
[[ 0. 0. 0.]
@zmjjmz
zmjjmz / tfweight_repro_bad.txt
Created December 20, 2017 19:03
tfweight repro global included output
Using TensorFlow backend.
2017-12-20 14:02:35.782187: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
output from keras
[[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]]
[[ 0. 0. 0.]
@zmjjmz
zmjjmz / tf_weight_repro_new.py
Last active December 20, 2017 19:00
TF weight discrepancy repro code
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
@zmjjmz
zmjjmz / ml_utils.py
Created December 19, 2017 18:23
shitty lookup layer
class TokenizeLookupLayer(keras.layers.Layer):
"""
Layer that encapsulates the following:
- Tokenizing sentences by space (or given delimiter)
- Looking up the words with a given vocabulary list / table
- Resetting the shape of the above to be batch_size x pad_len (using dark magic)
# Input Shape
2D string tensor with shape `(batch_size, 1)`
# Output Shape
2D int32 tensor with shape `(batch_size, pad_len)`