Skip to content

Instantly share code, notes, and snippets.

View zmjjmz's full-sized avatar

Zachary Jablons zmjjmz

View GitHub Profile
@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
@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 / 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 / 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_unconsumed_out_repro.py
Created August 22, 2018 21:50
Keras unconsumed output failure reproduction script.
import numpy
import tensorflow
print("Tensorflow version: {0}".format(tensorflow.VERSION))
DATA_SIZE = 1024
BATCH_SIZE = 32
N_EPOCHS = 1
EMBED_DIM = 100
@zmjjmz
zmjjmz / keras_summary_repro.py
Created August 31, 2018 01:35
Demonstration of keras summary writing bug
import glob
import os
import shutil
import numpy
import tensorflow
import pandas as pd
from tensorflow.python.estimator.export.export_output import PredictOutput
from tensorflow.python.saved_model import signature_constants
from protobuf_to_dict import protobuf_to_dict
@zmjjmz
zmjjmz / sagemaker_multiin_repro.py
Created September 11, 2018 23:28
Sagemaker Multi-input repro
import os
import json
import numpy
import tensorflow
from tensorflow.python.estimator.export.export import build_raw_serving_input_receiver_fn
print("Tensorflow version: {0}".format(tensorflow.VERSION))
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
@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)`
@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 / tf2_upgrade_test.py
Created March 7, 2019 23:39
TF2 Upgrade Script testing - part 1
import itertools
import numpy
import tensorflow
class TokenizeLookupLayer(tensorflow.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