I am using the below code neural network & then trying to interpret the network using LIME
import lime
from lime import lime_image
from skimage.segmentation import mark_boundaries
model = Sequential()
model.add(Conv2D(32, kernel_size=3, padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=2))
model.add(Flatten())
# Output layer
model.add(Dense(32,activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train, Y_train, validation_data=(X_val, Y_val), epochs=epochs, batch_size=batch_size, verbose=1)
explainer = lime_image.LimeImageExplainer(random_state=42)
explanation = explainer.explain_instance(
X_val[x] #some random sample,
model.predict, top_labels=2,labels=iter([0,1])
)
image, mask = explanation.get_image_and_mask(1)
The last line is throwing error: KeyError: 'Label not in explanation' though working fine when passing 0 as parameter. But I wish to visualize for class 1.