72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
from __future__ import print_function
|
|
import torch
|
|
import torch.nn as nn
|
|
import torch.nn.functional as F
|
|
import torch.optim as optim
|
|
import torchvision
|
|
from torchvision import datasets, transforms
|
|
import torchvision.models as models
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
|
|
# class Net(nn.Module):
|
|
# def __init__(self):
|
|
# super(Net, self).__init__()
|
|
# self.conv1 = nn.Conv2d(1, 64, kernel_size=5)
|
|
# self.conv2 = nn.Conv2d(64, 32, kernel_size=3)
|
|
# self.conv3 = nn.Conv2d(32, 16, kernel_size=5)
|
|
# self.fc1 = nn.Linear(1*16, 10)
|
|
#
|
|
# def forward(self, x):
|
|
#
|
|
# x = F.relu(F.max_pool2d(self.conv1(x), 2))
|
|
# x = F.relu(F.max_pool2d(self.conv2(x), 2))
|
|
# x = F.relu(self.conv3(x), 2)
|
|
#
|
|
# x = x.view(-1, 1*16)
|
|
# x = F.relu(self.fc1(x))
|
|
#
|
|
# return F.log_softmax(x, dim=1)
|
|
|
|
# class Net(nn.Module):
|
|
# def __init__(self):
|
|
# super(Net, self).__init__()
|
|
# self.conv1 = nn.Conv2d(1, 16, kernel_size=5)
|
|
# self.conv2 = nn.Conv2d(16, 16, kernel_size=3)
|
|
# self.conv3 = nn.Conv2d(16, 10, kernel_size=5)
|
|
#
|
|
# def forward(self, x):
|
|
#
|
|
# x = F.sigmoid(F.max_pool2d(self.conv1(x), 2))
|
|
# x = F.sigmoid(F.max_pool2d(self.conv2(x), 2))
|
|
# x = self.conv3(x)
|
|
#
|
|
# x = x.view(-1, 1*10)
|
|
#
|
|
# return F.log_softmax(x, dim=1)
|
|
|
|
|
|
class Net(nn.Module):
|
|
def __init__(self):
|
|
super(Net, self).__init__()
|
|
layers = []
|
|
layers += [nn.Conv2d(1, 8, kernel_size=5),nn.MaxPool2d(kernel_size=2, stride=2),nn.Sigmoid()]
|
|
layers += [nn.Conv2d(8, 8, kernel_size=3),nn.MaxPool2d(kernel_size=2, stride=2),nn.Sigmoid()]
|
|
layers += [nn.Conv2d(8, 10, kernel_size=5)]
|
|
self.features = nn.Sequential(*layers)
|
|
|
|
# self.conv1 = nn.Conv2d(1, 8, kernel_size=5)
|
|
# self.conv2 = self.__conv(8, 8, kernel_size=3)
|
|
# self.conv3 = self.__conv(8, 10, kernel_size=5)
|
|
|
|
def forward(self, x):
|
|
|
|
|
|
# x = F.sigmoid(F.max_pool2d(self.conv1(x), 2))
|
|
# x = F.sigmoid(F.max_pool2d(self.conv2(x), 2))
|
|
# x = self.conv3(x)
|
|
x = self.features(x)
|
|
x = x.view(-1, 1*10)
|
|
|
|
return F.log_softmax(x, dim=1) |