def get_samples(model, num_samples, seed=123): srng = utils.srng(seed) prior_samples = model.prior.samplesIshape_srng((num_samples, model.first_p_layer_weights_np().shape[0]), srng) samples = [prior_samples] for layer in model.p_layers[:-1]: samples.append(layer.samplesIx_srng(samples[-1], srng)) samples_function = theano.function([], model.p_layers[-1].meanIx(samples[-1])) return reshape_and_tile_images(samples_function())
def plot_images(images, shape, path, filename): # finally save to file import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt images = utils.reshape_and_tile_images(images, shape) plt.imshow(images, cmap='Greys') plt.axis('off') plt.savefig(path + filename + ".svg", format="svg") plt.close()
def get_samples(model, num_samples, seed=123): srng = utils.srng(seed) prior_samples = model.prior.samplesIshape_srng( (num_samples, model.first_p_layer_weights_np().shape[0]), srng) samples = [prior_samples] for layer in model.p_layers[:-1]: samples.append(layer.samplesIx_srng(samples[-1], srng)) samples_function = theano.function([], model.p_layers[-1].meanIx(samples[-1])) return reshape_and_tile_images(samples_function())
def get_last_p_layer_weights(model): shape = (28, 28) return utils.reshape_and_tile_images(model.last_p_layer_weights_np(), shape=shape)
def get_first_q_layer_weights(model): shape = (28, 28) return utils.reshape_and_tile_images(model.first_q_layer_weights_np().T, shape=shape)
def get_last_p_layer_weights(model): return utils.reshape_and_tile_images(model.last_p_layer_weights_np())
def get_first_q_layer_weights(model): return utils.reshape_and_tile_images(model.first_q_layer_weights_np().T)