<jupyter_start><jupyter_text>[LIME documentation](https://lime-ml.readthedocs.io/en/latest/index.html) <--  Previously trained VGG16<jupyter_code># Random seed for superpixels.
RSEED = 42

# Parameters for experimenting.
model_dir = "../results/classification/20201221_064530_INSTANCE/saved_model/20201221_064530"
layer_name = "block5_conv3"

# img_path = "/Users/cleonwong/Desktop/Code/mammogram-cv/data/preprocessed/Classification/all_classification_CROP/Calc-Test_P_01030_RIGHT_CC_CROP_1___PRE.png"
# img_path = "/Users/cleonwong/Desktop/Code/mammogram-cv/data/preprocessed/Classification/all_classification_CROP/Calc-Test_P_01030_RIGHT_CC_CROP_2___PRE.png"
# img_path = "/Users/cleonwong/Desktop/Code/mammogram-cv/data/preprocessed/Classification/all_classification_CROP/Mass-Training_P_00265_RIGHT_CC_CROP_1___PRE.png"
# img_path = "/Users/cleonwong/Desktop/Code/mammogram-cv/data/preprocessed/Classification/all_classification_CROP/Mass-Training_P_00921_RIGHT_CC_CROP_1___PRE.png"
# img_path = "/Users/cleonwong/Desktop/Code/mammogram-cv/data/preprocessed/Classification/all_classification_CROP/Mass-Training_P_01749_LEFT_MLO_CROP_1___PRE.png"
img_path = "/Users/cleonwong/Desktop/Code/mammogram-cv/data/preprocessed/Classification/all_classification_CROP/Mass-Training_P_00149_LEFT_MLO_CROP_1___PRE.png"
dsize = (224, 224)

# Load sample image for experimenting.
img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
img = cv2.resize(src=img, dsize=dsize)

# Min max normalise to [0, 1].
img = (img - img.min()) / (img.max() - img.min())

# Stack grayscale image to make channels=3.
img = np.stack([img, img, img], axis=-1)

# Make img shape into (1, 224, 224, 3).
img = img[np.newaxis, :]
plt.imshow(img[0], cmap="gray")
# Load previously trained model.
model = tf.keras.models.load_model(filepath=model_dir)<jupyter_output><empty_output><jupyter_text>Perform LIME<jupyter_code>explainer = lime_image.LimeImageExplainer()
explanation = explainer.explain_instance(img[0], classifier_fn=model.predict, top_labels=1, hide_color=0, num_samples=500, random_seed=RSEED)
temp, mask = explanation.get_image_and_mask(label=0, positive_only=True, hide_rest=True, num_features=5)
plt.imshow(mark_boundaries(temp, mask))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12449799196787148, 'fraction_numerical': 0.04462293618920125, 'mean_word_length': 7.397003745318352, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '372771', 'license': 'MIT', 'n_tokens_mistral': 934, 'n_tokens_neox': 846, 'n_words': 101, 'path': 'notebooks/Experiment_LIME.ipynb', 'repo_name': 'CleonWong/Can-You-Find-The-Tumour', 'size': '2241'}