Skip to content

Instantly share code, notes, and snippets.

View pclucas14's full-sized avatar

Lucas Caccia pclucas14

View GitHub Profile
@pclucas14
pclucas14 / conv_einsum.py
Created August 17, 2019 18:44
Convolutions with `as_strided` and `einsum`
class einsum_conv(nn.Module):
def __init__(self, kernel_size, stride=1):
super(einsum_conv, self).__init__()
self.ks = kernel_size
self.stride = stride
def forward(self, x, kernel):
if len(x.size()) == 3:
x = x.unsqueeze(0)
@pclucas14
pclucas14 / emd.py
Created July 24, 2018 19:28
Wrapper for EMD in pytorch
from torch.autograd import Function, Variable
import numpy as np
import torch
import torch.nn as nn
import pdb
from torch.nn.modules.utils import _pair
from pyinn.utils import Dtype, Stream, load_kernel
import torch.nn.functional as F
from torch.autograd import gradcheck