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 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 |
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
| model.modules[1].parameters = function() return nil end -- freezes the layer when using optim | |
| model.modules[1].accGradParameters = function() end -- overwrite this to reduce computations |
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
| -- multiple learning rates per network. Optimizes two copies of a model network and checks if the optimization steps (2) and (3) produce the same weights/parameters. | |
| require 'torch' | |
| require 'nn' | |
| require 'optim' | |
| torch.setdefaulttensortype('torch.FloatTensor') | |
| -- (1) Define a model for this example. | |
| local model = nn.Sequential() | |
| model:add(nn.Linear(10,20)) |
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
| -- multiple learning rates per network. Optimizes two copies of a model network and checks if the optimization steps (2) and (3) produce the same weights/parameters. | |
| require 'torch' | |
| require 'nn' | |
| require 'optim' | |
| torch.setdefaulttensortype('torch.FloatTensor') | |
| -- (1) Define a model for this example. | |
| local model = nn.Sequential() | |
| model:add(nn.Linear(10,20)) |
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
| -- example for an AlexNet-like model | |
| --model, unconverted = loadmatconvnet('/path/to/somemodel.mat', { | |
| -- conv2 = {groups = 2}, | |
| -- conv4 = {groups = 2}, | |
| -- conv5 = {groups = 2}, | |
| -- fc6 = {fc_kH = 6, fc_kW = 6, type = 'nn.Linear'}, --ONE MAY NEED TO BE CAREFUL, these fc_kH, fc_kW are for 1x36 (or 36x1, don't remember) saved weights | |
| -- fc7 = {type = 'nn.Linear'}, | |
| --}) | |
| matio = require 'matio' |