Upload train_nano_job.py with huggingface_hub
Browse files- train_nano_job.py +3 -1
train_nano_job.py
CHANGED
|
@@ -70,6 +70,8 @@ def main():
|
|
| 70 |
x = (x - np.array([0.485, 0.456, 0.406], np.float32)) / np.array([0.229, 0.224, 0.225], np.float32)
|
| 71 |
x = np.transpose(x, (2, 0, 1))
|
| 72 |
y = CL.index(CL[r["sound_class"]] if isinstance(r["sound_class"], str) else CL[r["sound_class"]])
|
|
|
|
|
|
|
| 73 |
return torch.from_numpy(x), torch.tensor(y), torch.tensor(1 if y == 0 else 0, dtype=torch.float32)
|
| 74 |
|
| 75 |
tr = DataLoader(Win("train", 120000), batch_size=args.batch, shuffle=True, num_workers=4)
|
|
@@ -77,7 +79,7 @@ def main():
|
|
| 77 |
dev = "cuda" if torch.cuda.is_available() else "cpu"
|
| 78 |
m = build_nano().to(dev)
|
| 79 |
opt = torch.optim.AdamW(m.parameters(), lr=3e-4)
|
| 80 |
-
cw = torch.tensor([1.0, 6.0, 6.0, 1.0
|
| 81 |
for ep in range(args.epochs):
|
| 82 |
m.train(); tot = 0
|
| 83 |
for x, y, w in tr:
|
|
|
|
| 70 |
x = (x - np.array([0.485, 0.456, 0.406], np.float32)) / np.array([0.229, 0.224, 0.225], np.float32)
|
| 71 |
x = np.transpose(x, (2, 0, 1))
|
| 72 |
y = CL.index(CL[r["sound_class"]] if isinstance(r["sound_class"], str) else CL[r["sound_class"]])
|
| 73 |
+
if y == 4:
|
| 74 |
+
y = 3 # 'unknown' folds into ambient_outdoor for the 4-class head
|
| 75 |
return torch.from_numpy(x), torch.tensor(y), torch.tensor(1 if y == 0 else 0, dtype=torch.float32)
|
| 76 |
|
| 77 |
tr = DataLoader(Win("train", 120000), batch_size=args.batch, shuffle=True, num_workers=4)
|
|
|
|
| 79 |
dev = "cuda" if torch.cuda.is_available() else "cpu"
|
| 80 |
m = build_nano().to(dev)
|
| 81 |
opt = torch.optim.AdamW(m.parameters(), lr=3e-4)
|
| 82 |
+
cw = torch.tensor([1.0, 6.0, 6.0, 1.0]) # boost rare classes (drone, vehicle, explosion, ambient)
|
| 83 |
for ep in range(args.epochs):
|
| 84 |
m.train(); tot = 0
|
| 85 |
for x, y, w in tr:
|