-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphTry.py
137 lines (109 loc) · 2.89 KB
/
graphTry.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
import matplotlib.pyplot as plt
FGnet_path = "./datasets/FGNET/images/"
images_path = os.listdir(FGnet_path)
finalData = []
for i, path in enumerate(images_path):
names = path.split(".")[0]
names = names.split("A")
names[1] = names[1].replace("a", "")
names[1] = names[1].replace("b", "")
# finalData.append([int(names[0]), int(names[1])])
finalData.append([names[0], int(names[1])])
# print(finalData)
collectingData = {}
# collectingData["sd"] = []
for data in finalData:
try:
collectingData[data[0]].append(data[1])
except:
# print("An exception occurred")
collectingData[data[0]] = [data[1]]
# print(collectingData)
finalCollectionLabels = []
finalCollectionValues = []
imgCount = []
finalAvgDiff = []
for data in collectingData:
sum = 0
lastIndex = 0
deffCount = 0
deffSum = 0
for i, ages in enumerate(collectingData[data]):
try:
if id((collectingData[data][i + 1] - ages) != 0):
deffSum = deffSum + (collectingData[data][i + 1] - ages)
deffCount = deffCount + 1
except:
pass
sum = sum + ages
lastIndex = i
avgDef = deffSum / deffCount
avg = sum / (lastIndex + 1)
finalCollectionLabels.append(int(data))
finalCollectionValues.append(avg)
imgCount.append((lastIndex + 1))
finalAvgDiff.append(avgDef)
# print(finalCollection[0])
sumImgCount = 0
totImgCount = 0
for var in imgCount:
sumImgCount += var
totImgCount += 1
avgImgCount = sumImgCount / totImgCount
print(avgImgCount)
###############################################
sumOffinalAvgDiff = 0
totFinalAvgDiff = 0
for var in finalAvgDiff:
sumOffinalAvgDiff = sumOffinalAvgDiff + var
totFinalAvgDiff = totFinalAvgDiff + 1
avgFinalAvgDiff = sumOffinalAvgDiff / totFinalAvgDiff
print(avgFinalAvgDiff)
plt.bar(
finalCollectionLabels,
imgCount,
tick_label=finalCollectionLabels,
width=0.4,
color=["red", "green"],
)
# naming the x-axis
plt.xlabel("Labels")
# naming the y-axis
plt.ylabel("Number of imgs")
# plot title
plt.title("Number of images for eash person")
# function to show the plot
plt.show()
## should make avg age diffrence between images for each person
plt.bar(
finalCollectionLabels,
finalCollectionValues,
tick_label=finalCollectionLabels,
width=0.4,
color=["red", "green"],
)
# naming the x-axis
plt.xlabel("Labels")
# naming the y-axis
plt.ylabel("Avg age")
# plot title
plt.title("Avarge Age")
# function to show the plot
plt.show()
#############################
plt.bar(
finalCollectionLabels,
finalAvgDiff,
tick_label=finalCollectionLabels,
width=0.4,
color=["red", "green"],
)
# naming the x-axis
plt.xlabel("Labels")
# naming the y-axis
plt.ylabel("Avg age diff")
# plot title
plt.title("Avarge difference in Age between images for each Person")
# function to show the plot
plt.show()