Skip to content

Instantly share code, notes, and snippets.

View santisy's full-sized avatar

santis_yang santisy

  • Nanjing University
View GitHub Profile
"""
Convert tar file to zip file
Author: Dingdong Yang
"""
import cv2
import numpy as np
import tarfile
import zipfile
@santisy
santisy / type_jit_pytorch_example.py
Created November 26, 2018 21:36
Question about the typing in torch.jit.script
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
class hGRUKernel(nn.Module):
'''
initializer: the one used to initialize the weights
gain: xavier gain
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch.nn import Parameter
def _l2normalize(v, eps=1e-12):
return v / (torch.norm(v, p=2) + eps)
def max_singular_value(W, u=None, Ip=1):
@santisy
santisy / example.py
Last active September 16, 2017 04:52
minimum example of strange speed change
import torch
import time
import numpy as np
time1 = time.time()
## double this tensor's second dimension(20->40), you will almost double the time
for _ in range(100):
tensor = torch.randn(5, 20, 128, 128)
array = np.zeros((128, 128), dtype=np.uint8)
tensor[1, 2, :, :] = torch.from_numpy(array).float()