Skip to content

Instantly share code, notes, and snippets.

View aecker's full-sized avatar

Alexander Ecker aecker

View GitHub Profile
@aecker
aecker / custom_saver.py
Created November 4, 2016 12:24
Tensorflow custom saver that keeps VGG variables out of checkpoint files
class MySaver(tf.train.Saver):
def __init__(self, var_list, extra_vars=None, extra_chkpt_file=None, **kwargs):
super().__init__(var_list=var_list, **kwargs)
self.extra_chkpt_file = extra_chkpt_file
self.extra_saver = tf.train.Saver(var_list=extra_vars)
def restore(self, sess, save_path):
super().restore(sess, save_path)
self.extra_saver.restore(sess, self.extra_chkpt_file)
@aecker
aecker / ve.py
Created October 11, 2016 19:39
Calculation of explainable variance etc.
# Load data
responses_val_raw = np.load(os.path.join(path, 'raw_validation_set.npy'))
prediction = mymodel.prediction()
reps, num_imgs, num_neurons = responses_val_raw.shape
# Calculate normalized noise power
obs_var_raw = (responses_val_raw.var(axis=0, ddof=1)).mean(axis=0)
total_var_raw = responses_val_raw.reshape([-1, num_neurons]).var(axis=0, ddof=1)
nnp = obs_var / total_var