Skip to content

Instantly share code, notes, and snippets.

View andrehuang's full-sized avatar
🎯
Focusing

Haiwen Huang andrehuang

🎯
Focusing
View GitHub Profile
import tensorflow as tf
from tensorflow.python.framework import ops
import numpy as np
# Define custom py_func which takes also a grad op as argument:
def py_func(func, inp, Tout, stateful=True, name=None, grad=None):
# Need to generate a unique name to avoid duplicates:
rnd_name = 'PyFuncGrad' + str(np.random.randint(0, 1E+8))