Skip to content

Instantly share code, notes, and snippets.

@Mistobaan
Mistobaan / snippet.py
Created June 6, 2020 05:06
How to add a `key` parameter to serving models signatures in tensorflow
# Serving function that passes through keys
@tf.function(input_signature=[{
'is_male': tf.TensorSpec([None,], dtype=tf.string, name='is_male'),
'mother_age': tf.TensorSpec([None,], dtype=tf.float32, name='mother_age'),
'plurality': tf.TensorSpec([None,], dtype=tf.string, name='plurality'),
'gestation_weeks': tf.TensorSpec([None,], dtype=tf.float32, name='gestation_weeks'),
'key': tf.TensorSpec([None,], dtype=tf.string, name='key')
}])
def my_serve(inputs):
feats = inputs.copy()
@Mistobaan
Mistobaan / snippet.py
Last active June 5, 2020 22:18
Machine Learning Jobs Path Format
import datetime
dt = datetime.datetime.now()
now = dt.strftime('%Y%m%d_%H%M%S')
PROJECT_ID= "my-google-cloud-project-id"
MODEL_NAME='resnet50'
DATASET='imagenet'
EXPERIMENT_NAME=f"{MODEL_NAME}-{DATASET}"
JOB_NAME=f"{EXPERIMENT_NAME}-{now}"
@Mistobaan
Mistobaan / istio-runbookd.md
Last active May 28, 2020 00:05
Istio Run Book

Troubleshooting

Execute the following command to determine if your Kubernetes cluster is running in an environment that supports external load balancers:

kubectl get svc istio-ingressgateway -n istio-system

Ensure that there are no issues with the configuration:

istioctl analyze
# The #power of a good #API #design: implement a whole paper in 2 lines of code and get 3x faster results:
dataset.flat_map( lambda t:
tf.data.Dataset.from_tensors(t).repeat(e))
# from: Faster #NeuralNetwork Training with #Data Echoing https://arxiv.org/pdf/1907.05550.pdf #Tensorflow
# The #power of a good #API #design: implement a whole paper in 2 lines of code and get 3x faster results:
dataset.flat_map( lambda t:
tf.data.Dataset.from_tensors(t).repeat(e))
# from: Faster #NeuralNetwork Training with #Data Echoing https://arxiv.org/pdf/1907.05550.pdf #Tensorflow

05/05/2018

2018: Speech2Vec: A Sequence-to-Sequence Framework for Learning Word Embeddings from Speech

Projects audio files that contains one word of speech into a hyper-dimension space just like Word2Vec. Uses "Force Aligment" to split audio into words (which requires text). Pad the audio segments with zeros, do MFCC, feed into encoder-decoder which uses RMSE. They also add noise to the signal and make the network denoise it. LibriSpeech 500 hour of audio. Not sure how it can incorporated in an ASR or TTS systems. The audio file has to be paired with a text otherwise Speech2Vec cannot split the audio file into words using "Forced Alignment" method. It is used to query if the spoken word is similar to an existing word in the corpus.

2016: Neural Machine Translation of Rare Words with Subword Units (BPE)

BPE data compression tool that combines most frequent pair of bytes with one. It works well with Named Entity, loadwords and morphologically complex words. Handles OOVs well and rare words. You can

from google.cloud import storage
from tensorflow import MetaGraphDef
client = storage.Client()
bucket = client.get_bucket(Config.MODEL_BUCKET)
blob = bucket.get_blob('model.ckpt.meta')
model_graph = blob.download_as_string()
mgd = MetaGraphDef()
mgd.ParseFromString(model_graph)
@Mistobaan
Mistobaan / plot_interactive.py
Created May 11, 2020 05:00
Interactive Plot example
# Create layer slider
# Import all the necessary packages
import numpy as np
import nibabel as nib
from ipywidgets import interact, interactive, IntSlider, ToggleButtons
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set_style('darkgrid')
@Mistobaan
Mistobaan / cutmix.py
Last active May 3, 2020 11:20
Tensorflow Image Augmentation Tips and Tricks
# from https://www.kaggle.com/cdeotte/cutmix-and-mixup-on-gpu-tpu
## CutMix Augmentation¶
# The following code does cutmix using the GPU/TPU.
# Change the variables SWITCH, CUTMIX_PROB and MIXUP_PROB
# in function transform() to control the amount of augmentation during training.
# CutMix will occur SWITCH * CUTMIX_PROB often and
# MixUp will occur (1-SWITCH) * MIXUP_PROB often during training.
def onehot(image,label):
CLASSES = 104
@Mistobaan
Mistobaan / common_callbacks.py
Last active May 5, 2020 04:26
Gists for tf.keras
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint, ReduceLROnPlateau
reduce_lr = ReduceLROnPlateau(
monitor='val_loss',
factor=0.5,
patience=2,
verbose=1,
mode='auto',
min_lr=0.000001)