This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from keras.backend.tensorflow_backend import set_session | |
config = tf.ConfigProto() | |
config.gpu_options.per_process_gpu_memory_fraction = 0.33 | |
set_session(tf.Session(config=config)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import HTML | |
import os, base64 | |
def GetLink(fname): | |
with open(fname, 'rb') as f: | |
data = base64.b64encode(f.read()) | |
return HTML('<a href="data:application/binary;base64,{0}" download={1}>{1}</a>'.format(data.decode(), os.path.basename(fname))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCallBack(Callback): | |
def __init__(self, x_v, y_v): | |
super(MyCallBack, self).__init__() | |
self.x_v, self.y_v = x_v, y_v | |
self.ps = [] | |
def on_epoch_end(self, epoch, logs={}): | |
p = self.model.predict(self.x_v).flatten() | |
self.ps.append(p) | |
logs['val_loss'] = log_loss(self.x_y, p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import optimizers | |
from keras import losses | |
import numpy as np | |
input_img_data = np.random.random((1,) + K.int_shape(model.inputs[0])[1:]) | |
input_img = K.variable(input_img_data) | |
inp = Input(tensor=input_img, batch_shape=input_img_data.shape) | |
out = model(inp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.python.client import timeline | |
from keras import backend as K | |
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) | |
run_metadata = tf.RunMetadata() | |
model = ... # A Keras model | |
fn = K.function(model.inputs, model.outputs, options=run_options, run_metadata=run_metadata) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.cm as cm | |
from itertools import product, count | |
# generate uniform unit vectors | |
def generate_grid_vectors(n): | |
'Generates matrix NxN of unit length vectors' | |
v = np.random.uniform(-1, 1, (n, n, 2)) |
NewerOlder