This file contains 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 torch.nn as nn | |
def myModule(nn.Module): | |
def __init__(self): | |
# Init stuff here | |
self.X = nn.Sequential( | |
nn.Linear(num_input_genes, num_tfs), | |
nn.ReLU(), | |
nn.BatchNorm1d(num_tfs) | |
) |
This file contains 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 torch | |
import torch.nn as nn | |
from torch.autograd import Variable | |
class SimpleModel(nn.Module): | |
def __init__(self): | |
super(SimpleModel, self).__init__() | |
self.net = nn.Linear(10, 2) | |
def forward(self, inputs): |
This file contains 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
# Since convolution takes the most time, only do it on images with | |
# mask = 1. Note that masks.data.nonzero() is of size (N, 1). | |
# As a result, when expanding to 4 dims, we need to unsqueeze it twice. | |
selected_idx = Variable(masks.data.nonzero().unsqueeze(2).unsqueeze(3).repeat( | |
1, images.size(1), images.size(2), images.size(3))) | |
selected_images = torch.gather(images, 0, selected_idx) | |
# Get image features from CNN and linear layer rnn_emb. | |
some_im_feats = self.rnn_emb(self.cnn(selected_images).squeeze()) |
NewerOlder