Commit 65282dd0 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

visualize grids

parent 3953cb74
......@@ -233,12 +233,79 @@ def modeHistogram(data):
def modeAnalyze(data):
def modeBlock(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")
def dispGrid(yTrue,yPred,title):
'''
REFERENCE:
https://stackoverflow.com/questions/10194482/custom-matplotlib-plot-chess-board-like-table-with-colored-cells
'''
global SQRT_CELLS
title=title+' : screen bit error locations'
yTrue=np.reshape(yTrue,(yTrue.shape[0],SQRT_CELLS,SQRT_CELLS))
yPred=np.reshape(yPred,(yPred.shape[0],SQRT_CELLS,SQRT_CELLS))
correctCount=((yTrue==yPred).astype(np.float32)).mean(axis=0)
cm=correctCount
normalize=False
cmap=plt.cm.Blues
classes=np.arange(SQRT_CELLS)
fig, ax = plt.subplots()
im = ax.imshow(cm, interpolation='nearest', cmap=cmap)
ax.figure.colorbar(im, ax=ax)
# We want to show all ticks...
ax.set(xticks=np.arange(cm.shape[1]),
yticks=np.arange(cm.shape[0]),
# ... and label them with the respective list entries
xticklabels=classes, yticklabels=classes,
title=title,
ylabel='Screen height',
xlabel='Screen width')
# Rotate the tick labels and set their alignment.
plt.setp(ax.get_xticklabels(), rotation=0, ha="right",
rotation_mode="anchor")
# Loop over data dimensions and create text annotations.
#fmt = '.2f' if normalize else 'd'
fmt = '.2f'
thresh = 0#cm.max() / np.inf
for i in range(cm.shape[0]):
for j in range(cm.shape[1]):
c='black'
ax.text(j, i, format(cm[i, j], fmt),ha="center", va="center", color=c)
fig.tight_layout()
#nrows, ncols = 9,9
#image = np.zeros(nrows*ncols)
# Set every other cell to a random number (this would be your data)
# image[::2] = np.random.random(nrows*ncols //2 + 1)
# Reshape things into a 9x9 grid.
# image = image.reshape((nrows, ncols))
'''row_labels = range(SQRT_CELLS)
col_labels = range(SQRT_CELLS)
plt.matshow(correctCount)
plt.xticks(range(SQRT_CELLS), col_labels)
plt.yticks(range(SQRT_CELLS), row_labels)'''
def modeGrid(data):
dispGrid(data['yTrueTest'],data['yPredTest'],"Test")
dispGrid(data['yTrueTrain'],data['yPredTrain'],"Train")
if __name__ == '__main__':
# test_convolve2D()
if True:
......@@ -252,9 +319,10 @@ if __name__ == '__main__':
if MODE=='histogram' or MODE=='hist':
modeHistogram(data)
elif MODE=='analyze':
modeAnalyze(data)
elif MODE=='block':
modeBlock(data)
elif MODE=='grid':
modeGrid(data)
else:
......@@ -264,7 +332,8 @@ if __name__ == '__main__':
if False:
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")
print("python visualize-2.py res.npz 100 block 2 2")
print("python visualize-2.py res.npz 100 grid")
......
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