Commit 3953cb74 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

vis2

parent 8fac9517
DEBUG=True
DEBUG=False
#python visualize-2.py results-video.npz
......@@ -30,6 +30,11 @@ def plot_confusion_matrix(y_true, y_pred, classes,
title = 'Normalized confusion matrix'
else:
title = 'Confusion matrix, without normalization'
else:
if normalize:
title = title+': Normalized confusion matrix'
else:
title = title+': Confusion matrix, without normalization'
# Compute confusion matrix
cm = confusion_matrix(y_true, y_pred)
......@@ -83,7 +88,7 @@ def plot_confusion_matrix(y_true, y_pred, classes,
ha="center", va="center",
color="white" if cm[i, j] > thresh else "black")
fig.tight_layout()
plt.show()
return ax
......@@ -95,8 +100,8 @@ def convolve2D(X,Y,XY):
for i in range(XY.shape[0]):
for j in range(XY.shape[1]):
if DEBUG:
print("DEBUG: convs X ",X[i:i+Y.shape[0],j:j+Y.shape[0]])
print("DEBUG: convs Y ",Y)
if DEBUG: print("DEBUG: convs X ",X[i:i+Y.shape[0],j:j+Y.shape[0]])
if DEBUG: print("DEBUG: convs Y ",Y)
XY[i,j]=np.sum(np.sum(X[i:i+Y.shape[0],j:j+Y.shape[0]] * Y))
if DEBUG: print("DEBUG",i,j,XY[i,j])
......@@ -116,7 +121,7 @@ def test_convolve2D():
print("Conv X,Y=",ZZ)
def countMisses(yTrue,yPred,windowH,windowW):
def countMisses(yTrue,yPred,windowH,windowW,testOrTrain=None):
global SQRT_CELLS
truePred=np.zeros(shape=(windowH*windowW,windowH*windowW),dtype=np.int32)
......@@ -124,7 +129,7 @@ def countMisses(yTrue,yPred,windowH,windowW):
yPred=np.reshape(yPred,(yPred.shape[0],SQRT_CELLS,SQRT_CELLS))
convKer=np.arange(windowH*windowW).reshape((windowH,windowW))
convKer=(2**np.arange(1,windowH*windowW+1)).reshape((windowH,windowW))
convTrue=np.zeros((yTrue.shape[0],SQRT_CELLS-windowH+1,SQRT_CELLS-windowW+1), dtype=np.int32)
convPred=np.zeros((yPred.shape[0],SQRT_CELLS-windowH+1,SQRT_CELLS-windowW+1), dtype=np.int32)
......@@ -146,7 +151,11 @@ def countMisses(yTrue,yPred,windowH,windowW):
if DEBUG:
print("convTrue shape={}, convPred shape={}".format(convTrue.shape,convPred.shape))
plot_confusion_matrix(convTrue,convPred,np.arange(2**(windowH*windowW)),param1=windowW,param2=windowH,normalize=True)
if testOrTrain!=None:
plot_confusion_matrix(convTrue,convPred,np.arange(2**(windowH*windowW)),param1=windowW,param2=windowH,normalize=True,title=testOrTrain)
else:
plot_confusion_matrix(convTrue,convPred,np.arange(2**(windowH*windowW)),param1=windowW,param2=windowH,normalize=True)
'''for y in range(convTrue.shape[0]):
......@@ -209,10 +218,26 @@ def drawTrainingHistograms(data,VID,FIG,CAPTION):
plt.title(TITLE)
plt.savefig(FIG_NAME,dpi=1000)
plt.show()
def modeHistogram(data):
vidName=sys.argv[4]
fileName=sys.argv[5]
CAPTION=""
for x in range(6,len(sys.argv)):
CAPTION=CAPTION+" "+sys.argv[x]
drawTrainingHistograms(data,vidName,fileName,CAPTION)
def modeAnalyze(data):
codeH=int(sys.argv[4])
codeW=int(sys.argv[5])
countMisses(data['yTrueTest'],data['yPredTest'], codeH, codeW,testOrTrain="Test")
countMisses(data['yTrueTrain'],data['yPredTrain'], codeH, codeW,testOrTrain="Train")
if __name__ == '__main__':
# test_convolve2D()
......@@ -225,27 +250,20 @@ if __name__ == '__main__':
MODE=sys.argv[3]
if MODE=='histogram' or MODE=='hist':
vidName=sys.argv[4]
fileName=sys.argv[5]
CAPTION=""
for x in range(6,len(sys.argv)):
CAPTION=CAPTION+" "+sys.argv[x]
drawTrainingHistograms(data,vidName,fileName,CAPTION)
modeHistogram(data)
elif MODE=='analyze':
codeH=int(sys.argv[4])
codeW=int(sys.argv[5])
countMisses(data['yTrueTest'],data['yPredTest'], codeH, codeW)
modeAnalyze(data)
else:
_=sys.argv[10000]#Just looking for something to give an error
plt.show()
if False:
print("python visualize-2.py res.npz 100 hist multivid multivid-with-inception")
print("python visualize-2.py res.npz 100 hist vid-name-for-plot file-name-to-save-plot")
print("python visualize-2.py res.npz 100 analyze 2 2")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment