| import torch |
| import torch.nn as nn |
| import numpy as np |
| from torch.utils.data import DataLoader, TensorDataset |
| from torchvision.models import resnet18, resnet34, resnet50 |
|
|
| |
| |
| |
| |
| |
|
|
| data = np.load("train.npz") |
| images = torch.from_numpy(data["images"]).float() / 255.0 |
| labels = torch.from_numpy(data["labels"]).long() |
|
|
| dataset = TensorDataset(images, labels) |
| loader = DataLoader(dataset, batch_size=256, shuffle=True) |
|
|
| print("Dataset size:", len(dataset)) |
| print("Image shape:", images.shape) |
| print("Label range:", labels.min().item(), "to", labels.max().item()) |
|
|
| NUM_CLASSES = 9 |
|
|
| |
| model = resnet18(weights=None) |
| model.fc = nn.Linear(model.fc.in_features, NUM_CLASSES) |
|
|
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| model.eval() |
| with torch.no_grad(): |
| out = model(torch.randn(1, 3, 32, 32)) |
| print("Output shape:", out.shape) |
|
|
| |
| torch.save(model.state_dict(), "model.pt") |