-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampler.py
45 lines (38 loc) · 1.08 KB
/
sampler.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
36
37
38
39
40
41
42
43
44
45
import os
from bindsnet.datasets import MNIST
from bindsnet.encoding import PoissonEncoder
import numpy as np
# Load MNIST data.
dataset = MNIST(
None,
None,
root=os.path.join("..", "..", "data", "MNIST"),
download=False,
# transform=transforms.Compose(
# [transforms.ToTensor(),
# transforms.Lambda(lambda x: x * intensity),
# transforms.CenterCrop(crop_size)]
)
test_dataset = MNIST(
None,
None,
root=os.path.join("..", "..", "data", "MNIST"),
download=False,
train=False,
# transform=transforms.Compose(
# [transforms.ToTensor(),
# transforms.Lambda(lambda x: x * intensity),
# transforms.CenterCrop(crop_size)]
# ),
)
target_classes = (6, 8, 9)
mask = np.array(
[1 if dataset[i]["label"] in target_classes else 0 for i in range(len(dataset))]
)
mask_test = np.array(
[
1 if test_dataset[i]["label"] in target_classes else 0
for i in range(len(test_dataset))
]
)
np.savez(f'mask_{"_".join([str(i) for i in target_classes])}.npz', mask, mask_test)