Skip to content

Instantly share code, notes, and snippets.

View arunmallya's full-sized avatar

Arun Mallya arunmallya

View GitHub Profile
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)
)
@arunmallya
arunmallya / bug.py
Created June 20, 2017 20:46
Exposes bug with DataParallel when using dicts as input
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):
@arunmallya
arunmallya / masked_conv.py
Created June 20, 2017 17:51
Performs conv only on valid input images.
# 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())