2
0
mirror of https://github.com/Shawn-Shan/fawkes.git synced 2024-11-12 02:01:30 +05:30
fawkes/fawkes_dev/config.py

42 lines
1.5 KiB
Python
Raw Normal View History

2020-06-01 20:20:02 +05:30
import glob
import json
import os
DATASETS = {
2020-06-29 21:44:48 +05:30
"pubfig": "../data/pubfig",
"scrub": "/home/shansixioing/fawkes/data/scrub/",
2020-06-29 10:04:48 +05:30
"vggface2": "/mnt/data/sixiongshan/data/vggface2/",
2020-06-01 20:20:02 +05:30
"webface": "/mnt/data/sixiongshan/data/webface/",
2020-06-29 10:04:48 +05:30
"youtubeface": "/mnt/data/sixiongshan/data/youtubeface/keras_flow_data/",
2020-06-01 20:20:02 +05:30
}
def main():
config = {}
for dataset in DATASETS.keys():
path = DATASETS[dataset]
if not os.path.exists(path):
print("Dataset path for {} does not exist, skipped".format(dataset))
continue
train_dir = os.path.join(path, "train")
test_dir = os.path.join(path, "test")
if not os.path.exists(train_dir):
print("Training dataset path for {} does not exist, skipped".format(dataset))
continue
num_classes = len(os.listdir(train_dir))
num_images = len(glob.glob(os.path.join(train_dir, "*/*")))
if num_images == 0 or num_classes == 0 or num_images == num_classes:
raise Exception("Dataset {} is not setup as detailed in README.".format(dataset))
config[dataset] = {"train_dir": train_dir, "test_dir": test_dir, "num_classes": num_classes,
"num_images": num_images}
print("Successfully config {}".format(dataset))
j = json.dumps(config)
model_dir = os.path.join(os.path.expanduser('~'), '.fawkes')
with open(os.path.join(model_dir, "config.json"), "wb") as f:
2020-06-01 20:20:02 +05:30
f.write(j.encode())
if __name__ == '__main__':
main()