| 17 | |
| 18 | |
| 19 | def TSA(schedule, cur_iter, total_iter, num_classes): |
| 20 | training_progress = cur_iter / total_iter |
| 21 | |
| 22 | if schedule == 'linear': |
| 23 | threshold = training_progress |
| 24 | elif schedule == 'exp': |
| 25 | scale = 5 |
| 26 | threshold = math.exp((training_progress - 1) * scale) |
| 27 | elif schedule == 'log': |
| 28 | scale = 5 |
| 29 | threshold = 1 - math.exp((-training_progress) * scale) |
| 30 | elif schedule == 'none': |
| 31 | return 1 |
| 32 | tsa = threshold * (1 - 1 / num_classes) + 1 / num_classes |
| 33 | return tsa |
| 34 | |
| 35 | |
| 36 | def consistency_loss(logits_s, logits_w, class_acc, it, ds, name='ce', T=1.0, p_cutoff=0.0, use_flex=False): |