Views
No views yet
cardboard, glass, metal, paper, plastic, trashtorchvision.models.resnet18 (IMAGENET1K_V1 weights), custom Linear(64) -> ReLU -> Dropout(0.5) -> Linear(num_classes) headtrash class is underrepresented ~3.6x vs paper)lr, weight_decay, batch_size) selected via Optuna hyperparameter search (25 trials), then trained for 30 epochs with the winning config1from huggingface_hub import hf_hub_download
2import torch
3from torchvision import models
4import torch.nn as nn
5
6def get_model(hidden_size=64, num_classes=6):
7 model = models.resnet18(weights=None)
8 model.fc = nn.Sequential(
9 nn.Linear(model.fc.in_features, hidden_size),
10 nn.ReLU(),
11 nn.Dropout(p=0.5),
12 nn.Linear(hidden_size, num_classes),
13 )
14 return model
15
16checkpoint_path = hf_hub_download(
17 repo_id="tonghahaha/trashnet-resnet18",
18 filename="best_resnet18_trashnet.pth",
19)
20model = get_model(num_classes=6)
21model.load_state_dict(torch.load(checkpoint_path, map_location="cpu", weights_only=True))
22model.eval()