forked from akrishna77/CS6476-VisRel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriplets_dataset_visualization.py
More file actions
71 lines (55 loc) · 2.67 KB
/
Copy pathtriplets_dataset_visualization.py
File metadata and controls
71 lines (55 loc) · 2.67 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import imageio
import matplotlib.pyplot as plt
import numpy as np
def visualizeDataset(filename, numExamples=10):
#No need to make changes from here
def getCoordinates(bbox):
x = bbox['x']
y = bbox['y']
w = bbox['w']
h = bbox['h']
x2 = x+w
y2 = y+h
x_coordinates = np.array([x,x,x2,x2,x])
y_coordinates = np.array([y,y2,y2,y,y])
return x_coordinates, y_coordinates
import json
filter = "JSON file (*.json)|*.json|All Files (*.*)|*.*||"
#Read JSON data into the datastore variable
if filename:
with open(filename, 'r') as f:
datastore = json.load(f)
print("Total Positive Negative Example Pairs for this predicate = ",len(datastore['examples']))
for it in range(min(len(datastore['examples']),numExamples)):
filename1 = datastore['examples'][it]['filename1']
filename2 = datastore['examples'][it]['filename2']
p_bb1 = datastore['examples'][it]['positive']['bbox1']
p_bb2 = datastore['examples'][it]['positive']['bbox2']
n_bb1 = datastore['examples'][it]['negative']['bbox1']
n_bb2 = datastore['examples'][it]['negative']['bbox2']
p_obj1 = datastore['examples'][it]['positive']['obj1']
p_obj2 = datastore['examples'][it]['positive']['obj2']
n_obj1 = datastore['examples'][it]['negative']['obj1']
n_obj2 = datastore['examples'][it]['negative']['obj2']
p_pred = datastore['examples'][it]['positive']['relationship']
n_pred = datastore['examples'][it]['negative']['relationship']
img1 = imageio.imread("sg_dataset/sg_test_images/"+filename1)
img2 = imageio.imread("sg_dataset/sg_test_images/"+filename2)
plt.subplot(121)
plt.title("Positive Example: \n"+p_obj1+", "+p_pred+", "+p_obj2)
plt.imshow(img1)
coordinates_x, coordinates_y = getCoordinates(p_bb1)
plt.plot(coordinates_x, coordinates_y, 'b-')
coordinates_x, coordinates_y = getCoordinates(p_bb2)
plt.plot(coordinates_x, coordinates_y, 'b-')
plt.subplot(122)
plt.title("Negative Example: \n" + n_obj1 + ", " + n_pred + ", " + n_obj2)
plt.imshow(img2)
coordinates_x, coordinates_y = getCoordinates(n_bb1)
plt.plot(coordinates_x, coordinates_y, 'r-')
coordinates_x, coordinates_y = getCoordinates(n_bb2)
plt.plot(coordinates_x, coordinates_y, 'r-')
plt.show()
#Just enter filename
filename = "triplets_dataset/behind_test_triplets.json"
visualizeDataset(filename)