-
Notifications
You must be signed in to change notification settings - Fork 0
/
s.txt
28 lines (24 loc) · 968 Bytes
/
s.txt
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
def build_dataset(data_dir, target=None, batch_size=32):
all_images = []
all_labels = []
#
class_labels = os.listdir(data_dir)
for class_label in class_labels:
if target is not None and class_label != str(target):
continue
class_dir = os.path.join(data_dir, class_label)
images = glob.glob(os.path.join(class_label, '*.png')
all_images.extend(images)
all_labels.extend([int(class_label == str(target))] * len(images))
ds = tf.data.Dataset.from_tensor_slices((all_images, all_labels))
ds = ds.map(lambda x,y: (tf.io.encode_base64(tf.io.read_file(x)) ,y))
ds = ds.shuffle(100, seed=123)
ds = ds.batch(batch_size)
return ds
train_ds = build_dataset(train_dir)
dev_ds = build_dataset(dev_dir)
test_ds = build_dataset(test_dir)
File "/tmp/ipykernel_18/2725700248.py", line 11
all_images.extend(images)
^
SyntaxError: invalid syntax