Skip to content

Commit 9c2f867

Browse files
committed
Fixed compatibility with existing framework
1 parent 5b372cc commit 9c2f867

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

data/omniglot/preprocess.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -x
23

34
# download data and convert to .json format
45
if [ ! -d "data/all_data" ] || [ ! "$(ls -A data/all_data)" ]; then

data/omniglot/preprocess/data_to_json.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from collections import defaultdict
88

99
image_size = (28, 28)
10+
status_update_after = 5000 # images processed
1011

1112
user_class = dict()
12-
user_data = defaultdict(list)
13+
user_data = defaultdict(dict)
1314

1415
parent_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
1516
image_paths = os.path.join(parent_path, 'data', 'raw_data', 'images_*', '*', '*', '*.png')
@@ -22,14 +23,20 @@
2223
img = Image.open(character_file).resize(image_size, resample=Image.LANCZOS)
2324
flattened_img = np.array(img.convert('L')).flatten() / 255.
2425

25-
user_data[user_id].append(flattened_img.tolist())
2626
if user_id not in user_class:
2727
user_class[user_id] = character_class
28+
user_data[user_id]['x'] = list()
29+
user_data[user_id]['y'] = list()
30+
user_data[user_id]['x'].append(flattened_img.tolist())
31+
user_data[user_id]['y'].append(user_id)
2832

29-
if (i+1) % 1000 == 0:
33+
if (i+1) % status_update_after == 0:
3034
print ("{} images converted".format(i+1))
3135

32-
all_data = { 'users': list(user_class.items()), 'user_data': user_data }
36+
all_data = dict()
37+
all_data['users'] = list(user_class.keys())
38+
all_data['num_samples'] = [ len(user_data[x]['x']) for x in all_data['users'] ]
39+
all_data['user_data'] = user_data
3340

3441
file_name = 'all_data.json'
3542
file_path = os.path.join(parent_path, 'data', 'all_data', file_name)

data/omniglot/preprocess/get_imagenet.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)