-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatasets.py
More file actions
31 lines (23 loc) · 749 Bytes
/
Copy pathdatasets.py
File metadata and controls
31 lines (23 loc) · 749 Bytes
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
import jax.numpy as jnp
import numpy as np
from PIL import Image
class SkinData(object):
def __init__(self, df, transform=None):
self.df = df
self.transform = transform
def __len__(self):
return len(self.df)
def __getitem__(self, index):
X = np.array(Image.open(self.df["path"][index]).resize((64, 64)))
y = jnp.array(int(self.df["target"][index]))
if self.transform:
X = self.transform(X)
return X, y
def get_batch(self, indices):
X_batch = []
y_batch = []
for idx in indices:
X, y = self.__getitem__(idx)
X_batch.append(X)
y_batch.append(y)
return jnp.stack(X_batch), jnp.stack(y_batch)