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

XAI with Saliency library solution notebook #426

Merged
merged 5 commits into from
Apr 3, 2024
Merged

XAI with Saliency library solution notebook #426

merged 5 commits into from
Apr 3, 2024

Conversation

takumiohym
Copy link
Collaborator

@takumiohym takumiohym commented Mar 14, 2024

A new notebook for XAI with Saliency library. This notebook trains and explains a image classification model locally.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@takumiohym takumiohym marked this pull request as ready for review March 25, 2024 12:33
Copy link

review-notebook-app bot commented Mar 25, 2024

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2024-03-25T22:06:05Z
----------------------------------------------------------------

Can you add a line about what the Saliency library does?


takumiohym commented on 2024-03-27T16:43:21Z
----------------------------------------------------------------

Makes sense! Added.

Copy link

review-notebook-app bot commented Mar 25, 2024

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2024-03-25T22:06:06Z
----------------------------------------------------------------

Can you please break these functions up into multiple cells and provide an explanation of what each function does?


takumiohym commented on 2024-03-27T16:50:50Z
----------------------------------------------------------------

Actually this cell and description is taken by the vertex ai explanation notebook.

https://github.com/GoogleCloudPlatform/asl-ml-immersion/blob/master/notebooks/responsible_ai/explainable_ai/solutions/xai_image_vertex.ipynb

I think we can assume the user understand this basic flows as the vertex ai version assumes in this notebook, since it is not the focus.

Anyway I added a reference to another notebook in case students want to review what's going on here. I hope it helps!

BenoitDherin commented on 2024-03-28T16:08:55Z
----------------------------------------------------------------

I agree with Sanjana. Breaking that long code cell and adding one-liner explanations in markdown will help a lot.

takumiohym commented on 2024-04-02T19:50:51Z
----------------------------------------------------------------

Broke up to multiple cells, and removed unnecessary functions.

Copy link

review-notebook-app bot commented Mar 25, 2024

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2024-03-25T22:06:07Z
----------------------------------------------------------------

Line #36.            "https://tfhub.dev/google/imagenet/"

tfhub.dev is going to be deprecated soon, can you use the Kaggle Models link here instead?


takumiohym commented on 2024-03-27T16:53:35Z
----------------------------------------------------------------

Makes sense! Updated.

BenoitDherin commented on 2024-03-28T16:12:53Z
----------------------------------------------------------------

Please store the long URL into a separate variable at the beginning of the cell.

It seems to me some of the lines have more than 80 chars (pep8 violation). Maybe pass it through a pep8 formatter.

takumiohym commented on 2024-04-02T19:51:11Z
----------------------------------------------------------------

Modified. Thanks!

Copy link

review-notebook-app bot commented Mar 25, 2024

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2024-03-25T22:06:07Z
----------------------------------------------------------------

Can you add a brief explanation of Integrated Gradients here?


takumiohym commented on 2024-03-27T16:57:38Z
----------------------------------------------------------------

Added. Thanks!

Copy link

review-notebook-app bot commented Mar 25, 2024

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2024-03-25T22:07:11Z
----------------------------------------------------------------

Very nice! Thank you for adding this notebook!


takumiohym commented on 2024-03-27T16:57:50Z
----------------------------------------------------------------

Thank you for your feedback!

Copy link
Collaborator Author

Makes sense! Added.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Actually this cell and description is taken by the vertex ai explanation notebook.

https://github.com/GoogleCloudPlatform/asl-ml-immersion/blob/master/notebooks/responsible_ai/explainable_ai/solutions/xai_image_vertex.ipynb

I think we can assume the user understand this basic flows as the vertex ai version assumes in this notebook, since it is not the focus.

Anyway I added a reference to another notebook in case students want to review what's going on here. I hope it helps!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Makes sense! Updated.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Added. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Thank you for your feedback!


View entire conversation on ReviewNB

Copy link
Collaborator

I agree with Sanjana. Breaking that long code cell and adding one-liner explanations in markdown will help a lot.


View entire conversation on ReviewNB

Copy link
Collaborator

Please store the long URL into a separate variable at the beginning of the cell.

It seems to me some of the lines have more than 80 chars (pep8 violation). Maybe pass it through a pep8 formatter.


View entire conversation on ReviewNB

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:15Z
----------------------------------------------------------------

  • use Saliency library --> use the Saliency library
  • to explain the model --> to explain the model predictions
  • Add a "Learning Objective" to match the style of the other labs
  • "In this lab you will: " --> "Learning objectives:"


takumiohym commented on 2024-04-02T19:49:46Z
----------------------------------------------------------------

Modified. Thanks!

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:16Z
----------------------------------------------------------------

* Use "os.path.join" instead of concatenating with "+" (this will avoid issues with "//" or no "/" )


takumiohym commented on 2024-04-02T19:49:55Z
----------------------------------------------------------------

Modified. Thanks!

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:16Z
----------------------------------------------------------------

This is a long code cell. Maybe break it so that you can explain what the functions are doing in markdown cells above the code cells.


takumiohym commented on 2024-04-02T19:50:42Z
----------------------------------------------------------------

Broke up to multiple cells, and removed unnecessary functions.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:17Z
----------------------------------------------------------------

Punctuation: "Now that our image classification model has been trained, let's choose a target image we want to explain, and check the prediction result."


takumiohym commented on 2024-04-02T19:51:24Z
----------------------------------------------------------------

Modified.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:18Z
----------------------------------------------------------------

Please break this cell into one code cell per function and explain what these functions are doing in a markdown cell.


takumiohym commented on 2024-04-02T19:52:02Z
----------------------------------------------------------------

Removed these helper functions. Integrated all to a single ShowImage function defined above.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:19Z
----------------------------------------------------------------

  • "Saliency library" --> "the Saliency library"
  • Maybe define what is a "saliency based explanation" technique here.

takumiohym commented on 2024-04-02T19:52:49Z
----------------------------------------------------------------

Rewrote this section by adding detailed explanations.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:19Z
----------------------------------------------------------------

  • "call_model_function defines " --> "The call_model_function defines "
  • Define what a "saliency mask" is

takumiohym commented on 2024-04-02T19:53:19Z
----------------------------------------------------------------

Modified, and adde explanations on the saliency methods and masks.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:22Z
----------------------------------------------------------------

  • Explain what an integrated gradient mask is
  • From the explanation above it's not very clear what "GetMask" and "GetSmoothedMask" are doing. Maybe consider expanding on what is the output of these function and why it is useful.

takumiohym commented on 2024-04-02T19:56:23Z
----------------------------------------------------------------

Added comprehensive explanations.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:22Z
----------------------------------------------------------------

  • Explain what you mean by "integration with segmentation"
  • XARI --> XRAI

takumiohym commented on 2024-04-02T19:56:56Z
----------------------------------------------------------------

Expanded the entire XRAI explanations.

Copy link

review-notebook-app bot commented Mar 28, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-03-28T16:41:23Z
----------------------------------------------------------------

Add licence information.


takumiohym commented on 2024-04-02T19:57:06Z
----------------------------------------------------------------

Added. Thanks!

Copy link
Collaborator Author

Modified. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Modified. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Broke up to multiple cells, and removed unnecessary functions.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Broke up to multiple cells, and removed unnecessary functions.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Modified. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Modified.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Removed these helper functions. Integrated all to a single ShowImage function defined above.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Rewrote this section by adding detailed explanations.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Modified, and adde explanations on the saliency methods and masks.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Added explanations!

Regarding the function argument, this is what the Saliency library expects and can't be modified.

I think it's ok given this function is used not for generic purpose, but as a model wrapper to define an extra function for saliency methods.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Added those informations. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Added comprehensive explanations.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Expanded the entire XRAI explanations.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Added. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator

Thanks! Great!


View entire conversation on ReviewNB

Copy link

review-notebook-app bot commented Apr 2, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-04-02T20:24:40Z
----------------------------------------------------------------

  • that build -> that builds

takumiohym commented on 2024-04-03T10:03:38Z
----------------------------------------------------------------

Modified. Thanks!

Copy link

review-notebook-app bot commented Apr 2, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-04-02T20:24:41Z
----------------------------------------------------------------

Some typos fixed in the suggestion below:

"The code in the cell below contains the training logic. It starts by ingesting the data from GCS, then trains an image classification model using mobileNet as a feature extractor, and at last sends its output feature vector through a tf.keras.dense layer with 5 units (one unit per label) and a softmax activation ."


takumiohym commented on 2024-04-03T10:03:58Z
----------------------------------------------------------------

Modified. Thanks!

Copy link

review-notebook-app bot commented Apr 2, 2024

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2024-04-02T20:24:43Z
----------------------------------------------------------------

Something is off with the bullet points here. They don't seem to be matching the steps.


takumiohym commented on 2024-04-03T10:06:17Z
----------------------------------------------------------------

It seem it is a bug of this reviewer app. The original markdown was ok. (2. should come before "Compute gradients...")

Copy link
Collaborator

@BenoitDherin BenoitDherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator Author

Modified. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

Modified. Thanks!


View entire conversation on ReviewNB

Copy link
Collaborator Author

It seem it is a bug of this reviewer app. The original markdown was ok. (2. should come before "Compute gradients...")


View entire conversation on ReviewNB

@takumiohym takumiohym merged commit c746c86 into master Apr 3, 2024
5 checks passed
@takumiohym takumiohym deleted the saliency branch April 3, 2024 10:37
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

Successfully merging this pull request may close these issues.

2 participants