<jupyter_start><jupyter_text>Assess performance in the validation set<jupyter_code>yhat = model.predict_generator(generator_val, steps=len(generator_val))
metrics.accuracy_score(generator_val.classes, yhat>0.5)
metrics.roc_auc_score(generator_val.classes, yhat>0.5)
metrics.average_precision_score(generator_val.classes, yhat.ravel())<jupyter_output><empty_output><jupyter_text>Save weights<jupyter_code>model.save_weights('../data/resnet50_mouse_gloms_scale4.h5')<jupyter_output><empty_output><jupyter_text>Perform inference on the whole slide<jupyter_code>model.load_weights('../data/resnet50_mouse_gloms_scale4.h5')
fnxml  = "../data/14112.xml"

rreader = RoiReader(fnxml, threshold_tissue=True,
                    verbose=True, # prints out counts of ROIs below 
                   )

patch_iterator = slsl.PatchIterator(rreader, vertices=rreader.df_tissue.vertices.iloc[0],
                   points=None, side=256,
                   subsample=8, batch_size=4, preprocess=lambda x: preprocess_input(x.astype('float32')),
                   oversample=4, mode='grid' )
yhat = model.predict_generator(patch_iterator, steps=len(patch_iterator))
# for img, xy in patch_iterator:
#     break
import matplotlib.pyplot as plt
%matplotlib inline
# dir(patch_iterator)
plt.hist(yhat.ravel())
plt.scatter(patch_iterator.points[:,0], 
            patch_iterator.points[:,1],
            c=yhat.ravel(),
            cmap='coolwarm')
plt.axis('equal');
plt.gca().invert_yaxis() # y=0 is on top for images
rreader.plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1237848347375243, 'fraction_numerical': 0.018794556059624108, 'mean_word_length': 4.697416974169742, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '219230', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 550, 'n_tokens_neox': 524, 'n_words': 74, 'path': 'notebooks/demo-feed-keras.ipynb', 'repo_name': 'DSLituiev/slideslicer', 'size': '1543'}