zgcr654321 commited on
Commit
a06b5ad
1 Parent(s): c1ca0dc

Upload 28 files

Browse files
imagenet/van_b0/__pycache__/train_config.cpython-38.pyc ADDED
Binary file (3.15 kB). View file
 
imagenet/van_b0/checkpoints/latest.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e3973460b358593771c4a8c864bb3033f55034f96d4443dd26b71c653ab986c
3
+ size 49711051
imagenet/van_b0/checkpoints/van_b0-acc75.618.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:162b506f60e4a1f1251c9e7de97bd9324ccf758474727277531cd27ee6bce45b
3
+ size 16575333
imagenet/van_b0/log/train.info.log ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b0/log/train.info.log.2023-11-21 ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b0/log/train.info.log.2023-11-28 ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b0/test.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --master_addr 127.0.1.0 --master_port 10000 ../../../tools/test_classification_model.py --work-dir ./
imagenet/van_b0/test_config.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ BASE_DIR = os.path.dirname(
5
+ os.path.dirname(os.path.dirname(os.path.dirname(
6
+ os.path.abspath(__file__)))))
7
+ sys.path.append(BASE_DIR)
8
+
9
+ from tools.path import ILSVRC2012_path
10
+
11
+ from simpleAICV.classification import backbones
12
+ from simpleAICV.classification import losses
13
+ from simpleAICV.classification.datasets.ilsvrc2012dataset import ILSVRC2012Dataset
14
+ from simpleAICV.classification.common import Opencv2PIL, TorchResize, TorchCenterCrop, TorchMeanStdNormalize, ClassificationCollater, load_state_dict
15
+
16
+ import torch
17
+ import torchvision.transforms as transforms
18
+
19
+
20
+ class config:
21
+ '''
22
+ for resnet,input_image_size = 224;for darknet,input_image_size = 256
23
+ '''
24
+ network = 'van_b0'
25
+ num_classes = 1000
26
+ input_image_size = 224
27
+ scale = 256 / 224
28
+
29
+ model = backbones.__dict__[network](**{
30
+ 'num_classes': num_classes,
31
+ })
32
+
33
+ # load pretrained model or not
34
+ trained_model_path = ''
35
+ load_state_dict(trained_model_path, model)
36
+
37
+ test_criterion = losses.__dict__['CELoss']()
38
+
39
+ test_dataset = ILSVRC2012Dataset(
40
+ root_dir=ILSVRC2012_path,
41
+ set_name='val',
42
+ transform=transforms.Compose([
43
+ Opencv2PIL(),
44
+ TorchResize(resize=input_image_size * scale),
45
+ TorchCenterCrop(resize=input_image_size),
46
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
47
+ std=[0.229, 0.224, 0.225]),
48
+ ]))
49
+ test_collater = ClassificationCollater()
50
+
51
+ seed = 0
52
+ # batch_size is total size
53
+ batch_size = 256
54
+ # num_workers is total workers
55
+ num_workers = 16
imagenet/van_b0/train.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --master_addr 127.0.1.0 --master_port 10000 ../../../tools/train_classification_model.py --work-dir ./
imagenet/van_b0/train_config.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ BASE_DIR = os.path.dirname(
5
+ os.path.dirname(os.path.dirname(os.path.dirname(
6
+ os.path.abspath(__file__)))))
7
+ sys.path.append(BASE_DIR)
8
+
9
+ from tools.path import ILSVRC2012_path
10
+
11
+ from simpleAICV.classification import backbones
12
+ from simpleAICV.classification import losses
13
+ from simpleAICV.classification.datasets.ilsvrc2012dataset import ILSVRC2012Dataset
14
+ from simpleAICV.classification.common import Opencv2PIL, TorchRandomResizedCrop, TorchRandomHorizontalFlip, RandAugment, TorchResize, TorchCenterCrop, TorchMeanStdNormalize, RandomErasing, ClassificationCollater, MixupCutmixClassificationCollater, load_state_dict
15
+
16
+ import torch
17
+ import torchvision.transforms as transforms
18
+
19
+
20
+ class config:
21
+ '''
22
+ for resnet,input_image_size = 224;for darknet,input_image_size = 256
23
+ '''
24
+ network = 'van_b0'
25
+ num_classes = 1000
26
+ input_image_size = 224
27
+ scale = 256 / 224
28
+
29
+ model = backbones.__dict__[network](**{
30
+ 'drop_path_prob': 0.1,
31
+ 'num_classes': num_classes,
32
+ })
33
+
34
+ # load pretrained model or not
35
+ trained_model_path = '/root/code/SimpleAICV_pytorch_training_examples_on_ImageNet_COCO_ADE20K/pretrained_models/van_weight_convert_from_official_weights/van_b0_pytorch_official_weight_convert.pth'
36
+ load_state_dict(trained_model_path, model)
37
+
38
+ train_criterion = losses.__dict__['OneHotLabelCELoss']()
39
+ test_criterion = losses.__dict__['CELoss']()
40
+
41
+ train_dataset = ILSVRC2012Dataset(
42
+ root_dir=ILSVRC2012_path,
43
+ set_name='train',
44
+ transform=transforms.Compose([
45
+ Opencv2PIL(),
46
+ TorchRandomResizedCrop(resize=input_image_size),
47
+ TorchRandomHorizontalFlip(prob=0.5),
48
+ RandAugment(magnitude=9,
49
+ num_layers=2,
50
+ resize=input_image_size,
51
+ mean=[0.485, 0.456, 0.406],
52
+ integer=True,
53
+ weight_idx=None,
54
+ magnitude_std=0.5,
55
+ magnitude_max=None),
56
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
57
+ std=[0.229, 0.224, 0.225]),
58
+ RandomErasing(prob=0.25, mode='pixel', max_count=1),
59
+ ]))
60
+
61
+ test_dataset = ILSVRC2012Dataset(
62
+ root_dir=ILSVRC2012_path,
63
+ set_name='val',
64
+ transform=transforms.Compose([
65
+ Opencv2PIL(),
66
+ TorchResize(resize=input_image_size * scale),
67
+ TorchCenterCrop(resize=input_image_size),
68
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
69
+ std=[0.229, 0.224, 0.225]),
70
+ ]))
71
+
72
+ train_collater = MixupCutmixClassificationCollater(
73
+ use_mixup=True,
74
+ mixup_alpha=0.8,
75
+ cutmix_alpha=1.0,
76
+ cutmix_minmax=None,
77
+ mixup_cutmix_prob=1.0,
78
+ switch_to_cutmix_prob=0.5,
79
+ mode='batch',
80
+ correct_lam=True,
81
+ label_smoothing=0.1,
82
+ num_classes=1000)
83
+ test_collater = ClassificationCollater()
84
+
85
+ seed = 0
86
+ # batch_size is total size
87
+ batch_size = 256
88
+ # num_workers is total workers
89
+ num_workers = 30
90
+ accumulation_steps = 4
91
+
92
+ optimizer = (
93
+ 'AdamW',
94
+ {
95
+ 'lr': 1e-4,
96
+ 'global_weight_decay': False,
97
+ # if global_weight_decay = False
98
+ # all bias, bn and other 1d params weight set to 0 weight decay
99
+ 'weight_decay': 1e-4,
100
+ 'no_weight_decay_layer_name_list': [],
101
+ },
102
+ )
103
+
104
+ scheduler = (
105
+ 'CosineLR',
106
+ {
107
+ 'warm_up_epochs': 5,
108
+ 'min_lr': 1e-6,
109
+ },
110
+ )
111
+
112
+ epochs = 300
113
+ print_interval = 50
114
+
115
+ sync_bn = False
116
+ use_amp = False
117
+ use_compile = False
118
+ compile_params = {
119
+ # 'default': optimizes for large models, low compile-time and no extra memory usage.
120
+ # 'reduce-overhead': optimizes to reduce the framework overhead and uses some extra memory, helps speed up small models, model update may not correct.
121
+ # 'max-autotune': optimizes to produce the fastest model, but takes a very long time to compile and may failed.
122
+ 'mode': 'default',
123
+ }
124
+
125
+ use_ema_model = False
126
+ ema_model_decay = 0.9999
imagenet/van_b1/__pycache__/train_config.cpython-38.pyc ADDED
Binary file (3.15 kB). View file
 
imagenet/van_b1/checkpoints/latest.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:39b1c45b4bc52676f3e15de8dafb4efb7ccb837e937024ead4d2aecfc7558a54
3
+ size 166723007
imagenet/van_b1/checkpoints/van_b1-acc80.956.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7d54257e90cba48e94e2abcc8b39a24d26096eac4d18122e758ba4d0bc4e3f3
3
+ size 55600905
imagenet/van_b1/log/train.info.log ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b1/log/train.info.log.2023-11-28 ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b1/test.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --master_addr 127.0.1.0 --master_port 10000 ../../../tools/test_classification_model.py --work-dir ./
imagenet/van_b1/test_config.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ BASE_DIR = os.path.dirname(
5
+ os.path.dirname(os.path.dirname(os.path.dirname(
6
+ os.path.abspath(__file__)))))
7
+ sys.path.append(BASE_DIR)
8
+
9
+ from tools.path import ILSVRC2012_path
10
+
11
+ from simpleAICV.classification import backbones
12
+ from simpleAICV.classification import losses
13
+ from simpleAICV.classification.datasets.ilsvrc2012dataset import ILSVRC2012Dataset
14
+ from simpleAICV.classification.common import Opencv2PIL, TorchResize, TorchCenterCrop, TorchMeanStdNormalize, ClassificationCollater, load_state_dict
15
+
16
+ import torch
17
+ import torchvision.transforms as transforms
18
+
19
+
20
+ class config:
21
+ '''
22
+ for resnet,input_image_size = 224;for darknet,input_image_size = 256
23
+ '''
24
+ network = 'van_b1'
25
+ num_classes = 1000
26
+ input_image_size = 224
27
+ scale = 256 / 224
28
+
29
+ model = backbones.__dict__[network](**{
30
+ 'num_classes': num_classes,
31
+ })
32
+
33
+ # load pretrained model or not
34
+ trained_model_path = ''
35
+ load_state_dict(trained_model_path, model)
36
+
37
+ test_criterion = losses.__dict__['CELoss']()
38
+
39
+ test_dataset = ILSVRC2012Dataset(
40
+ root_dir=ILSVRC2012_path,
41
+ set_name='val',
42
+ transform=transforms.Compose([
43
+ Opencv2PIL(),
44
+ TorchResize(resize=input_image_size * scale),
45
+ TorchCenterCrop(resize=input_image_size),
46
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
47
+ std=[0.229, 0.224, 0.225]),
48
+ ]))
49
+ test_collater = ClassificationCollater()
50
+
51
+ seed = 0
52
+ # batch_size is total size
53
+ batch_size = 256
54
+ # num_workers is total workers
55
+ num_workers = 16
imagenet/van_b1/train.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --master_addr 127.0.1.0 --master_port 10000 ../../../tools/train_classification_model.py --work-dir ./
imagenet/van_b1/train_config.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ BASE_DIR = os.path.dirname(
5
+ os.path.dirname(os.path.dirname(os.path.dirname(
6
+ os.path.abspath(__file__)))))
7
+ sys.path.append(BASE_DIR)
8
+
9
+ from tools.path import ILSVRC2012_path
10
+
11
+ from simpleAICV.classification import backbones
12
+ from simpleAICV.classification import losses
13
+ from simpleAICV.classification.datasets.ilsvrc2012dataset import ILSVRC2012Dataset
14
+ from simpleAICV.classification.common import Opencv2PIL, TorchRandomResizedCrop, TorchRandomHorizontalFlip, RandAugment, TorchResize, TorchCenterCrop, TorchMeanStdNormalize, RandomErasing, ClassificationCollater, MixupCutmixClassificationCollater, load_state_dict
15
+
16
+ import torch
17
+ import torchvision.transforms as transforms
18
+
19
+
20
+ class config:
21
+ '''
22
+ for resnet,input_image_size = 224;for darknet,input_image_size = 256
23
+ '''
24
+ network = 'van_b1'
25
+ num_classes = 1000
26
+ input_image_size = 224
27
+ scale = 256 / 224
28
+
29
+ model = backbones.__dict__[network](**{
30
+ 'drop_path_prob': 0.1,
31
+ 'num_classes': num_classes,
32
+ })
33
+
34
+ # load pretrained model or not
35
+ trained_model_path = '/root/code/SimpleAICV_pytorch_training_examples_on_ImageNet_COCO_ADE20K/pretrained_models/van_weight_convert_from_official_weights/van_b1_pytorch_official_weight_convert.pth'
36
+ load_state_dict(trained_model_path, model)
37
+
38
+ train_criterion = losses.__dict__['OneHotLabelCELoss']()
39
+ test_criterion = losses.__dict__['CELoss']()
40
+
41
+ train_dataset = ILSVRC2012Dataset(
42
+ root_dir=ILSVRC2012_path,
43
+ set_name='train',
44
+ transform=transforms.Compose([
45
+ Opencv2PIL(),
46
+ TorchRandomResizedCrop(resize=input_image_size),
47
+ TorchRandomHorizontalFlip(prob=0.5),
48
+ RandAugment(magnitude=9,
49
+ num_layers=2,
50
+ resize=input_image_size,
51
+ mean=[0.485, 0.456, 0.406],
52
+ integer=True,
53
+ weight_idx=None,
54
+ magnitude_std=0.5,
55
+ magnitude_max=None),
56
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
57
+ std=[0.229, 0.224, 0.225]),
58
+ RandomErasing(prob=0.25, mode='pixel', max_count=1),
59
+ ]))
60
+
61
+ test_dataset = ILSVRC2012Dataset(
62
+ root_dir=ILSVRC2012_path,
63
+ set_name='val',
64
+ transform=transforms.Compose([
65
+ Opencv2PIL(),
66
+ TorchResize(resize=input_image_size * scale),
67
+ TorchCenterCrop(resize=input_image_size),
68
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
69
+ std=[0.229, 0.224, 0.225]),
70
+ ]))
71
+
72
+ train_collater = MixupCutmixClassificationCollater(
73
+ use_mixup=True,
74
+ mixup_alpha=0.8,
75
+ cutmix_alpha=1.0,
76
+ cutmix_minmax=None,
77
+ mixup_cutmix_prob=1.0,
78
+ switch_to_cutmix_prob=0.5,
79
+ mode='batch',
80
+ correct_lam=True,
81
+ label_smoothing=0.1,
82
+ num_classes=1000)
83
+ test_collater = ClassificationCollater()
84
+
85
+ seed = 0
86
+ # batch_size is total size
87
+ batch_size = 256
88
+ # num_workers is total workers
89
+ num_workers = 30
90
+ accumulation_steps = 4
91
+
92
+ optimizer = (
93
+ 'AdamW',
94
+ {
95
+ 'lr': 1e-4,
96
+ 'global_weight_decay': False,
97
+ # if global_weight_decay = False
98
+ # all bias, bn and other 1d params weight set to 0 weight decay
99
+ 'weight_decay': 1e-4,
100
+ 'no_weight_decay_layer_name_list': [],
101
+ },
102
+ )
103
+
104
+ scheduler = (
105
+ 'CosineLR',
106
+ {
107
+ 'warm_up_epochs': 5,
108
+ 'min_lr': 1e-6,
109
+ },
110
+ )
111
+
112
+ epochs = 300
113
+ print_interval = 50
114
+
115
+ sync_bn = False
116
+ use_amp = False
117
+ use_compile = False
118
+ compile_params = {
119
+ # 'default': optimizes for large models, low compile-time and no extra memory usage.
120
+ # 'reduce-overhead': optimizes to reduce the framework overhead and uses some extra memory, helps speed up small models, model update may not correct.
121
+ # 'max-autotune': optimizes to produce the fastest model, but takes a very long time to compile and may failed.
122
+ 'mode': 'default',
123
+ }
124
+
125
+ use_ema_model = False
126
+ ema_model_decay = 0.9999
imagenet/van_b2/__pycache__/train_config.cpython-38.pyc ADDED
Binary file (3.15 kB). View file
 
imagenet/van_b2/checkpoints/latest.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7bb5fa0d4292847ea6e686273c143b2d8efb4b9a79ff97c63dbfc837579c38f
3
+ size 319694059
imagenet/van_b2/checkpoints/van_b2-acc82.322.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d62b46a66177819c875a50822bbda4190cac5c989cecde2cd1963b68e6c6f7d
3
+ size 106609413
imagenet/van_b2/log/train.info.log ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b2/log/train.info.log.2023-11-21 ADDED
The diff for this file is too large to render. See raw diff
 
imagenet/van_b2/test.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --master_addr 127.0.1.0 --master_port 10000 ../../../tools/test_classification_model.py --work-dir ./
imagenet/van_b2/test_config.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ BASE_DIR = os.path.dirname(
5
+ os.path.dirname(os.path.dirname(os.path.dirname(
6
+ os.path.abspath(__file__)))))
7
+ sys.path.append(BASE_DIR)
8
+
9
+ from tools.path import ILSVRC2012_path
10
+
11
+ from simpleAICV.classification import backbones
12
+ from simpleAICV.classification import losses
13
+ from simpleAICV.classification.datasets.ilsvrc2012dataset import ILSVRC2012Dataset
14
+ from simpleAICV.classification.common import Opencv2PIL, TorchResize, TorchCenterCrop, TorchMeanStdNormalize, ClassificationCollater, load_state_dict
15
+
16
+ import torch
17
+ import torchvision.transforms as transforms
18
+
19
+
20
+ class config:
21
+ '''
22
+ for resnet,input_image_size = 224;for darknet,input_image_size = 256
23
+ '''
24
+ network = 'van_b2'
25
+ num_classes = 1000
26
+ input_image_size = 224
27
+ scale = 256 / 224
28
+
29
+ model = backbones.__dict__[network](**{
30
+ 'num_classes': num_classes,
31
+ })
32
+
33
+ # load pretrained model or not
34
+ trained_model_path = ''
35
+ load_state_dict(trained_model_path, model)
36
+
37
+ test_criterion = losses.__dict__['CELoss']()
38
+
39
+ test_dataset = ILSVRC2012Dataset(
40
+ root_dir=ILSVRC2012_path,
41
+ set_name='val',
42
+ transform=transforms.Compose([
43
+ Opencv2PIL(),
44
+ TorchResize(resize=input_image_size * scale),
45
+ TorchCenterCrop(resize=input_image_size),
46
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
47
+ std=[0.229, 0.224, 0.225]),
48
+ ]))
49
+ test_collater = ClassificationCollater()
50
+
51
+ seed = 0
52
+ # batch_size is total size
53
+ batch_size = 256
54
+ # num_workers is total workers
55
+ num_workers = 16
imagenet/van_b2/train.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.run --nproc_per_node=4 --master_addr 127.0.1.0 --master_port 10000 ../../../tools/train_classification_model.py --work-dir ./
imagenet/van_b2/train_config.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ BASE_DIR = os.path.dirname(
5
+ os.path.dirname(os.path.dirname(os.path.dirname(
6
+ os.path.abspath(__file__)))))
7
+ sys.path.append(BASE_DIR)
8
+
9
+ from tools.path import ILSVRC2012_path
10
+
11
+ from simpleAICV.classification import backbones
12
+ from simpleAICV.classification import losses
13
+ from simpleAICV.classification.datasets.ilsvrc2012dataset import ILSVRC2012Dataset
14
+ from simpleAICV.classification.common import Opencv2PIL, TorchRandomResizedCrop, TorchRandomHorizontalFlip, RandAugment, TorchResize, TorchCenterCrop, TorchMeanStdNormalize, RandomErasing, ClassificationCollater, MixupCutmixClassificationCollater, load_state_dict
15
+
16
+ import torch
17
+ import torchvision.transforms as transforms
18
+
19
+
20
+ class config:
21
+ '''
22
+ for resnet,input_image_size = 224;for darknet,input_image_size = 256
23
+ '''
24
+ network = 'van_b2'
25
+ num_classes = 1000
26
+ input_image_size = 224
27
+ scale = 256 / 224
28
+
29
+ model = backbones.__dict__[network](**{
30
+ 'drop_path_prob': 0.1,
31
+ 'num_classes': num_classes,
32
+ })
33
+
34
+ # load pretrained model or not
35
+ trained_model_path = '/root/code/SimpleAICV_pytorch_training_examples_on_ImageNet_COCO_ADE20K/pretrained_models/van_weight_convert_from_official_weights/van_b2_pytorch_official_weight_convert.pth'
36
+ load_state_dict(trained_model_path, model)
37
+
38
+ train_criterion = losses.__dict__['OneHotLabelCELoss']()
39
+ test_criterion = losses.__dict__['CELoss']()
40
+
41
+ train_dataset = ILSVRC2012Dataset(
42
+ root_dir=ILSVRC2012_path,
43
+ set_name='train',
44
+ transform=transforms.Compose([
45
+ Opencv2PIL(),
46
+ TorchRandomResizedCrop(resize=input_image_size),
47
+ TorchRandomHorizontalFlip(prob=0.5),
48
+ RandAugment(magnitude=9,
49
+ num_layers=2,
50
+ resize=input_image_size,
51
+ mean=[0.485, 0.456, 0.406],
52
+ integer=True,
53
+ weight_idx=None,
54
+ magnitude_std=0.5,
55
+ magnitude_max=None),
56
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
57
+ std=[0.229, 0.224, 0.225]),
58
+ RandomErasing(prob=0.25, mode='pixel', max_count=1),
59
+ ]))
60
+
61
+ test_dataset = ILSVRC2012Dataset(
62
+ root_dir=ILSVRC2012_path,
63
+ set_name='val',
64
+ transform=transforms.Compose([
65
+ Opencv2PIL(),
66
+ TorchResize(resize=input_image_size * scale),
67
+ TorchCenterCrop(resize=input_image_size),
68
+ TorchMeanStdNormalize(mean=[0.485, 0.456, 0.406],
69
+ std=[0.229, 0.224, 0.225]),
70
+ ]))
71
+
72
+ train_collater = MixupCutmixClassificationCollater(
73
+ use_mixup=True,
74
+ mixup_alpha=0.8,
75
+ cutmix_alpha=1.0,
76
+ cutmix_minmax=None,
77
+ mixup_cutmix_prob=1.0,
78
+ switch_to_cutmix_prob=0.5,
79
+ mode='batch',
80
+ correct_lam=True,
81
+ label_smoothing=0.1,
82
+ num_classes=1000)
83
+ test_collater = ClassificationCollater()
84
+
85
+ seed = 0
86
+ # batch_size is total size
87
+ batch_size = 256
88
+ # num_workers is total workers
89
+ num_workers = 60
90
+ accumulation_steps = 4
91
+
92
+ optimizer = (
93
+ 'AdamW',
94
+ {
95
+ 'lr': 1e-4,
96
+ 'global_weight_decay': False,
97
+ # if global_weight_decay = False
98
+ # all bias, bn and other 1d params weight set to 0 weight decay
99
+ 'weight_decay': 1e-4,
100
+ 'no_weight_decay_layer_name_list': [],
101
+ },
102
+ )
103
+
104
+ scheduler = (
105
+ 'CosineLR',
106
+ {
107
+ 'warm_up_epochs': 5,
108
+ 'min_lr': 1e-6,
109
+ },
110
+ )
111
+
112
+ epochs = 300
113
+ print_interval = 50
114
+
115
+ sync_bn = False
116
+ use_amp = False
117
+ use_compile = False
118
+ compile_params = {
119
+ # 'default': optimizes for large models, low compile-time and no extra memory usage.
120
+ # 'reduce-overhead': optimizes to reduce the framework overhead and uses some extra memory, helps speed up small models, model update may not correct.
121
+ # 'max-autotune': optimizes to produce the fastest model, but takes a very long time to compile and may failed.
122
+ 'mode': 'default',
123
+ }
124
+
125
+ use_ema_model = False
126
+ ema_model_decay = 0.9999