MCPcopy
hub / github.com/NVlabs/SPADE / make_dataset

Function make_dataset

data/image_folder.py:36–64  ·  view source on GitHub ↗
(dir, recursive=False, read_cache=False, write_cache=False)

Source from the content-addressed store, hash-verified

34
35
36def make_dataset(dir, recursive=False, read_cache=False, write_cache=False):
37 images = []
38
39 if read_cache:
40 possible_filelist = os.path.join(dir, 'files.list')
41 if os.path.isfile(possible_filelist):
42 with open(possible_filelist, 'r') as f:
43 images = f.read().splitlines()
44 return images
45
46 if recursive:
47 make_dataset_rec(dir, images)
48 else:
49 assert os.path.isdir(dir) or os.path.islink(dir), '%s is not a valid directory' % dir
50
51 for root, dnames, fnames in sorted(os.walk(dir)):
52 for fname in fnames:
53 if is_image_file(fname):
54 path = os.path.join(root, fname)
55 images.append(path)
56
57 if write_cache:
58 filelist_cache = os.path.join(dir, 'files.list')
59 with open(filelist_cache, 'w') as f:
60 for path in images:
61 f.write("%s\n" % path)
62 print('wrote filelist cache at %s' % filelist_cache)
63
64 return images
65
66
67def default_loader(path):

Callers 6

get_pathsMethod · 0.90
get_pathsMethod · 0.90
get_pathsMethod · 0.90
get_pathsMethod · 0.90
get_pathsMethod · 0.90
__init__Method · 0.85

Calls 2

make_dataset_recFunction · 0.85
is_image_fileFunction · 0.85

Tested by

no test coverage detected