# java-python weight training ops
weights = ['java_python.h5'
           ]  #,'java_python_no_code.h5','java_python_pv_no_code.h5']
for weight in weights:
    if weight == 'all_four.h5':
        options = four_options
        model = VGG(shape, 4)
    else:
        options = two_options
        model = VGG(shape, 2)
    # load weights file
    model.load_weights('../../jp_Fold_0/' + weight)
    # make directory for images
    os.mkdir('jp_Images/' + weight.replace('.h5', '/'))
    # predict classes for testing images
    predicitions = model.predict(images)

    # iterate over all the predictions to produce cam
    for i in range(len(predicitions)):
        # get class label from prediction
        code = np.argmax(predicitions[i])
        # label photo
        name = '_Predicted ' + options[code]

        location = 'jp_Images/' + weight.replace('.h5', '/') + str(i) + name
        cam = visualize_cam(model,
                            len(model.layers) - 1, code,
                            images[i].reshape((1, ) + shape))
        img = images[i]
        plt.imshow(overlay(cam, img))
        plt.savefig(location)
from prepare_data import *
import matplotlib.pyplot as plt
import random



train_x,train_y,val_x,val_y = create_data_test()

model = VGG(shape=(64, 256, 1))
model.summary()
model.load_weights(cf.CKP_PATH)

n = val_x.shape[0]

count = 0
pred = model.predict(val_x)
pred = np.argmax(pred,axis=-1)
true = np.argmax(val_y,axis = -1)
for i in range(n):
    if np.all(pred[i,:]==true[i]):
        count +=1
print("total acc: " +str(count/n*100)+"%")


k = random.randint(0,10000)  
imgplot = plt.imshow(val_x[k,:,:,:].reshape(64,256))  
arr = []
arr2 = []
for i in range(8):
    arr.append(dic[pred[k,i]])
    arr2.append(dic[true[k,i]])