Skip to content

Instantly share code, notes, and snippets.

@VikingPenguinYT
VikingPenguinYT / dropout_bayesian_approximation_tensorflow.py
Last active August 6, 2024 16:09
Implementing Dropout as a Bayesian Approximation in TensorFlow
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.contrib.distributions import Bernoulli
class VariationalDense:
"""Variational Dense Layer Class"""
def __init__(self, n_in, n_out, model_prob, model_lam):
self.model_prob = model_prob
@kdubovikov
kdubovikov / fast_sampling_cython.pyx
Created October 8, 2017 10:22
Fast random subset sampling with Cython
%%cython
import numpy as np
cimport numpy as np
cimport cython # so we can use cython decorators
from cpython cimport bool # type annotation for boolean
# disable index bounds checking and negative indexing for speedups
@cython.wraparound(False)
@cython.boundscheck(False)
cdef cython_get_sample(np.ndarray arr, arr_len, n_iter, int sample_size,
@franktoffel
franktoffel / complex_step_derivative.py
Last active July 18, 2022 02:33
Complex-step derivative approximation (implemented in Python, NumPy, matplotlib)
# coding: utf-8
'''The following code reproduces an example of the paper:
'The Complex-Step Derivative Approximation'
by Joaquim R. R. A. MARTINS, Peter STURDZA and Juan J. Alonso published in 2003.
License: MIT
Author: FJ Navarro Brull
'''
@Breta01
Breta01 / ImportModulesNotebook.ipynb
Last active October 22, 2020 09:02
Example of importing multiple TensorFlow modules
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

TensorFlow Serving in 10 minutes!

TensorFlow SERVING is Googles' recommended way to deploy TensorFlow models. Without proper computer engineering background, it can be quite intimidating, even for people who feel comfortable with TensorFlow itself. Few things that I've found particularly hard were:

  • Tutorial examples have C++ code (which I don't know)
  • Tutorials have Kubernetes, gRPG, Bezel (some of which I saw for the first time)
  • It needs to be compiled. That process takes forever!

After all, it worked just fine. Here I present an easiest possible way to deploy your models with TensorFlow Serving. You will have your self-built model running inside TF-Serving by the end of this tutorial. It will be scalable, and you will be able to query it via REST.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@falcondai
falcondai / guided_relu.py
Last active April 1, 2021 09:12
Tensorflow implementation of guided backpropagation through ReLU
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.ops import gen_nn_ops
@ops.RegisterGradient("GuidedRelu")
def _GuidedReluGrad(op, grad):
return tf.select(0. < grad, gen_nn_ops._relu_grad(grad, op.outputs[0]), tf.zeros(grad.get_shape()))
if __name__ == '__main__':
with tf.Session() as sess: