-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
56 lines (43 loc) · 1.75 KB
/
helpers.py
File metadata and controls
56 lines (43 loc) · 1.75 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
52
53
54
55
56
import numpy as np
import torch
import torchvision
import torch.nn as nn
import torch.optim as optim
import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def plot_img(img):
plt.imshow(np.array(img.permute(1,2,0).cpu().int()))
def plot_roads(gt):
plt.imshow(gt.detach().cpu().numpy(), cmap='gray')
def get_sets(n = 100, train = True):
import os
if train:
root_dir = "training/"
image_dir = root_dir + "images/"
gt_dir = root_dir + "groundtruth/"
files = os.listdir(image_dir)
Images = torch.tensor([])
GroundTruths = torch.tensor([])
for i in range(n):
image = torchvision.io.read_image(image_dir + files[i]).unsqueeze(0).float()
groundtruth = mpimg.imread(gt_dir+files[i])
groundtruth = torch.tensor(groundtruth).unsqueeze(0).float()
Images = torch.cat((Images, image))
GroundTruths = torch.cat((GroundTruths, groundtruth))
if (i+1)%10==0:
print('{}/{} images loaded'.format(i+1,len(files)))
else:
root_dir = "test_set_images/"
image_dir = root_dir
files = os.listdir(image_dir)
import re
files.sort(key=lambda test_string : list( map(int, re.findall(r'\d+', test_string)))[0])
Images = torch.tensor([])
GroundTruths = torch.tensor([])
for i in range(len(files)):
image = torchvision.io.read_image(image_dir + files[i] + "/" + files[i] + ".png").unsqueeze(0).float()
Images = torch.cat((Images, image))
if (i+1)%10==0:
print('{}/{} images loaded'.format(i+1,len(files)))
return Images, GroundTruths