Skip to content

Instantly share code, notes, and snippets.

View ntakouris's full-sized avatar
🤖
Building robots

Theodoros Ntakouris ntakouris

🤖
Building robots
View GitHub Profile
=== l1_5e-5_quantizable_32_4_3_2 ===
threshold = 0
32 bits => 0.914 top5_acc
4 bits => 0.9115 top5_acc
3 bits => 0.9069 top5_acc
2 bits => 0.8941 top5_acc
threshold = 1e-06
32 bits => 0.914 top5_acc
4 bits => 0.05 top5_acc
=== l1_5e-5_quantizable_32_4_3_2 ===
threshold = 0
32 bits => 0.6823 top1_acc
4 bits => 0.6795 top1_acc
3 bits => 0.6734 top1_acc
2 bits => 0.6377 top1_acc
threshold = 1e-06
32 bits => 0.6823 top1_acc
4 bits => 0.01 top1_acc
3 bits => 0.01 top1_acc
The following are for full precision (fp32) original resnset18:
cifar100 L2 1e-4 - top5 accuracy
unclamped => 0.77
threshold = 1e-08 => 0.77
threshold = 1e-07 => 0.77
threshold = 1e-06 => 0.77
threshold = 1e-05 => 0.77
import os
from functools import partial
from typing import Any, Dict, List, Text
import kerastuner
import tensorflow as tf
import tensorflow.keras.backend as K
import tensorflow_transform as tft
import tensorflow_data_validation as tfdv
from absl import logging
from typing import Dict, Text
import tensorflow as tf
from absl import logging
from tensorflow.keras.layers import (LSTM, Activation, Concatenate, Dense)
import kerastuner
from rnn.constants import (INPUT_FEATURE_KEYS, PREDICT_FEATURE_KEYS,
HP_HIDDEN_LATENT_DIM,
HP_HIDDEN_LAYER_NUM, HP_LR,
HP_PRE_OUTPUT_UNITS,
import tensorflow as tf
import kerastuner
TRAIN_STEPS = 1000
EVAL_STEPS = 100
BATCH_SIZE = 128
INPUT_WINDOW_SIZE = 7
OUTPUT_WINDOW_SIZE = 1
def get_pipeline(data_path: Text,
pyfiles_root: str = None, # parent directory for user modules
tune: bool = False, # do hparam tuning ?
hyper_params_uri: Text = None, # if not, provide some hparams uri
hyperparam_train_args: trainer_pb2.TrainArgs = None,
hyperparam_eval_args: trainer_pb2.EvalArgs = None,
train_args: trainer_pb2.TrainArgs = None,
eval_args: trainer_pb2.EvalArgs = None,
push_args: Dict[Text, Any] = None):
if not pyfiles_root:
def transformed_name(key: Text) -> Text:
return key + '_xf'
def gzip_reader_fn(filenames):
return tf.data.TFRecordDataset(filenames, compression_type='GZIP')
def input_fn(file_pattern, tf_transform_output,
feature_spec,
# feature_keys, input_feature_keys, predict_feature_keys, or anything you like
batch_size=256):
def get_input_graph(input_feature_keys, input_window_size) -> Tuple[Input, tf.keras.layers.Layer]:
transformed_columns = [transformed_name(
key) for key in input_feature_keys]
input_layers = {
colname: Input(name=colname, shape=(
input_window_size), dtype=tf.float32)
for colname in transformed_columns
}
def _get_serve_tf_examples_fn(model, tf_transform_output):
"""Returns a function that parses a serialized tf.Example and applies TFT."""
model.tft_layer = tf_transform_output.transform_features_layer()
@tf.function
def serve_tf_examples_fn(serialized_tf_examples):
"""Returns the output to be used in the serving signature."""
feature_spec = tf_transform_output.raw_feature_spec()
feature_spec.pop(_LABEL_KEY)