'''Using an already trained model, run predictions on unknown images.'''

import random
import numpy as np
import pydot
import matplotlib.pyplot as plt

from train import partition_to_character_name_to_npz_paths, one_hot_decode

pydot.find_graphviz = lambda: True
from keras.models import load_model

model = load_model('weights.505.h5')

# from keras.utils import plot_model
# plot_model(model, to_file='model.pdf')

test_character_name_to_npz_path = partition_to_character_name_to_npz_paths['test']

for character_name, npz_paths in test_character_name_to_npz_path.items():
    random_npz_path = random.choice(npz_paths)
    pixels = np.load(random_npz_path)['pixels']
    predicted_labels = model.predict(np.array([pixels]), batch_size=1)
    character_name_to_probability = one_hot_decode(predicted_labels[0])
    top_character_probability = sorted(character_name_to_probability.items(),
                                       key=lambda item_tup: item_tup[1],
                                       reverse=True)[:3]
    top_character_names, top_character_probabilities = zip(*top_character_probability)
    print(top_character_probability)

    ax1 = plt.subplot2grid((7, 1), (0, 0), rowspan=6)
    ax1.set_title(character_name)
    ax2 = plt.subplot2grid((7, 1), (6, 0), rowspan=1)
    ax1.imshow(pixels)
    y_pos = np.arange(len(top_character_names))*0.11
    ax2.barh(y_pos, top_character_probabilities, height=0.1, align='center',
            color='cyan', ecolor='black')
    ax2.set_yticks(y_pos)
    ax2.set_yticklabels(top_character_names, position=(1,0))
    ax2.invert_yaxis()
    plt.show()

@@ -66,24 +66,35 @@
 ges.'''%0A
+import json
 %0Aimport 
 random%0Ai
@@ -85,21 +85,19 @@
 %0Aimport 
-rando
+tqd
 m%0Aimport
@@ -113,21 +113,8 @@
  np%0A
-import pydot%0A
 impo
@@ -140,16 +140,26 @@
 t as plt
+%0Aimport os
 %0A%0Afrom t
@@ -227,16 +227,28 @@
 _decode%0A
+import pydot
 %0Apydot.f
@@ -336,16 +336,29 @@
 el('
+all_networks/
 weights.
 505.
@@ -357,11 +357,10 @@
 hts.
-505
+46
 .h5'
@@ -475,16 +475,19 @@
 _path = 
+%7B**
 partitio
@@ -530,118 +530,431 @@
 st'%5D
-%0A%0Afor character_name, npz_paths in test_character_name_to_npz_path.items():%0A    random_npz_path = random.choic
+, **partition_to_character_name_to_npz_paths%5B'validation'%5D%7D%0A%0Aoutput_json_name = 'all_predictions.json'%0Acharacter_to_predictions = %7B%7D%0Ajson.dump(character_to_predictions, open(output_json_name, 'w'))%0A%0Aflattened = %5B(character_name, npz_path) for character_name, npz_paths in test_character_name_to_npz_path.items() for npz_path in npz_paths%5D%0Afor character_name, npz_path in tqdm.tqdm(flattened):%0A    npz_name = os.path.basenam
 e(np
@@ -959,17 +959,16 @@
 npz_path
-s
 )%0A    pi
@@ -986,15 +986,8 @@
 oad(
-random_
 npz_
@@ -1147,49 +1147,33 @@
 s%5B0%5D
-)%0A    top_character_probability = sorted(
+.astype(np.float64))%0A    
 char
@@ -1182,175 +1182,34 @@
 ter_
-name_
 to_pr
-obability.items(),%0A                                       key=lambda item_tup: item_tup%5B1%5D,%0A                                       reverse=True)%5B:3%5D%0A    top_
+edictions.setdefault(
 char
@@ -1222,96 +1222,43 @@
 name
-s
 , 
-top_character_probabilities = zip(*top_character_probability)%0A    print(top_character
+%7B%7D)%5Bnpz_name%5D = character_name_to
 _pro
@@ -1269,469 +1269,71 @@
 lity
-)
 %0A%0A
-    ax1 = plt.subplot2grid((7, 1), (0, 0), rowspan=6)%0A    ax1.set_title(character_name)%0A    ax2 = plt.subplot2grid((7, 1), (6, 0), rowspan=1)%0A    ax1.imshow(pixels)%0A    y_pos = np.arange(len(top_character_names))*0.11%0A    ax2.barh(y_pos, top_character_probabilities, height=0.1, align='center',%0A            color='cyan', ecolor='black')%0A    ax2.set_yticks(y_pos)%0A    ax2.set_yticklabels(top_character
+json.dump(character_to_predictions, open(output_json
 _name
-s
 , 
-position=(1,0))%0A    ax2.invert_yaxis()%0A    plt.show(
+'w')
 )%0A

Make prediction script write results to a file instead of plot them.