-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.py
More file actions
33 lines (25 loc) · 830 Bytes
/
Copy pathdataset.py
File metadata and controls
33 lines (25 loc) · 830 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
import configs
import glob
import tensorflow as tf
import PIL.Image as pil_image
import numpy as np
class Dataset(object):
def __init__(self, path):
self.imagesRef = sorted(glob.glob(path + '/*/*'))
#print("self.imagesRef")
#print(self.imagesRef)
def __getitem__(self, idx):
image = tf.io.read_file(self.imagesRef[idx])
#print("image")
#print(image)
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.resize_with_pad(image, 400,400)
#image = pil_image.fromarray(image.numpy())
image = np.array(image).astype(np.float32)
image = np.transpose(image, axes=[2, 0, 1])
# normalization
image /= 255.0
#print(image)
return image
def __len__(self):
return len(self.imagesRef)