-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
35 lines (29 loc) · 1.24 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def dataset_from_config(config):
# Select dataset
if config['name'] == 'celeba':
from Utils.celeba import CCelebADataset
return CCelebADataset(
image_size=config['image_size'],
batch_size=config['batch_size'],
toGrayscale=config.get('toGrayscale', True),
extras=config.get('extras', [])
)
raise NotImplementedError(f"Dataset {config['name']} not implemented.")
# Hacky way to create ImageProcessor without instantiating a dataset
def ImageProcessor_from_config(config):
if isinstance(config, str) and ('celeba' == config.lower()): # shortcut
config = dict(name='celeba', image_size=64, toGrayscale=True)
if isinstance(config, dict) and ('celeba' == config['name'].lower()):
from Utils.CelebaImageProcessor import CelebaImageProcessor
return CelebaImageProcessor(
image_size=config['image_size'],
to_grayscale=config.get('toGrayscale', True),
extras=[], # no extras
)
raise NotImplementedError(f"ImageProcessor {config['name']} not implemented.")
def extractImageProcessor(config):
''' Extracts the image processor configuration from the given config '''
res = dict()
for key in ['image_size', 'toGrayscale', 'name']:
if key in config: res[key] = config[key]
return res