This repository has been archived by the owner on Feb 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
illustrate tent by image corruption example
to illustrate the tent method and fully test-time adaptation setting, we provide an example for adaptation to image corruptions. this is simply *example code* for explanation, not *reference code* for reproduction. that said, experimenting with this should give results that are representative. reference code will follow to reproduce our ImageNet-C results
- Loading branch information
Showing
10 changed files
with
628 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CORRUPTION: | ||
MODEL: Standard | ||
EVAL_ONLY: True | ||
SEVERITY: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 1 | ||
TYPE: | ||
- gaussian_noise | ||
- shot_noise | ||
- impulse_noise | ||
- defocus_blur | ||
- glass_blur | ||
- motion_blur | ||
- zoom_blur | ||
- snow | ||
- frost | ||
- fog | ||
- brightness | ||
- contrast | ||
- elastic_transform | ||
- pixelate | ||
- jpeg_compression | ||
BN: | ||
FUNC: FrozenMeanVarBatchNorm2d | ||
OPTIM: | ||
BATCH_SIZE: 200 | ||
METHOD: Adam | ||
ITER: 1 | ||
BETA: 0.9 | ||
LR: 1e-3 | ||
WD: 0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CORRUPTION: | ||
MODEL: Standard | ||
EVAL_ONLY: True | ||
SEVERITY: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 1 | ||
TYPE: | ||
- gaussian_noise | ||
- shot_noise | ||
- impulse_noise | ||
- defocus_blur | ||
- glass_blur | ||
- motion_blur | ||
- zoom_blur | ||
- snow | ||
- frost | ||
- fog | ||
- brightness | ||
- contrast | ||
- elastic_transform | ||
- pixelate | ||
- jpeg_compression | ||
BN: | ||
FUNC: TrainModeBatchNorm2d | ||
OPTIM: | ||
BATCH_SIZE: 200 | ||
METHOD: Adam | ||
ITER: 1 | ||
BETA: 0.9 | ||
LR: 1e-3 | ||
WD: 0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CORRUPTION: | ||
MODEL: Standard | ||
EVAL_ONLY: False | ||
SEVERITY: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 1 | ||
TYPE: | ||
- gaussian_noise | ||
- shot_noise | ||
- impulse_noise | ||
- defocus_blur | ||
- glass_blur | ||
- motion_blur | ||
- zoom_blur | ||
- snow | ||
- frost | ||
- fog | ||
- brightness | ||
- contrast | ||
- elastic_transform | ||
- pixelate | ||
- jpeg_compression | ||
BN: | ||
FUNC: TrainModeBatchNorm2d | ||
OPTIM: | ||
BATCH_SIZE: 200 | ||
METHOD: Adam | ||
ITER: 1 | ||
BETA: 0.9 | ||
LR: 1e-3 | ||
WD: 0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
import torch | ||
|
||
from robustbench.data import load_cifar10c | ||
from robustbench.utils import clean_accuracy as accuracy | ||
|
||
from tent import tent | ||
from conf import cfg, load_cfg_fom_args | ||
|
||
|
||
def evaluate(cfg_file): | ||
load_cfg_fom_args(cfg_file=cfg_file, | ||
description="CIFAR-10-C evaluation.") | ||
logger = logging.getLogger(__name__) | ||
for severity in cfg.CORRUPTION.SEVERITY: | ||
for corruption_type in cfg.CORRUPTION.TYPE: | ||
x_test, y_test = load_cifar10c(cfg.CORRUPTION.NUM_EX, | ||
severity, cfg.DATA_DIR, False, | ||
[corruption_type]) | ||
x_test, y_test = x_test.cuda(), y_test.cuda() | ||
model = tent(cfg.CORRUPTION.MODEL) | ||
acc = accuracy(model, x_test, y_test, cfg.OPTIM.BATCH_SIZE) | ||
logger.info('accuracy [{}{}]: {:.2%}'.format( | ||
corruption_type, severity, acc)) | ||
|
||
|
||
if __name__ == '__main__': | ||
evaluate('cifar10c.yaml') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CORRUPTION: | ||
MODEL: Standard | ||
SEVERITY: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 1 | ||
TYPE: | ||
- gaussian_noise | ||
- shot_noise | ||
- impulse_noise | ||
- defocus_blur | ||
- glass_blur | ||
- motion_blur | ||
- zoom_blur | ||
- snow | ||
- frost | ||
- fog | ||
- brightness | ||
- contrast | ||
- elastic_transform | ||
- pixelate | ||
- jpeg_compression | ||
BN: | ||
FUNC: TrainModeBatchNorm2d | ||
OPTIM: | ||
BATCH_SIZE: 200 | ||
METHOD: Adam | ||
ITER: 1 | ||
BETA: 0.9 | ||
LR: 1e-3 | ||
WD: 0. |
Oops, something went wrong.