Skip to content

Instantly share code, notes, and snippets.

View hanneshapke's full-sized avatar

Hannes Hapke hanneshapke

View GitHub Profile
@hanneshapke
hanneshapke / tensorboard.sh
Last active February 12, 2023 18:27
TensorBoard Profiler + TensorFlow Serving
#!/bin/bash
TENSORFLOW_SERVING_VERSION=2.11.0
TENSORFLOW_SERVING_HOSTNAME=serving
TENSORFLOW_SERVING_MODEL_NAME=test_model
INTRA_OP_PARALLELISM=2
INTER_OP_PARALLELISM=2
TENSORBOARD_LOGDIR="/tmp/tensorboard"
DOCKER_PROFILER_TAG=tensorboard_profiler:latest
@hanneshapke
hanneshapke / track_celery.py
Created July 22, 2016 03:41
Decorator for Celery functions to measure the execution time and memory usage
import time
from memory_profiler import memory_usage
import logging
celery_logger = logging.getLogger('celery')
def track_celery(method):
"""
@hanneshapke
hanneshapke / install_gpu_driver_for_tf27.py
Last active April 2, 2022 17:03
Install Nvidia GPU and CUDA Drivers to support TF 2.7-2.8
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@hanneshapke
hanneshapke / redis.py
Created May 24, 2018 21:38
Load word vectors into a redis db
import bz2
import pickle
from django.conf import settings
from djang_redis import get_redis_connection
from tqdm import tqdm
from .constants import GOOGLE_WORD2VEC_MODEL_NAME
@hanneshapke
hanneshapke / example-convolutional-neural-net-with-tf-keras.ipynb
Last active August 23, 2021 17:39
Example Convolutional Neural Net with tf.keras
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hanneshapke
hanneshapke / tfx-pipeline-for-bert-preprocessing.ipynb
Last active August 21, 2021 06:18
TFX Pipeline for Bert Preprocessing.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hanneshapke
hanneshapke / parallelize.py
Created November 1, 2020 01:00
Parallelize data processing
# install job lib
from joblib import Parallel, delayed
import numpy as np
def myfun(p):
return np.linalg.norm(p[0]-p[1])
X = [1,2,3,4]
Y = [6,4,8,1]
@hanneshapke
hanneshapke / tfx_pipeline_for_bert_preprocessing_wo_tf-example.ipynb
Last active June 4, 2020 22:48
TFX_Pipeline_for_Bert_Preprocessing_wo_tf.Example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def _get_serve_tf_examples_fn(model, tf_transform_output):
model.tft_layer = tf_transform_output.transform_features_layer()
@tf.function
def serve_tf_examples_fn(serialized_tf_examples):
feature_spec = tf_transform_output.raw_feature_spec()
feature_spec.pop(_LABEL_KEY)
parsed_features = tf.io.parse_example(serialized_tf_examples, feature_spec)
transformed_features = model.tft_layer(parsed_features)
import tensorflow_hub as hub
BERT_TFHUB_URL = "https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/2"
bert_layer = hub.KerasLayer(handle=BERT_TFHUB_URL, trainable=True)
vocab_file_path = bert_layer.resolved_object.vocab_file.asset_path.numpy()