|
21 | 21 | from datetime import datetime |
22 | 22 |
|
23 | 23 | import torch.nn as nn |
24 | | -import torch.backends.cudnn as cudnn |
25 | 24 |
|
26 | | -from transforms.spatial_transforms import Compose, Normalize, RandomHorizontalFlip, \ |
27 | | - RandomVerticalFlip, MultiScaleRandomCrop, ToTensor, CenterCrop |
| 25 | +from transforms.spatial_transforms import Compose, Normalize, RandomHorizontalFlip, MultiScaleRandomCrop, ToTensor, CenterCrop |
28 | 26 | from transforms.temporal_transforms import TemporalRandomCrop |
29 | 27 | from transforms.target_transforms import ClassLabel |
30 | 28 |
|
31 | 29 | from epoch_iterators import train_epoch, validation_epoch |
32 | 30 | from utils.utils import * |
| 31 | +import utils.mean_values |
33 | 32 | import factory.data_factory as data_factory |
34 | 33 | import factory.model_factory as model_factory |
35 | 34 | from config import parse_opts |
|
43 | 42 | config = init_cropping_scales(config) |
44 | 43 | config = set_lr_scheduling_policy(config) |
45 | 44 |
|
| 45 | +config.image_mean = utils.mean_values.get_mean(config.norm_value, config.dataset) |
| 46 | +config.image_std = utils.mean_values.get_std(config.norm_value) |
| 47 | + |
46 | 48 | print_config(config) |
47 | 49 | write_config(config, os.path.join(config.save_dir, 'config.json')) |
48 | 50 |
|
|
75 | 77 | #################################################################### |
76 | 78 | # Setup of data transformations |
77 | 79 |
|
| 80 | +if config.no_dataset_mean and config.no_dataset_std: |
| 81 | + # Just zero-center and scale to unit std |
| 82 | + print('Data normalization: no dataset mean, no dataset std') |
| 83 | + norm_method = Normalize([0, 0, 0], [1, 1, 1]) |
| 84 | +elif not config.no_dataset_mean and config.no_dataset_std: |
| 85 | + # Subtract dataset mean and scale to unit std |
| 86 | + print('Data normalization: use dataset mean, no dataset std') |
| 87 | + norm_method = Normalize(config.image_mean, [1, 1, 1]) |
| 88 | +else: |
| 89 | + # Subtract dataset mean and scale to dataset std |
| 90 | + print('Data normalization: use dataset mean, use dataset std') |
| 91 | + norm_method = Normalize(config.image_mean, config.image_std) |
| 92 | + |
78 | 93 | train_transforms = { |
79 | 94 | 'spatial': Compose([MultiScaleRandomCrop(config.scales, config.spatial_size), |
80 | | - RandomHorizontalFlip(), RandomVerticalFlip(), |
81 | | - ToTensor(config.norm_value), Normalize([0, 0, 0], [1, 1, 1])]), |
| 95 | + RandomHorizontalFlip(), |
| 96 | + ToTensor(config.norm_value), |
| 97 | + norm_method]), |
82 | 98 | 'temporal': TemporalRandomCrop(config.sample_duration), |
83 | 99 | 'target': ClassLabel() |
84 | 100 | } |
85 | 101 |
|
| 102 | +# print('WARNING: setting train transforms for dataset statistics') |
| 103 | +# train_transforms = { |
| 104 | +# 'spatial': Compose([ToTensor(1.0)]), |
| 105 | +# 'temporal': TemporalRandomCrop(64), |
| 106 | +# 'target': ClassLabel() |
| 107 | +# } |
| 108 | + |
86 | 109 | validation_transforms = { |
87 | | - 'spatial': Compose([CenterCrop(config.spatial_size), ToTensor(config.norm_value), |
88 | | - Normalize([0, 0, 0], [1, 1, 1])]), |
| 110 | + 'spatial': Compose([CenterCrop(config.spatial_size), |
| 111 | + ToTensor(config.norm_value), |
| 112 | + norm_method]), |
89 | 113 | 'temporal': TemporalRandomCrop(config.sample_duration), |
90 | 114 | 'target': ClassLabel() |
91 | 115 | } |
|
0 commit comments