Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected keyword argument 'progress_bar' for lime_image.LimeImageExplainer().explain_instance() #739

Open
momchilgeorgiev opened this issue Feb 8, 2024 · 0 comments

Comments

@momchilgeorgiev
Copy link

momchilgeorgiev commented Feb 8, 2024

Similar to issue #660 and #480 (specifically this part), lime_image.LimeImageExplainer().explain_instance() throws out an error when trying to hide tqdm progress bar.

This is for lime 0.2.0.1 installed via pip. I made sure to update before posting here. I am also running everything in wsl2, config: Ubuntu 22.04.3 LTS in a conda environment, because of TensorFlow requirements on windows systems.

I wanted to share since sometimes it's pretty unusable when working in a notebook. Am I doing something wrong?

I have also checked the source code:
image

Code:

def plot_lime(img_path, model):
    # img_path - str
    # model - tf model instance
    # Get an image path and a model and plot 

    print(f'Processing {img_path}')
    # Explain a prediction
    explainer = lime_image.LimeImageExplainer()
    segmenter = SegmentationAlgorithm('slic', n_segments=100, compactness=1, sigma=1) 

    img = preprocess_image(img_path)[0]  # Preprocess the image

    # Make predictions
    preds = model.predict(img[np.newaxis, ...])  # Add batch dimension
    top_pred_index = np.argmax(preds[0])  # Index of the top prediction
    top_pred_label = ['NORMAL', 'PNEUMONIA'][top_pred_index]  
    top_pred_prob = preds[0][top_pred_index]  # Probability of top prediction

    # Get the explanation
    explanation = explainer.explain_instance(img.astype('double'), 
                                            classifier_fn=model.predict, 
                                            top_labels=1, 
                                            hide_color=0, 
                                            num_samples=1000, 
                                            segmentation_fn=segmenter,
                                            progress_bar=False
                                            )

    # Display the top label's explanation
    temp, mask = explanation.get_image_and_mask(explanation.top_labels[0], positive_only=True, num_features=50)
    plt.imshow(mark_boundaries(temp / 2 + 0.5, mask))
    plt.show()

    print(f"Model's predicted class: {top_pred_label} with probability {top_pred_prob}")

Call function:

plot_lime(image_path, resnet_balanced)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[29], [line 1](vscode-notebook-cell:?execution_count=29&line=1)
----> [1](vscode-notebook-cell:?execution_count=29&line=1) plot_lime(image_path, resnet_balanced)

Cell In[28], [line 27](vscode-notebook-cell:?execution_count=28&line=27)
     [24](vscode-notebook-cell:?execution_count=28&line=24) top_pred_prob = preds[0][top_pred_index]  # Probability of top prediction
     [26](vscode-notebook-cell:?execution_count=28&line=26) # Get the explanation
---> [27](vscode-notebook-cell:?execution_count=28&line=27) explanation = explainer.explain_instance(img.astype('double'), 
     [28](vscode-notebook-cell:?execution_count=28&line=28)                                         classifier_fn=model.predict, 
     [29](vscode-notebook-cell:?execution_count=28&line=29)                                         top_labels=1, 
     [30](vscode-notebook-cell:?execution_count=28&line=30)                                         hide_color=0, 
     [31](vscode-notebook-cell:?execution_count=28&line=31)                                         num_samples=1000, 
     [32](vscode-notebook-cell:?execution_count=28&line=32)                                         segmentation_fn=segmenter,
     [33](vscode-notebook-cell:?execution_count=28&line=33)                                         progress_bar=False
     [34](vscode-notebook-cell:?execution_count=28&line=34)                                         )
     [36](vscode-notebook-cell:?execution_count=28&line=36) # Display the top label's explanation
     [38](vscode-notebook-cell:?execution_count=28&line=38) temp, mask = explanation.get_image_and_mask(explanation.top_labels[0], positive_only=True, num_features=50)

TypeError: explain_instance() got an unexpected keyword argument 'progress_bar'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant