Skip to content

Commit 1eda53f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 60098a1 commit 1eda53f

23 files changed

Lines changed: 83 additions & 183 deletions

File tree

benchmarks/train_crnn_cinc2020/trainer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,15 @@ def evaluate(self, data_loader: DataLoader) -> Dict[str, float]:
245245
head_labels = all_labels[:head_num, ...]
246246
head_labels_classes = [np.array(classes)[np.where(row)] for row in head_labels]
247247
for n in range(head_num):
248-
msg = textwrap.dedent(
249-
f"""
248+
msg = textwrap.dedent(f"""
250249
----------------------------------------------
251250
scalar prediction: {[round(n, 3) for n in head_scalar_preds[n].tolist()]}
252251
binary prediction: {head_bin_preds[n].tolist()}
253252
labels: {head_labels[n].astype(int).tolist()}
254253
predicted classes: {head_preds_classes[n].tolist()}
255254
label classes: {head_labels_classes[n].tolist()}
256255
----------------------------------------------
257-
"""
258-
)
256+
""")
259257
self.log_manager.log_message(msg)
260258

261259
(

benchmarks/train_crnn_cinc2021/dataset.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,10 @@ def _train_test_split(self, train_ratio: float = 0.8, force_recompute: bool = Fa
314314
)
315315
train_file.write_text(json.dumps(train_set, ensure_ascii=False))
316316
test_file.write_text(json.dumps(test_set, ensure_ascii=False))
317-
print(
318-
textwrap.dedent(
319-
f"""
317+
print(textwrap.dedent(f"""
320318
train set saved to \n\042{str(train_file)}\042
321319
test set saved to \n\042{str(test_file)}\042
322-
"""
323-
)
324-
)
320+
"""))
325321
else:
326322
train_set = json.loads(train_file.read_text())
327323
test_set = json.loads(test_file.read_text())
@@ -362,16 +358,12 @@ def _check_train_test_split_validity(self, train_set: List[str], test_set: List[
362358
test_classes = set(list_sum([self.reader.get_labels(rec, fmt="a") for rec in test_set]))
363359
test_classes.intersection_update(all_classes)
364360
is_valid = len(all_classes) == len(train_classes) == len(test_classes)
365-
print(
366-
textwrap.dedent(
367-
f"""
361+
print(textwrap.dedent(f"""
368362
all_classes: {all_classes}
369363
train_classes: {train_classes}
370364
test_classes: {test_classes}
371365
is_valid: {is_valid}
372-
"""
373-
)
374-
)
366+
"""))
375367
return is_valid
376368

377369
def persistence(self) -> None:

benchmarks/train_crnn_cinc2021/trainer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,15 @@ def evaluate(self, data_loader: DataLoader) -> Dict[str, float]:
233233
head_labels = all_labels[:head_num, ...]
234234
head_labels_classes = [np.array(classes)[np.where(row)] for row in head_labels]
235235
for n in range(head_num):
236-
msg = textwrap.dedent(
237-
f"""
236+
msg = textwrap.dedent(f"""
238237
----------------------------------------------
239238
scalar prediction: {[round(n, 3) for n in head_scalar_preds[n].tolist()]}
240239
binary prediction: {head_bin_preds[n].tolist()}
241240
labels: {head_labels[n].astype(int).tolist()}
242241
predicted classes: {head_preds_classes[n].tolist()}
243242
label classes: {head_labels_classes[n].tolist()}
244243
----------------------------------------------
245-
"""
246-
)
244+
""")
247245
self.log_manager.log_message(msg)
248246

249247
(

benchmarks/train_crnn_cinc2023/trainer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,15 @@ def evaluate(self, data_loader: DataLoader) -> Dict[str, float]:
346346
]
347347
log_head_num = min(log_head_num, len(head_scalar_preds))
348348
for n in range(log_head_num):
349-
msg = textwrap.dedent(
350-
f"""
349+
msg = textwrap.dedent(f"""
351350
----------------------------------------------
352351
cpc scalar prediction: {[round(item, 3) for item in head_scalar_preds[n].tolist()]}
353352
cpc binary prediction: {head_bin_preds[n].tolist()}
354353
cpc labels: {head_labels[n].astype(int).tolist()}
355354
cpc predicted classes: {head_preds_classes[n].tolist()}
356355
cpc label classes: {head_labels_classes[n].tolist()}
357356
----------------------------------------------
358-
"""
359-
)
357+
""")
360358
self.log_manager.log_message(msg)
361359

362360
eval_res = compute_challenge_metrics(

benchmarks/train_hybrid_cpsc2020/trainer.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ def train(
162162

163163
# max_itr = n_epochs * n_train
164164

165-
msg = textwrap.dedent(
166-
f"""
165+
msg = textwrap.dedent(f"""
167166
Starting training:
168167
------------------
169168
Epochs: {n_epochs}
@@ -174,8 +173,7 @@ def train(
174173
Device: {device.type}
175174
Optimizer: {config.train_optimizer}
176175
-----------------------------------------
177-
"""
178-
)
176+
""")
179177
# print(msg) # in case no logger
180178
if logger:
181179
logger.info(msg)
@@ -351,20 +349,17 @@ def train(
351349
scheduler.step()
352350

353351
if debug:
354-
eval_train_msg = textwrap.dedent(
355-
f"""
352+
eval_train_msg = textwrap.dedent(f"""
356353
train/auroc: {eval_train_res[0]}
357354
train/auprc: {eval_train_res[1]}
358355
train/accuracy: {eval_train_res[2]}
359356
train/f_measure: {eval_train_res[3]}
360357
train/f_beta_measure: {eval_train_res[4]}
361358
train/g_beta_measure: {eval_train_res[5]}
362-
"""
363-
)
359+
""")
364360
else:
365361
eval_train_msg = ""
366-
msg = textwrap.dedent(
367-
f"""
362+
msg = textwrap.dedent(f"""
368363
Train epoch_{epoch + 1}:
369364
--------------------
370365
train/epoch_loss: {epoch_loss}{eval_train_msg}
@@ -375,8 +370,7 @@ def train(
375370
test/f_beta_measure: {eval_res[4]}
376371
test/g_beta_measure: {eval_res[5]}
377372
---------------------------------
378-
"""
379-
)
373+
""")
380374
elif config.model_name == "seq_lab":
381375
eval_res = evaluate_seq_lab(model, val_loader, config, device, debug)
382376
model.train()
@@ -403,8 +397,7 @@ def train(
403397
scheduler.step()
404398

405399
if debug:
406-
eval_train_msg = textwrap.dedent(
407-
f"""
400+
eval_train_msg = textwrap.dedent(f"""
408401
train/total_loss: {eval_train_res.total_loss}
409402
train/spb_loss: {eval_train_res.spb_loss}
410403
train/pvc_loss: {eval_train_res.pvc_loss}
@@ -414,12 +407,10 @@ def train(
414407
train/pvc_fp: {eval_train_res.pvc_fp}
415408
train/spb_fn: {eval_train_res.spb_fn}
416409
train/pvc_fn: {eval_train_res.pvc_fn}
417-
"""
418-
)
410+
""")
419411
else:
420412
eval_train_msg = ""
421-
msg = textwrap.dedent(
422-
f"""
413+
msg = textwrap.dedent(f"""
423414
Train epoch_{epoch + 1}:
424415
--------------------
425416
train/epoch_loss: {epoch_loss}{eval_train_msg}
@@ -433,8 +424,7 @@ def train(
433424
test/spb_fn: {eval_res.spb_fn}
434425
test/pvc_fn: {eval_res.pvc_fn}
435426
---------------------------------
436-
"""
437-
)
427+
""")
438428

439429
# print(msg) # in case no logger
440430
if logger:
@@ -460,12 +450,10 @@ def train(
460450
print(msg)
461451
break
462452

463-
msg = textwrap.dedent(
464-
f"""
453+
msg = textwrap.dedent(f"""
465454
best challenge metric = {best_challenge_metric},
466455
obtained at epoch {best_epoch}
467-
"""
468-
)
456+
""")
469457
if logger:
470458
logger.info(msg)
471459
else:
@@ -615,17 +603,15 @@ def evaluate_crnn(
615603
head_labels = all_labels[:head_num, ...]
616604
head_labels_classes = [np.array(classes)[np.where(row)] for row in head_labels]
617605
for n in range(head_num):
618-
msg = textwrap.dedent(
619-
f"""
606+
msg = textwrap.dedent(f"""
620607
----------------------------------------------
621608
scalar prediction: {[round(n, 3) for n in head_scalar_preds[n].tolist()]}
622609
binary prediction: {head_bin_preds[n].tolist()}
623610
labels: {head_labels[n].astype(int).tolist()}
624611
predicted classes: {head_preds_classes[n].tolist()}
625612
label classes: {head_labels_classes[n].tolist()}
626613
----------------------------------------------
627-
"""
628-
)
614+
""")
629615
if logger:
630616
logger.info(msg)
631617
else:

benchmarks/train_hybrid_cpsc2021/dataset.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,14 +1183,10 @@ def _train_test_split(self, train_ratio: float = 0.8, force_recompute: bool = Fa
11831183

11841184
train_file.write_text(json.dumps(train_set, ensure_ascii=False))
11851185
test_file.write_text(json.dumps(test_set, ensure_ascii=False))
1186-
print(
1187-
nildent(
1188-
f"""
1186+
print(nildent(f"""
11891187
train set saved to \n\042{str(train_file)}\042
11901188
test set saved to \n\042{str(test_file)}\042
1191-
"""
1192-
)
1193-
)
1189+
"""))
11941190
else:
11951191
train_set = json.loads(train_file.read_text())
11961192
test_set = json.loads(test_file.read_text())

benchmarks/train_mtl_cinc2022/inputs.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ def from_waveform(self, waveform: Union[np.ndarray, torch.Tensor]) -> torch.Tens
404404

405405

406406
class SpectralInput(_SpectralInput):
407-
__doc__ = (
408-
_SpectralInput.__doc__
409-
+ """
407+
__doc__ = _SpectralInput.__doc__ + """
410408
411409
Concatenation of 3 different types of spectrograms:
412410
- Spectrogram
@@ -444,7 +442,6 @@ class SpectralInput(_SpectralInput):
444442
(32, 3, 224, 2308)
445443
446444
"""
447-
)
448445

449446
__name__ = "SpectralInput"
450447

benchmarks/train_mtl_cinc2022/trainer.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,15 @@ def evaluate(self, data_loader: DataLoader) -> Dict[str, float]:
353353
]
354354
log_head_num = min(log_head_num, len(head_scalar_preds))
355355
for n in range(log_head_num):
356-
msg = textwrap.dedent(
357-
f"""
356+
msg = textwrap.dedent(f"""
358357
----------------------------------------------
359358
murmur scalar prediction: {[round(item, 3) for item in head_scalar_preds[n].tolist()]}
360359
murmur binary prediction: {head_bin_preds[n].tolist()}
361360
murmur labels: {head_labels[n].astype(int).tolist()}
362361
murmur predicted classes: {head_preds_classes[n].tolist()}
363362
murmur label classes: {head_labels_classes[n].tolist()}
364363
----------------------------------------------
365-
"""
366-
)
364+
""")
367365
self.log_manager.log_message(msg)
368366
if "outcome" in input_tensors:
369367
head_scalar_preds = all_outputs[0].outcome_output.prob[:log_head_num]
@@ -382,17 +380,15 @@ def evaluate(self, data_loader: DataLoader) -> Dict[str, float]:
382380
]
383381
log_head_num = min(log_head_num, len(head_scalar_preds))
384382
for n in range(log_head_num):
385-
msg = textwrap.dedent(
386-
f"""
383+
msg = textwrap.dedent(f"""
387384
----------------------------------------------
388385
outcome scalar prediction: {[round(item, 3) for item in head_scalar_preds[n].tolist()]}
389386
outcome binary prediction: {head_bin_preds[n].tolist()}
390387
outcome labels: {head_labels[n].astype(int).tolist()}
391388
outcome predicted classes: {head_preds_classes[n].tolist()}
392389
outcome label classes: {head_labels_classes[n].tolist()}
393390
----------------------------------------------
394-
"""
395-
)
391+
""")
396392
self.log_manager.log_message(msg)
397393

398394
eval_res = compute_challenge_metrics(

docs/source/conf.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,11 @@ def setup(app):
216216
]
217217

218218
# https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#latex-backend-fails-with-citations-in-figure-captions
219-
latex_elements = {
220-
"preamble": r"""
219+
latex_elements = {"preamble": r"""
221220
% make phantomsection empty inside figures
222221
\usepackage{etoolbox}
223222
\AtBeginEnvironment{figure}{\renewcommand{\phantomsection}{}}
224-
"""
225-
}
223+
"""}
226224

227225
man_pages = [(master_doc, project, f"{project} Documentation", [author], 1)]
228226

test/test_pipelines/test_crnn_cinc2021_pipeline.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,15 @@ def evaluate(self, data_loader: DataLoader) -> Dict[str, float]:
621621
head_labels = all_labels[:head_num, ...]
622622
head_labels_classes = [np.array(classes)[np.where(row)] for row in head_labels]
623623
for n in range(head_num):
624-
msg = textwrap.dedent(
625-
f"""
624+
msg = textwrap.dedent(f"""
626625
----------------------------------------------
627626
scalar prediction: {[round(n, 3) for n in head_scalar_preds[n].tolist()]}
628627
binary prediction: {head_bin_preds[n].tolist()}
629628
labels: {head_labels[n].astype(int).tolist()}
630629
predicted classes: {head_preds_classes[n].tolist()}
631630
label classes: {head_labels_classes[n].tolist()}
632631
----------------------------------------------
633-
"""
634-
)
632+
""")
635633
self.log_manager.log_message(msg)
636634

637635
(

0 commit comments

Comments
 (0)