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

Ks dev #4

Open
wants to merge 3 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
Binary file added src/__pycache__/model.cpython-39.pyc
Binary file not shown.
11 changes: 8 additions & 3 deletions src/train.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
# 作者:小土堆
# 公众号:土堆碎念

import torchvision
from torch.utils.tensorboard import SummaryWriter
Expand All @@ -10,6 +7,8 @@
from torch import nn
from torch.utils.data import DataLoader

# 使用GPU
device = torch.device("cuda")
train_data = torchvision.datasets.CIFAR10(root="../data", train=True, transform=torchvision.transforms.ToTensor(),
download=True)
test_data = torchvision.datasets.CIFAR10(root="../data", train=False, transform=torchvision.transforms.ToTensor(),
Expand All @@ -29,9 +28,11 @@

# 创建网络模型
tudui = Tudui()
tudui = tudui.to(device)

# 损失函数
loss_fn = nn.CrossEntropyLoss()
loss_fn = loss_fn.to(device)

# 优化器
# learning_rate = 0.01
Expand All @@ -57,6 +58,8 @@
tudui.train()
for data in train_dataloader:
imgs, targets = data
imgs = imgs.to(device)
targets = targets.to(device)
outputs = tudui(imgs)
loss = loss_fn(outputs, targets)

Expand All @@ -77,6 +80,8 @@
with torch.no_grad():
for data in test_dataloader:
imgs, targets = data
imgs = imgs.to(device)
targets = targets.to(device)
outputs = tudui(imgs)
loss = loss_fn(outputs, targets)
total_test_loss = total_test_loss + loss.item()
Expand Down
Binary file modified src/tudui_0.pth
Binary file not shown.
Binary file added src/tudui_1.pth
Binary file not shown.
Binary file added src/tudui_2.pth
Binary file not shown.
Binary file added src/tudui_3.pth
Binary file not shown.
Binary file added src/tudui_4.pth
Binary file not shown.
Binary file added src/tudui_5.pth
Binary file not shown.
Binary file added src/tudui_6.pth
Binary file not shown.
Binary file added src/tudui_7.pth
Binary file not shown.
Binary file added src/tudui_8.pth
Binary file not shown.
Binary file added src/tudui_9.pth
Binary file not shown.