forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
55 lines (45 loc) · 1.39 KB
/
Copy pathconfig.py
File metadata and controls
55 lines (45 loc) · 1.39 KB
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
46
47
48
49
50
51
52
53
54
55
import json
import os
from typing import Any, Dict, Optional
from dataclasses import dataclass, asdict
@dataclass
class Config:
model_name: str = "neuralforge_model"
batch_size: int = 32
epochs: int = 100
learning_rate: float = 0.001
weight_decay: float = 0.0001
optimizer: str = "adamw"
scheduler: str = "cosine"
warmup_epochs: int = 5
grad_clip: float = 1.0
data_path: str = "./data"
num_workers: int = 4
pin_memory: bool = True
model_dir: str = "./models"
log_dir: str = "./logs"
checkpoint_freq: int = 10
use_amp: bool = True
device: str = "cuda"
seed: int = 42
nas_enabled: bool = False
nas_population_size: int = 20
nas_generations: int = 50
nas_mutation_rate: float = 0.1
image_size: int = 224
num_classes: int = 1000
def save(self, path: str):
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as f:
json.dump(asdict(self), f, indent=2)
@classmethod
def load(cls, path: str) -> 'Config':
with open(path, 'r') as f:
data = json.load(f)
return cls(**data)
def update(self, **kwargs):
for key, value in kwargs.items():
if hasattr(self, key):
setattr(self, key, value)
def __str__(self) -> str:
return json.dumps(asdict(self), indent=2)