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

Met the issue about TypeError when using lime_image.LimeImageExplainer() #751

Open
CorleoneJW opened this issue Jul 9, 2024 · 0 comments

Comments

@CorleoneJW
Copy link

CorleoneJW commented Jul 9, 2024

Environment: lime -- 0.2.0.1
I just followed the document and just changed the image path.


def get_pil_transform(): 
    transf = transforms.Compose([
        transforms.Resize((224, 224)),
        # transforms.CenterCrop(224)
    ])    
    return transf

def batch_predict(images):
    model.eval()
    batch = torch.stack(tuple(eval_transforms(i) for i in images), dim=0)

    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model.to(device)
    batch = batch.to(device)
    
    logits, _ = model(batch)
    probs = F.softmax(logits, dim=1)
    return probs.detach().cpu().numpy()

from lime import lime_image

img = get_image('../data_finetune/sample.jpg')
pil_transform = get_pil_transform()
transformed_img = pil_transform(img)
explainer = lime_image.LimeImageExplainer()
explanation = explainer.explain_instance(np.array(transformed_img), 
                                         batch_predict, # classification function
                                         top_labels=1, 
                                         hide_color=0, 
                                         num_samples=1000) # number of images that will be sent to classification function

The shape of transformed_img is (224,224,3) and type of "np.adday(transformed_img)" is numpy.ndarray.

However, report the error as follows:
image
image
image

Could you help me solve this bug? Thank you so much for your kind help. I hope you have a good day.

Best regards

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