-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
45 lines (40 loc) · 1.37 KB
/
config.py
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
38
39
40
41
42
43
44
45
import torch
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
DATASET = "cifar100"
LABEL_NAME = "fine_label"
NUM_CLASSES = 100
# https://developer.nvidia.com/embedded/jetson-modules
# https://www.raspberrypi.com/products/raspberry-pi-4-model-b/specifications/
JETSON_NANO_CONFIG = {
'name' : 'Jetson Nano',
'compute' : 472, # GFLOPS
'memory': 4, # GB
}
JETSON_XAVIER_NX_8GB_CONFIG = {
'name' : 'Jetson Xavier NX 8GB',
'compute' : 21, # TOPS
'memory': 8, # GB
}
RASPBERRY_PI_4_CONFIG = {
'name' : 'Raspberry Pi 4 Model B',
'compute' : 9.69, # GFLOPS
'memory': 4, # GB
}
def train_cifar10(model, id, cifar10):
dataloader = torch.utils.data.DataLoader(cifar10, batch_size=32, shuffle=True, num_workers=3)
criterion = torch.nn.CrossEntropyLoss()
model = model().to(DEVICE)
model.train()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
for epoch in range(15):
for batch in dataloader:
optimizer.zero_grad()
inputs, labels = batch["img"].to(DEVICE), batch["label"].to(DEVICE)
outputs = model(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
if id is not None:
torch.save(model.state_dict(), f"checkpoints/device_{id}.pth")
else:
torch.save(model.state_dict(), "checkpoints/server.pth")