-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatasets.py
More file actions
41 lines (34 loc) · 870 Bytes
/
datasets.py
File metadata and controls
41 lines (34 loc) · 870 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
31
32
33
34
35
36
37
38
39
40
41
from pathlib import Path
from PIL import Image
import pandas as pd
from datastream import Dataset
from vae import problem
def dataframe():
return (
pd.DataFrame(dict(
image_path=problem.settings.data_path.glob('*.png'),
))
.assign(
key=lambda df: df['image_path'].apply(
lambda image_path: image_path.stem
)
)
)
def dataset(dataframe):
return (
Dataset.from_dataframe(dataframe)
.map(lambda row: row['image_path'])
.map(Path)
.map(Image.open)
.map(lambda image: problem.Example(image=image))
.cache('key')
)
def datasets(frozen=True):
return (
dataset(dataframe())
.split(
key_column='key',
proportions=dict(train=0.8, compare=0.2),
seed=177,
)
)