-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.py
72 lines (60 loc) · 2.07 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import torch
from torch.utils.data import Dataset
import glob
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os
class CityscapesDataset(Dataset):
def __init__(self, root, transforms=None):
super(CityscapesDataset, self).__init__()
self.transforms = transforms
self.dataset = glob.glob(root+"/train/*.jpg")
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
name = self.dataset[idx]
img = cv2.cvtColor(cv2.imread(name),cv2.COLOR_BGR2RGB)
img = img[:, :img.shape[1]//2]
img = cv2.resize(img, (128,128))
if self.transforms:
img = self.transforms(img)
return img
class tvtLaneDataset(Dataset):
def __init__(self, root, transforms=None):
super(tvtLaneDataset, self).__init__()
self.transforms = transforms
self.dataset = []
with open(root, 'r') as image_name:
while True:
lines = image_name.readline()
if not lines:
break
img_dir = lines.strip().split()[:-1]
for i in range(len(img_dir)):
img_dir[i] = img_dir[i][3:]
self.dataset.append(img_dir[:-1])
image_name.close()
self.dataset = [img for nest in self.dataset for img in nest]
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
name = self.dataset[idx]
img = cv2.imread(name)
if self.transforms:
img = self.transforms(img)
return img
class CULanesDataset(Dataset):
def __init__(self, root, transforms=None):
super(CULanesDataset, self).__init__()
self.root = root
self.transforms = transforms
self.dataset = glob.glob(root+"/*/*.jpg")
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
name = self.dataset[idx]
img = cv2.cvtColor(cv2.imread(name),cv2.COLOR_BGR2RGB)
if self.transforms:
img = self.transforms(img)
return img