Python utils.weights_init() Examples
The following are 5
code examples of utils.weights_init().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
utils
, or try the search function
.
Example #1
Source File: __init__.py From Deep-Expander-Networks with GNU General Public License v3.0 | 6 votes |
def setup(model, opt): if opt.criterion == "l1": criterion = nn.L1Loss().cuda() elif opt.criterion == "mse": criterion = nn.MSELoss().cuda() elif opt.criterion == "crossentropy": criterion = nn.CrossEntropyLoss().cuda() elif opt.criterion == "hingeEmbedding": criterion = nn.HingeEmbeddingLoss().cuda() elif opt.criterion == "tripletmargin": criterion = nn.TripletMarginLoss(margin = opt.margin, swap = opt.anchorswap).cuda() parameters = filter(lambda p: p.requires_grad, model.parameters()) if opt.optimType == 'sgd': optimizer = optim.SGD(parameters, lr = opt.lr, momentum = opt.momentum, nesterov = opt.nesterov, weight_decay = opt.weightDecay) elif opt.optimType == 'adam': optimizer = optim.Adam(parameters, lr = opt.maxlr, weight_decay = opt.weightDecay) if opt.weight_init: utils.weights_init(model, opt) return model, criterion, optimizer
Example #2
Source File: model.py From dgl with Apache License 2.0 | 5 votes |
def init_weights(self): from utils import weights_init, dgmg_message_weight_init self.graph_embed.apply(weights_init) self.graph_prop.apply(weights_init) self.add_node_agent.apply(weights_init) self.add_edge_agent.apply(weights_init) self.choose_dest_agent.apply(weights_init) self.graph_prop.message_funcs.apply(dgmg_message_weight_init)
Example #3
Source File: model_batch.py From dgl with Apache License 2.0 | 5 votes |
def init_weights(self): from utils import weights_init, dgmg_message_weight_init self.graph_embed.apply(weights_init) self.graph_prop.apply(weights_init) self.add_node_agent.apply(weights_init) self.add_edge_agent.apply(weights_init) self.choose_dest_agent.apply(weights_init) self.graph_prop.message_funcs.apply(dgmg_message_weight_init)
Example #4
Source File: model.py From a3c_continuous with Apache License 2.0 | 5 votes |
def __init__(self, num_inputs, action_space): super(A3C_CONV, self).__init__() self.conv1 = nn.Conv1d(num_inputs, 32, 3, stride=1, padding=1) self.lrelu1 = nn.LeakyReLU(0.1) self.conv2 = nn.Conv1d(32, 32, 3, stride=1, padding=1) self.lrelu2 = nn.LeakyReLU(0.1) self.conv3 = nn.Conv1d(32, 64, 2, stride=1, padding=1) self.lrelu3 = nn.LeakyReLU(0.1) self.conv4 = nn.Conv1d(64, 64, 1, stride=1) self.lrelu4 = nn.LeakyReLU(0.1) self.lstm = nn.LSTMCell(1600, 128) num_outputs = action_space.shape[0] self.critic_linear = nn.Linear(128, 1) self.actor_linear = nn.Linear(128, num_outputs) self.actor_linear2 = nn.Linear(128, num_outputs) self.apply(weights_init) lrelu_gain = nn.init.calculate_gain('leaky_relu') self.conv1.weight.data.mul_(lrelu_gain) self.conv2.weight.data.mul_(lrelu_gain) self.conv3.weight.data.mul_(lrelu_gain) self.conv4.weight.data.mul_(lrelu_gain) self.actor_linear.weight.data = norm_col_init( self.actor_linear.weight.data, 0.01) self.actor_linear.bias.data.fill_(0) self.actor_linear2.weight.data = norm_col_init( self.actor_linear2.weight.data, 0.01) self.actor_linear2.bias.data.fill_(0) self.critic_linear.weight.data = norm_col_init( self.critic_linear.weight.data, 1.0) self.critic_linear.bias.data.fill_(0) self.lstm.bias_ih.data.fill_(0) self.lstm.bias_hh.data.fill_(0) self.train()
Example #5
Source File: model.py From rl_a3c_pytorch with Apache License 2.0 | 5 votes |
def __init__(self, num_inputs, action_space): super(A3Clstm, self).__init__() self.conv1 = nn.Conv2d(num_inputs, 32, 5, stride=1, padding=2) self.maxp1 = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(32, 32, 5, stride=1, padding=1) self.maxp2 = nn.MaxPool2d(2, 2) self.conv3 = nn.Conv2d(32, 64, 4, stride=1, padding=1) self.maxp3 = nn.MaxPool2d(2, 2) self.conv4 = nn.Conv2d(64, 64, 3, stride=1, padding=1) self.maxp4 = nn.MaxPool2d(2, 2) self.lstm = nn.LSTMCell(1024, 512) num_outputs = action_space.n self.critic_linear = nn.Linear(512, 1) self.actor_linear = nn.Linear(512, num_outputs) self.apply(weights_init) relu_gain = nn.init.calculate_gain('relu') self.conv1.weight.data.mul_(relu_gain) self.conv2.weight.data.mul_(relu_gain) self.conv3.weight.data.mul_(relu_gain) self.conv4.weight.data.mul_(relu_gain) self.actor_linear.weight.data = norm_col_init( self.actor_linear.weight.data, 0.01) self.actor_linear.bias.data.fill_(0) self.critic_linear.weight.data = norm_col_init( self.critic_linear.weight.data, 1.0) self.critic_linear.bias.data.fill_(0) self.lstm.bias_ih.data.fill_(0) self.lstm.bias_hh.data.fill_(0) self.train()