-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
44 lines (27 loc) · 1.19 KB
/
tests.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
from PIL import Image
from transformers import SegformerFeatureExtractor
from matplotlib import pyplot as plt
import numpy as np
import torch
image = Image.open("data/training/images/satimage_117.png").convert("RGB")
segmentation = Image.open("data/training/groundtruth/satimage_117.png") #.convert("RGB")
image.show()
segmentation.show()
extractor = SegformerFeatureExtractor(reduce_labels=False, size=400, do_normalization=False)
encoded_inputs = extractor(image, segmentation, return_tensors="pt")
pixel_values = encoded_inputs["pixel_values"]
label_values = encoded_inputs["labels"]
print("pixel values ", pixel_values.shape , "label values ", label_values.shape)
pixel_values = pixel_values.squeeze_()
label_values = label_values.squeeze_()
print("pixel values ", pixel_values.shape , "label values ", label_values.shape)
pixel_values = torch.moveaxis(pixel_values, 0, -1)
#label_values = torch.moveaxis(label_values, 0, -1)
print("pixel values ", pixel_values.shape , "label values ", label_values.shape)
f = plt.figure()
f.add_subplot(1,2, 1)
plt.imshow(pixel_values, interpolation='nearest')
f.add_subplot(1,2, 2)
plt.imshow(label_values, interpolation='nearest')
plt.show(block=True)
f.show()