File size: 1,118 Bytes
27010fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import torch
from torchvision import datasets, transforms
import torch.nn as nn
import torch.optim as optim

# Define your model class
class TatsukichiHayamaClassifier(nn.Module):
    # ... (your model definition)

# Load dataset from PyTorch's ImageFolder
train_dataset = datasets.ImageFolder(root="TatsukichiHayamaDataset", transform=transforms.ToTensor())

# Create a DataLoader for training
dataloader = torch.utils.data.DataLoader(train_dataset, batch_size=32, shuffle=True)

# Create an instance of TatsukichiHayamaClassifier
your_num_classes = 10  # Adjust this based on your dataset
model = TatsukichiHayamaClassifier(num_classes=your_num_classes)

# Model, criterion, and optimizer
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)

# Training loop
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()}')