-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinalPredictionsProcessing.py
155 lines (99 loc) · 4.26 KB
/
FinalPredictionsProcessing.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 23 16:52:16 2019
@author: nithish k
"""
import glob
import os
import imageManipulations
import plotGridAndBound
import XMLParser
import assigngrid
import normalization
import denormalization
import generateTargetVariable
import decodePredictionArray
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import pickle
import nonMaxSupression
GRID_SIZE = 19
###image dicts
"""
Note: need to change class mapping dict as required as global variable
"""
classMappingDict = {'milk':0,'tomato': 1, 'apple':2 , 'eggs':3 ,'onion': 4,
'salt':5, 'yogurt': 6, 'sugar': 7, 'butter': 8, 'orange':9}
###has all of the Image informations as list of dicts
###plot at image level
def visualisePredictions(trueImgDict,trueObjList,imgPath,eachPredictionArray,
overlapThresh,probThres,dispClassLabel,checkLabels):
"""
Should shange the thresholds if required
change grid size as well if needed
"""
global classMappingDict
pred_objectList = decodePredictionArray.decodePredArr(trueImgDict,
eachPredictionArray,
classMappingDict)
postNonMaxPredObjList = nonMaxSupression.non_max_supression_wrapper(pred_objectList,classMappingDict,
overlapThresh,probThres,checkLabels)
gridImg = plotGridAndBound.plotGridOnImg(imgPath,GRID_SIZE,GRID_SIZE,postNonMaxPredObjList,
dispClassLabel= dispClassLabel,grid =False)
plt.figure()
def visualise_preds_for_set_of_images(imgFilePathList,
ImgDictsPath_True_Path,
ObjLists_True_Path,
predictionArrayPath,
overlapThresh=0.5,probThres=0.5,
maxImagesToPlot = 10,dispClassLabel = False, checkLabels= True, index_range = (0,10)):
"""
requires :
img dict pkl file
objectList pkl file
predictions pkl file
imagepaths list
"""
global classMappingDict
imgFilePaths_list = imgFilePathList
ListOf_imgDicts_true = pickle.load(open(ImgDictsPath_True_Path, 'rb'))
ListOf_ObjLists_true = pickle.load(open(ObjLists_True_Path, 'rb'))
ListOf_PredictionY = pickle.load(open(predictionArrayPath, 'rb'))
for index in range(index_range[0], index_range[1]):
visualisePredictions(ListOf_imgDicts_true[index],
ListOf_ObjLists_true[index],imgFilePaths_list[index],
ListOf_PredictionY[index],
overlapThresh,probThres,dispClassLabel, checkLabels)
#maxE = -float("Inf")
#for index,dic in enumerate(pred_objectList):
#
# if dic['ObjectnessProb'] >= maxE:
# maxE = dic['ObjectnessProb']
# maxIndex = index
#print(maxIndex)
#
#pred_objectList[maxIndex]
if __name__ == '__main__':
"""
Pretraining informations
"""
##pickle files
ImgDictsPath_True_Path = "Train images/annotations/ImageDictsAllFiles.pkl"
ObjLists_True_Path = "Train images/annotations/ObjectListsAllFiles.pkl"
###gets all the image as list
imagefileNames = "Train images/annotations/AllFileNames.pkl"
image_names_list = pickle.load(open(imagefileNames, 'rb'))
img_dir = "Train images/images/"
image_names_list = [img_dir+img_name for img_name in image_names_list]
"""
Prediction informations
"""
#### prediction array pickle path
predictionArrayPath = "Train images/annotations/PredictionArray.pkl"
visualise_preds_for_set_of_images(image_names_list,
ImgDictsPath_True_Path,
ObjLists_True_Path,
predictionArrayPath,
overlapThresh = 0.2,probThres= 0.98,
maxImagesToPlot = 10,index_range = (0,20), dispClassLabel=True,checkLabels=True)