-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_set.py
More file actions
51 lines (40 loc) · 1.58 KB
/
image_set.py
File metadata and controls
51 lines (40 loc) · 1.58 KB
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
import pickle
import torch
import numpy as np
from copy import deepcopy
from random import randrange
from datetime import timedelta
from chunkified_npset import ChunkifiedDataset
class ImageSet(torch.utils.data.Dataset):
def __init__(self, np_set, gen_tables):
self.in_width = 128
self.out_width = 64
self.inner_offset = int((128 - 64) / 2)
self.np_set = np_set
self._gen_tables(gen_tables)
def _gen_tables(self, gen_tables):
idx_2_time = None
with open('uk_data_np/idx_2_time', 'rb') as i2t_f:
idx_2_time = pickle.load(i2t_f)
i2t_f.close()
self.corner_and_idxs = gen_tables(idx_2_time)
def __len__(self):
return len(self.corner_and_idxs)
def _crop(self, section, corner, width):
return section[corner[0]:corner[0]+width, corner[1]:corner[1]+width]
def _in_crop(self, section, corner):
return self._crop(section, corner, self.in_width)
# def _out_crop(self, section, corner):
# corner[0] += self.inner_offset
# corner[1] += self.inner_offset
# return self._crop(section, corner, self.out_width)
def __getitem__(self, idx):
corner, np_idx = self.corner_and_idxs[idx]
corner = deepcopy(corner)
in_section = self.np_set[np_idx]
in_section = self._in_crop(in_section, corner)
in_section = in_section.astype(np.float32)
out_section = in_section
# out_section = self._out_crop(out_section, corner)
# out_section = out_section.astype(np.float32)
return (in_section, out_section)