-
Notifications
You must be signed in to change notification settings - Fork 4
/
water_dataset.py
57 lines (40 loc) · 1.28 KB
/
water_dataset.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
46
47
48
49
50
51
52
53
54
55
import os
import numpy as np
import logging
from config import opt
def read_sample(sample_file_path):
"""Returns the sample_file.
Args:
sample_file (file): The file of the sample.
Returns:
a data sample
"""
with open(sample_file_path, 'r') as f:
lines = f.readlines()
# label = int(float(lines[0].split(',')[0].strip()))
reallabel = int(float(lines[0].split(',')[0].strip()))
label = opt.labels_dict.index(reallabel)
datas = list()
for line in lines[1:] :
line = [float(item) for item in line.split(',')]
datas.append(line)
f.close()
return label, datas
class WaterDataset:
def __init__(self, data_dir, split='train'):
self.data_dir = os.path.join(data_dir, split)
self.list_file = os.listdir(self.data_dir)
def __len__(self):
return len(self.list_file)
def get_example(self, i):
"""Returns the i-th sample.
Args:
i (int): The index of the sample_files.
Returns:
a data sample
"""
# Load a sample
sample_file = self.list_file[i]
label, datas = read_sample(os.path.join(self.data_dir, sample_file))
return label, datas
__getitem__ = get_example