This file contains 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 | |
import torch.nn.functional as F | |
from torch._C import _infer_size | |
# Setup | |
x = Variable(torch.randn(4, 2, 2)) | |
y = Variable(torch.Tensor(4, 2, 2).random_(2)) | |
output = F.sigmoid(x) |
This file contains 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 numpy as np | |
# numpy | |
a = np.random.rand(10, 20) | |
tmp0 = np.split(a, indices_or_sections=5, axis=0) # split into 5 sections | |
for t in tmp0: | |
print(t.shape) | |
np.split(a, indices_or_sections=7, axis=0) # error, since no equal division |
This file contains 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 | |
# batch_size = 2 | |
x1 = Variable(torch.ones(2, 1)) | |
w1 = Variable(torch.ones(1, 1), requires_grad=True) | |
y1 = Variable(torch.ones(2, 1) * 2) |
This file contains 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
#Load packages | |
import torch | |
import torch.nn as nn | |
import torchvision.transforms as transforms | |
import torchvision.datasets as dsets | |
from torch.autograd import Variable | |
import torch.nn.functional as F | |
torch.manual_seed(2809) |
This file contains 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 | |
import torch.optim as optim | |
from torch.autograd import Variable | |
import torch.nn.functional as F | |
import matplotlib.pyplot as plt | |
import numpy as np |
This file contains 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 | |
import torch.optim as optim | |
from torch.utils.data import Dataset, DataLoader | |
class MyDataset(Dataset): | |
def __init__(self, data, target): | |
self.data = data | |
self.target = target |
This file contains 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 | |
import torch.optim as optim | |
import torch.nn.functional as F | |
from torchvision.utils import make_grid | |
import matplotlib.pyplot as plt | |
This file contains 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 | |
import torch.nn.functional as F | |
import torch.optim as optim | |
use_adam = False | |
class MyModel(nn.Module): | |
def __init__(self): |
This file contains 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 | |
import torch.nn.functional as F | |
import matplotlib.pyplot as plt | |
output = F.log_softmax(torch.randn(1, 3, 24, 24), 1) | |
target = torch.zeros(1, 24, 24, dtype=torch.long) | |
target[0, 4:12, 4:12] = 1 |
This file contains 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 time | |
import torch | |
import torch.nn as nn | |
device = 'cuda:0' | |
batch_size = 10 | |
channels = 64 | |
h, w = 128, 128 |
OlderNewer