Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daily task #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Tasks/daily tasks/Hashina/day_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from torch import nn

class Network(nn.Module):
def __init__(self):
super().__init__()

self.hidden = nn.Linear(1, 2)
self.output = nn.Linear(2, 1)

self.sigmoid = nn.Sigmoid()

def forward(self, x):
x = self.hidden(x)
x = self.sigmoid(x)
x = self.output(x)

return x

108 changes: 94 additions & 14 deletions Tasks/daily tasks/Hashina/day_4.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,98 @@
from torch import nn
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import torch.optim as optim

class Network(nn.Module):
transform = transforms.Compose(
[
transforms.ToTensor(),
transforms.Normalize(
(0.5, 0.5, 0.5),
(0.5, 0.5, 0.5)
)
]
)

trainset = torchvision.datasets.CIFAR10(
root='./data',
train=True,
download=False,
transform=transform
)

testset = torchvision.datasets.CIFAR10(
root='./data',
train=False,
download=False,
transform=transform
)

trainloader = torch.utils.data.DataLoader(
trainset,
batch_size=4,
shuffle=True,
num_workers=2
)

testloader = torch.utils.data.DataLoader(
testset,
batch_size=4,
shuffle=False,
num_workers=2
)

classes = (
'plane', 'car', 'bird', 'cat',
'deer', 'dog', 'frog', 'horse', 'ship', 'truck'
)

class Net(nn.Module):
def __init__(self):
super().__init__()

self.hidden = nn.Linear(1, 2)
self.output = nn.Linear(2, 1)

self.sigmoid = nn.Sigmoid()

super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)

def forward(self, x):
x = self.hidden(x)
x = self.sigmoid(x)
x = self.output(x)

x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x



net = Net()

loss_function = nn.CrossEntropyLoss()
optimizer = optim.SGD(
net.parameters(),
lr=0.001
)

for epoch in range(2):
running_loss = 0.0
for i, data in enumerate(trainloader, 0):
# data = (inputs, labels)
inputs, labels = data
optimizer.zero_grad()

outputs = net(inputs)
loss = loss_function(outputs, labels)
loss.backward()
optimizer.step()

running_loss = running_loss + loss.item()
if i % 2000 == 1999:
print(
'[%d, %5d] loss: %.3f' %
(epoch + 1, i+1, running_loss/2000)
)
running_loss = 0.0
print("vola")