<jupyter_start><jupyter_text>The following code will help you in calculating the accuracy on the test dataset. Please note that the structure in which the test data is stored needs to the same as that of the train or the validation dataset. Choose one of the models saved during training to calculate the test accuracy.<jupyter_code>from keras.models import load_model, Model
#######
    
model_name = '/storage/Final_data/model_init_conv_lstm_2018-10-0316_27_25.831386/model-00041-0.05310-0.99698-0.85627-0.71000.h5'
    
#######
    
test_doc = open('/notebooks/storage/Final_data/Collated_training/test.csv').readlines()
test_path = '/notebooks/storage/Final_data/Collated_training/test'
num_test_sequences = len(test_doc)
print ('# testing sequences =', num_test_sequences)
test_generator = generator(test_path, test_doc, batch_size)
model = load_model(model_name)
print("Model loaded.")
model_func = Model(inputs=[model.input], outputs=[model.output])
    
acc = 0
    
num_batches = int(num_test_sequences/batch_size)
    
for i in range(num_batches):
    x,true_labels = test_generator.__next__()
    print ("shape of x:", x.shape, "and shape of true_labels:", true_labels.shape)
    pred_idx = np.argmax(model_func.predict_on_batch(x), axis=1)
    for j,k in enumerate(pred_idx):
        if true_labels[j,k] == 1:
            acc += 1
                
if (num_test_sequences%batch_size) != 0:
    x,true_labels = test_generator.__next__()
    print ("shape of x:", x.shape, "and shape of true_labels:", true_labels.shape)
    pred_idx = np.argmax(model_func.predict_on_batch(x), axis=1)
    for j,k in enumerate(pred_idx):
        if true_labels[j,k] == 1:
            acc += 1

print('Accuracy is =', acc/num_test_sequences)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11627906976744186, 'fraction_numerical': 0.032898468519568916, 'mean_word_length': 4.313253012048193, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '296858', 'license': 'Apache-2.0', 'n_tokens_mistral': 626, 'n_tokens_neox': 583, 'n_words': 141, 'path': '06Deep Learning/06Neural Networks Project - Gesture Recognition/Test+Code.ipynb', 'repo_name': 'talk2sunil83/UpgradLearning', 'size': '1763'}