Skip to content

Instantly share code, notes, and snippets.

View arunmallya's full-sized avatar

Arun Mallya arunmallya

View GitHub Profile
@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())
@arunmallya
arunmallya / rf.ipynb
Last active March 30, 2023 09:29
A Jupyter notebook to get the receptive field and effective stride of layers in a CNN. Supports dilated convolutions as well.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arunmallya
arunmallya / ReadCSVToDatum.txt
Last active August 10, 2017 10:55
A function to load CSV data into a caffe datum
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] = ' ';