<jupyter_start><jupyter_text>Using Inception V3<jupyter_code>inet_model = inc_net.InceptionV3()
def transform_img_fn(path_list):
    out = []
    for img_path in path_list:
        img = image.load_img(img_path, target_size=(299, 299))
        x = image.img_to_array(img)
        x = np.expand_dims(x, axis=0)
        x = inc_net.preprocess_input(x)
        out.append(x)
    return np.vstack(out)<jupyter_output><empty_output><jupyter_text>Top 5 prediction for some image<jupyter_code>images = transform_img_fn(['cat_mouse.jpg'])
# I'm dividing by 2 and adding 0.5 because of how this Inception represents images
plt.imshow(images[0] / 2 + 0.5)
preds = inet_model.predict(images)
for x in decode_predictions(preds)[0]:
    print(x)<jupyter_output>('n02133161', 'American_black_bear', 0.63716084)
('n02105056', 'groenendael', 0.031817868)
('n02104365', 'schipperke', 0.029944103)
('n01883070', 'wombat', 0.028509649)
('n01877812', 'wallaby', 0.025093336)<jupyter_text>Explanation<jupyter_code>%load_ext autoreload
%autoreload 2
import os,sys
import lime
from lime import lime_image
explainer = lime_image.LimeImageExplainer()
%%time
# Hide color is the color for a superpixel turned OFF. Alternatively, if it is NONE, the superpixel will be replaced by the average of its pixels
explanation = explainer.explain_instance(images[0], inet_model.predict, top_labels=5, hide_color=0, num_samples=1000)<jupyter_output>Wall time: 1min 25s<jupyter_text>Black bear explanation<jupyter_code>from skimage.segmentation import mark_boundaries
temp, mask = explanation.get_image_and_mask(295, positive_only=True, num_features=5, hide_rest=True)
plt.imshow(mark_boundaries(temp / 2 + 0.5, mask))
temp, mask = explanation.get_image_and_mask(295, positive_only=True, num_features=5, hide_rest=False)
plt.imshow(mark_boundaries(temp / 2 + 0.5, mask))<jupyter_output><empty_output><jupyter_text>Explanation for Wombat<jupyter_code>temp, mask = explanation.get_image_and_mask(106, positive_only=True, num_features=5, hide_rest=True)
plt.imshow(mark_boundaries(temp / 2 + 0.5, mask))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11567877629063097, 'fraction_numerical': 0.06644359464627152, 'mean_word_length': 6.780669144981412, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '558118', 'license': 'MIT', 'n_tokens_mistral': 869, 'n_tokens_neox': 767, 'n_words': 154, 'path': 'Lime_example.ipynb', 'repo_name': 'tutelaris/data-processing', 'size': '2092'}