|
import torch |
|
from torchvision import datasets, transforms |
|
import torch.nn as nn |
|
import torch.optim as optim |
|
|
|
|
|
class TatsukichiHayamaClassifier(nn.Module): |
|
|
|
|
|
|
|
train_dataset = datasets.ImageFolder(root="TatsukichiHayamaDataset", transform=transforms.ToTensor()) |
|
|
|
|
|
dataloader = torch.utils.data.DataLoader(train_dataset, batch_size=32, shuffle=True) |
|
|
|
|
|
your_num_classes = 10 |
|
model = TatsukichiHayamaClassifier(num_classes=your_num_classes) |
|
|
|
|
|
criterion = nn.CrossEntropyLoss() |
|
optimizer = optim.Adam(model.parameters(), lr=0.001) |
|
|
|
|
|
num_epochs = 10 |
|
|
|
for epoch in range(num_epochs): |
|
model.train() |
|
for images, labels in dataloader: |
|
optimizer.zero_grad() |
|
outputs = model(images) |
|
loss = criterion(outputs, labels) |
|
loss.backward() |
|
optimizer.step() |
|
|
|
print(f'Epoch {epoch+1}/{num_epochs}, Loss: {loss.item()}') |
|
|