解釋食物影像的預測
你有一個用來分類食物的 model,你的任務是使用 LIME 來找出該模型在對下方 image 做出預測時,主要關注的區域。
負責產生預測的 model、model_predict 函式,以及下方的範例 image 都已為你預先載入。

本練習屬於課程
Python 的 Explainable AI
練習說明
- 建立一個名為
explainer的 LIME 影像解釋器。 - 針對給定的
image,為model的預測產生一個explanation。 - 根據
model的解釋,從image中擷取重點關注區域。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from lime import lime_image
np.random.seed(10)
# Create a LIME explainer
explainer = lime_image.____()
# Generate the explanation
explanation = explainer.____(____, ____, hide_color=0, num_samples=50)
# Display the explanation
temp, _ = explanation.____(____, ____)
plt.imshow(temp)
plt.title('LIME Explanation')
plt.axis('off')
plt.show()