-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model_simple.py
More file actions
30 lines (21 loc) · 877 Bytes
/
train_model_simple.py
File metadata and controls
30 lines (21 loc) · 877 Bytes
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
"""
this module is used to train a simple model without quantization and pruning
"""
import torch
from data import load_data
from model.resnet import get_model
from train import train
def train_model_simple(resume=True):
"""
Train a simple model without quantization and pruning.
"""
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(f"Device: {device}")
dataloaders = load_data(batch_size=128, num_workers=0)
model = get_model(num_classes=10)
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.9, patience=5)
train(model, dataloaders, optimizer, criterion, scheduler, device, "simplexx", 100, resume=resume)
if __name__ == '__main__':
train_model_simple()