Upload ProDiff/conf/config.py with huggingface_hub
Browse files- ProDiff/conf/config.py +105 -0
ProDiff/conf/config.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration settings for the trajectory interpolation project.
|
| 3 |
+
|
| 4 |
+
This file defines a function `load_config()` which returns a dictionary
|
| 5 |
+
containing various parameters grouped by their purpose (e.g., data, model,
|
| 6 |
+
diffusion, training, sampling).
|
| 7 |
+
"""
|
| 8 |
+
from types import SimpleNamespace
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
+
def load_config():
|
| 12 |
+
config_args = {
|
| 13 |
+
'data': {
|
| 14 |
+
'traj_length': 256, # 修正:增加长度以容纳两个1小时(120点)的遮蔽和上下文
|
| 15 |
+
'dataset': 'TKY_temporal',
|
| 16 |
+
'traj_path1': './data/',
|
| 17 |
+
'num_workers': 16, # 增加数据加载线程,减少GPU等待
|
| 18 |
+
},
|
| 19 |
+
'train': {
|
| 20 |
+
'batch_size': 512, # 显著降低batch_size以适应增长的traj_length,避免显存溢出
|
| 21 |
+
'n_epochs': 50,
|
| 22 |
+
'n_iters': 5000000,
|
| 23 |
+
'snapshot_freq': 5000,
|
| 24 |
+
'validation_freq': 5,
|
| 25 |
+
'dis_gpu': False,
|
| 26 |
+
},
|
| 27 |
+
'trans': {
|
| 28 |
+
'input_dim': 3,
|
| 29 |
+
'embed_dim': 512,
|
| 30 |
+
'num_layers': 4,
|
| 31 |
+
'num_heads': 8,
|
| 32 |
+
'forward_dim': 256,
|
| 33 |
+
'dropout': 0.1,
|
| 34 |
+
'N_CLUSTER': 20,
|
| 35 |
+
},
|
| 36 |
+
'test': {
|
| 37 |
+
'batch_size': 256, # 同样降低测试batch size以适应增长的traj_length
|
| 38 |
+
'last_only': True,
|
| 39 |
+
},
|
| 40 |
+
'diffusion': {
|
| 41 |
+
'beta_schedule': 'linear',
|
| 42 |
+
'beta_start': 0.0001,
|
| 43 |
+
'beta_end': 0.05,
|
| 44 |
+
'num_diffusion_timesteps': 500,
|
| 45 |
+
},
|
| 46 |
+
'model': {
|
| 47 |
+
'type': "simple",
|
| 48 |
+
'attr_dim': 8,
|
| 49 |
+
'guidance_scale': 2,
|
| 50 |
+
'in_channels': 3,
|
| 51 |
+
'out_ch': 3,
|
| 52 |
+
'ch': 128,
|
| 53 |
+
'ch_mult': [1, 2, 2, 2],
|
| 54 |
+
'num_res_blocks': 2,
|
| 55 |
+
'attn_resolutions': [16],
|
| 56 |
+
'dropout': 0.1,
|
| 57 |
+
'var_type': 'fixedlarge',
|
| 58 |
+
'resamp_with_conv': True,
|
| 59 |
+
},
|
| 60 |
+
'data_source': 'TKY',
|
| 61 |
+
'data_dir': './data/TKY/manually_split/',
|
| 62 |
+
'normalization_params_file': './data/TKY/normalization_params.json',
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# Create nested config structure to maintain compatibility
|
| 66 |
+
config = SimpleNamespace()
|
| 67 |
+
config.training = SimpleNamespace(**config_args['train'])
|
| 68 |
+
config.test = SimpleNamespace(**config_args['test'])
|
| 69 |
+
config.diffusion = SimpleNamespace(**config_args['diffusion'])
|
| 70 |
+
config.model = SimpleNamespace(**config_args['model'])
|
| 71 |
+
config.sampling = SimpleNamespace(**config_args['test']) # Use test config for sampling
|
| 72 |
+
# Add DDIM sampling configuration for faster testing
|
| 73 |
+
config.sampling.type = 'ddim' # Use DDIM instead of DDPM for 10x faster testing
|
| 74 |
+
config.sampling.ddim_steps = 50 # 50 steps instead of 500, 10x speedup
|
| 75 |
+
config.sampling.ddim_eta = 0.0 # Deterministic sampling
|
| 76 |
+
config.data = SimpleNamespace(**config_args['data'])
|
| 77 |
+
config.trans = SimpleNamespace(**config_args['trans'])
|
| 78 |
+
|
| 79 |
+
config.device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 80 |
+
config.masking_strategy = 'multi_segment' # 新增:'multi_segment'
|
| 81 |
+
config.mask_segments = [60, 60] # 修正:基于“一分钟一点”,每段遮蔽60个点
|
| 82 |
+
config.mask_ratio = 0.2
|
| 83 |
+
config.mask_points_per_hour = 60 # 修正:基于“一分钟一点”的先验知识
|
| 84 |
+
config.z_score_normalization = False
|
| 85 |
+
config.dis_gpu = False # Distributed GPU training
|
| 86 |
+
|
| 87 |
+
# Add missing top-level config fields
|
| 88 |
+
config.learning_rate = 1.5e-4 # 降低学习率,提高训练稳定性
|
| 89 |
+
config.batch_size = config_args['train']['batch_size']
|
| 90 |
+
config.n_epochs = config_args['train']['n_epochs']
|
| 91 |
+
config.validation_freq = config_args['train']['validation_freq']
|
| 92 |
+
config.warmup_epochs = 5 # 减少warmup epochs,加速训练
|
| 93 |
+
config.contrastive_margin = 1.0
|
| 94 |
+
config.kmeans_memory_size = 15 # 增加K-means缓存,提高聚类效率
|
| 95 |
+
config.contrastive_loss_weight = 0.1
|
| 96 |
+
config.ce_loss_weight = 0.1
|
| 97 |
+
config.diffusion_loss_weight = 1.0
|
| 98 |
+
config.device_id = 0
|
| 99 |
+
config.use_amp = True # 启用混合精度训练
|
| 100 |
+
config.normalization_params_file = config_args['normalization_params_file']
|
| 101 |
+
config.data_source = config_args['data_source']
|
| 102 |
+
config.data_dir = config_args['data_dir']
|
| 103 |
+
config.traj_length = config_args['data']['traj_length']
|
| 104 |
+
|
| 105 |
+
return config
|