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
| bool ReadCSVToDatum(const string& filename, Datum* datum) { | |
| // read in the CSV file into a vector | |
| fstream file(filename.c_str(), ios::in); | |
| vector<vector<int> > label; | |
| std::string line; | |
| while (std::getline(file, line)) { | |
| // replace commas with spaces | |
| for (int i = 0; i < line.length(); i++) { | |
| if (line[i] == ',') | |
| line[i] = ' '; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| # 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()) |
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 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 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 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 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
| from __future__ import print_function | |
| import torch | |
| A = torch.rand(4) | |
| idx = torch.LongTensor([0, 3]) | |
| An = A.numpy() | |
| idxn = idx.numpy() | |
| # Numpy indexing. |
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
| from __future__ import print_function | |
| import torch | |
| A = torch.rand(4, 4) | |
| An = A.numpy() | |
| idx = torch.ByteTensor([1, 0, 0, 1]) | |
| idxn = [True, False, False, True] | |
| # Numpy indexing. |
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
| American_Goldfinch_0062_31921.jpg -> n01531178_12730.JPEG | |
| Indigo_Bunting_0063_11820.jpg -> n01537544_9540.JPEG | |
| Blue_Jay_0053_62744.jpg -> n01580077_4622.JPEG | |
| American_Goldfinch_0131_32911.jpg -> n01531178_17834.JPEG | |
| Dark_Eyed_Junco_0057_68650.jpg -> n01534433_12777.JPEG | |
| Indigo_Bunting_0051_12837.jpg -> n01537544_2126.JPEG | |
| Dark_Eyed_Junco_0102_67402.jpg -> n01534433_9482.JPEG | |
| American_Goldfinch_0012_32338.jpg -> n01531178_14394.JPEG | |
| Laysan_Albatross_0033_658.jpg -> n02058221_16284.JPEG | |
| Black_Footed_Albatross_0024_796089.jpg -> n02058221_6390.JPEG |
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
| DEFAULT_THRESHOLD = 5e-3 | |
| class Binarizer(torch.autograd.Function): | |
| """Binarizes {0, 1} a real valued tensor.""" | |
| def __init__(self, threshold=DEFAULT_THRESHOLD): | |
| super(Binarizer, self).__init__() | |
| self.threshold = threshold | |
| def forward(self, inputs): |
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
| class ElementWiseConv2d(nn.Module): | |
| """Modified conv. Do we need mask for biases too?""" | |
| def __init__(self, in_channels, out_channels, kernel_size, stride=1, | |
| padding=0, dilation=1, groups=1, bias=True, | |
| mask_init='1s', mask_scale=1e-2, | |
| threshold_fn='binarizer', threshold=None): | |
| super(ElementWiseConv2d, self).__init__() | |
| kernel_size = _pair(kernel_size) | |
| stride = _pair(stride) |
OlderNewer