<jupyter_start><jupyter_text>vanilla unet<jupyter_code>model_cfg = deepcopy(ModelCfg)
model_cfg.model_name = "unet"
config = deepcopy(TrainCfg)
config.model_name = model_cfg.model_name
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
logger = init_logger(log_dir=config.log_dir, verbose=2)
logger.info(f"\n{'*'*20}   Start Training   {'*'*20}\n")
logger.info(f"Using device {device}")
logger.info(f"Using torch of version {torch.__version__}")
logger.info(f"with configuration\n{dict_to_str(config)}")
# print(f"\n{'*'*20}   Start Training   {'*'*20}\n")
# print(f"Using device {device}")
# print(f"Using torch of version {torch.__version__}")
# print(f"with configuration\n{dict_to_str(config)}")

model_name = config.model_name.lower()
model_config = deepcopy(ModelCfg[model_name])

if model_name == "subtract_unet":
    model = ECG_SUBTRACT_UNET_CPSC2019(
        n_leads=config.n_leads,
        config=model_config,
    )
elif model_name == "unet":
    model = ECG_UNET_CPSC2019(
        n_leads=config.n_leads,
        config=model_config,
    )

if torch.cuda.device_count() > 1:
    model = DP(model)
#     model = DDP(model)

model.to(device=device)
model.__DEBUG__ = False
model.device_ids
best_state_dict = train(
    model=model,
    model_config=model_config,
    device=device,
    config=config,
    logger=logger,
    debug=True,
)
# best_state_dict
# best_model = ECG_UNET_CPSC2019(
#     n_leads=config.n_leads,
#     config=model_config,
# )
# best_model.load_state_dict(best_state_dict)
# best_model<jupyter_output><empty_output><jupyter_text>CPSC2019 subtract unet<jupyter_code>model_cfg = deepcopy(ModelCfg)
model_cfg.model_name = "subtract_unet"

config = deepcopy(TrainCfg)
config.model_name = model_cfg.model_name
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
logger = init_logger(log_dir=config.log_dir, verbose=2)
logger.info(f"\n{'*'*20}   Start Training   {'*'*20}\n")
logger.info(f"Using device {device}")
logger.info(f"Using torch of version {torch.__version__}")
logger.info(f"with configuration\n{dict_to_str(config)}")
# print(f"\n{'*'*20}   Start Training   {'*'*20}\n")
# print(f"Using device {device}")
# print(f"Using torch of version {torch.__version__}")
# print(f"with configuration\n{dict_to_str(config)}")

model_name = config.model_name.lower()
model_config = deepcopy(ModelCfg[model_name])

if model_name == "subtract_unet":
    model = ECG_SUBTRACT_UNET_CPSC2019(
        n_leads=config.n_leads,
        config=model_config,
    )
elif model_name == "unet":
    model = ECG_UNET_CPSC2019(
        n_leads=config.n_leads,
        config=model_config,
    )

if torch.cuda.device_count() > 1:
    model = DP(model)
#     model = DDP(model)

model.to(device=device)
model.__DEBUG__ = False
best_state_dict = train(
    model=model,
    model_config=model_config,
    device=device,
    config=config,
    logger=logger,
    debug=True,
)<jupyter_output>ECG-UNET - INFO - training configurations are as follows:
{
    "fs": 500
    "db_dir": "/home/wenh06/Jupyter/data/CPSC2019/"
    "log_dir": "/home/wenh06/Jupyter/wenhao/workspace/torch_ecg/train/train_unet_cpsc2019/log"
    "checkpoints": "/home/wenh06/Jupyter/wenhao/workspace/torch_ecg/train/train_unet_cpsc2019/checkpoints"
    "model_dir": "/home/wenh06/Jupyter/wenhao/workspace/torch_ecg/train/train_unet_cpsc2019/saved_models"
    "final_model_name": None
    "keep_checkpoint_max": 20
    "train_ratio": 0.8
    "input_len": 5000
    "classes": [
        "N"
    ]
    "n_leads": 1
    "bias_thr": 37
    "skip_dist": 250
    "label_smoothing": 0.0
    "random_normalize": True
    "random_normalize_mean": [
        -0.05, 0.1
    ]
    "random_normalize_std": [
        0.08, 0.32
    ]
    "baseline_wander": True
    "bw": True
    "bw_fs": [0.33 0.1  0.05 0.01]
    "bw_ampl_ratio": [[0.01 0.01 0.02 0.03]
 [0.01 0.02 0.04 0.05]
 [0.1  0.06 0.04 0.02]
 [0.02 0.04 0.07 0.1 ]
 [0.05 0.1  [...]<jupyter_text>DEBUG<jupyter_code>from train.database_reader.database_reader.cpsc_databases.cpsc2019 import CPSC2019 as DR
from dataset import CPSC2019 as DG
dr = DR(db_dir=TrainCfg.db_dir)
dg = DG(TrainCfg)
dg.__DEBUG__ = False
values, labels = dg[2]
labels.shape
plt.plot(labels[...,0])
# for s,l in dg:
for idx in range(len(dg)):
    s,l = dg[idx]
    fig, ax = plt.subplots()
    ax.plot(l[...,0])
    plt.show()
    print("-"*50)
values = values.astype(np.float32)
# labels.shape
# ?best_model.inference
pred, rpeaks = best_model.inference(values[np.newaxis,...])
np.where(pred>0.5)
pred.shape, values.shape
fig, ax = plt.subplots(figsize=(20,4))
ax.plot(values[0])
ax.plot(pred[0]-0.5,c="red")
plt.show()
hehe_fwd = best_model.forward(torch.from_numpy(values[np.newaxis,...]).to(device))
plt.plot(hehe_fwd.squeeze().cpu().detach().numpy())
?nn.Sigmoid
plt.plot(labels[0])
np.unique(labels[0])<jupyter_output><empty_output><jupyter_text>clear GPU<jupyter_code>with torch.no_grad():
    torch.cuda.empty_cache()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1541391060332732, 'fraction_numerical': 0.03808378432551614, 'mean_word_length': 4.4714912280701755, 'pattern_counts': {'":': 25, '<': 16, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '96635', 'license': 'MIT', 'n_tokens_mistral': 2107, 'n_tokens_neox': 1989, 'n_words': 307, 'path': 'rpeaks_unet/results/train_unet_cpsc2019.ipynb', 'repo_name': 'DeepPSP/torch_ecg_models', 'size': '4989'}