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

Vertex AI Image Classifier with Explainable Predictions (solution notebook) #168

Merged
merged 3 commits into from
Mar 14, 2022

Conversation

kylesteckler
Copy link
Collaborator

Solution Notebook for XAI Image Lab with Vertex. #165

  • Explore flower dataset
  • Build/package tensorflow model to train on Vertex AI
  • Train on Vertex AI
  • Upload/deploy model to Vertex AI
  • Serve predictions and visualize feature attributions from IG

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:07Z
----------------------------------------------------------------

  • "with Explanations" -> "with explanations"

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:08Z
----------------------------------------------------------------

Consider grouping all the imports at the beginning as in a standard Python file, so that all the notebook dependencies are immediately clear.

New comment: Did you run pre-commit? The import ordering within groups does not seem to be sorted by alphabetical order.

_sanjanalreddy commented on 2022-03-04T23:51:45Z_ ----------------------------------------------------------------

+1

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:08Z
----------------------------------------------------------------

Maybe shorten that cell into the following one-liner:

!gsutil ls -d | grep -w gs://${BUCKET}/ || gsutil mb -l ${REGION} gs://${BUCKET}


kylesteckler commented on 2022-03-08T20:45:09Z
----------------------------------------------------------------

When I run this one-liner with BUCKET='kylesteckler-demo' I get an error:

InvalidUrlError: Invalid bucket name in URL "-demo".

BenoitDherin commented on 2022-03-09T18:46:20Z
----------------------------------------------------------------

Have you tried quoting the bucket path as follows:

!gsutil ls -d | grep -w "gs://${BUCKET}/" || gsutil mb -l ${REGION} "gs://${BUCKET}"

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:09Z
----------------------------------------------------------------

  • Have all the imports at the beginning to the notebook (see comment above).

  • Instead of creating an alias, why not importing directly aiplatform, which is more readable than the acronym aip:

from google.cloud import aiplatform


@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:10Z
----------------------------------------------------------------

* "shuffle, split and copy" -> "shuffle, split, and copy"


@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:10Z
----------------------------------------------------------------

IMAGE_SIZE and BATCH_SIZE seem not to be used in this cell, maybe move them where we start using them?


@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:11Z
----------------------------------------------------------------

  • "task.py" -> "task.py"

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:12Z
----------------------------------------------------------------

Suggestion: What about using fire in order to parse the command line argument? Doing that would essentially get rid of the task.py.


takumiohym commented on 2022-03-07T03:10:34Z
----------------------------------------------------------------

+1

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:13Z
----------------------------------------------------------------

  • The code of this cell does not seem pep8 compliant (lines too long, only one space between functions, for instance). Have you passed it in a pep8 formater?(I notice that sometimes pre-commit fails to clean up code in notebook cells.)

  • What about importing the layers you need at the beginning of the file to avoid all the verbosity of having tf.keras.layers repeated at each layer? This way the code would be shorter and the model clearer to comprehend at a glance.

  • Same remark for tf.keras.Sequential

sanjanalreddy commented on 2022-03-04T23:55:32Z
----------------------------------------------------------------

Just a brief comment on what the architecture of the model is would be helpful in the markdown above. Since we aren't focusing on model building here, it might be useful to mention what kind of model we are using.

takumiohym commented on 2022-03-07T03:12:20Z
----------------------------------------------------------------

In terms of the model, how about just doing transfer learning?

That can shorten the training time, and get better result (and better explainability).

BenoitDherin commented on 2022-03-09T18:50:17Z
----------------------------------------------------------------

New comment: Did you run pre-commit? The code still doesn't look fully pep8 compliant (e.g., only one line between functions, lines looking too long)

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:13Z
----------------------------------------------------------------

Is is possible to escape the quote as follows so that the yaml files is more readable:

echo > ./config.yaml "\
workerPoolSpecs:
  machineSpec:
    machineType: n1-standard-8
  replicaCount: 1
  pythonPackageSpec:

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 4, 2022

View / edit / reply to this conversation on ReviewNB

BenoitDherin commented on 2022-03-04T23:09:14Z
----------------------------------------------------------------

Maybe adding something about what is going on in the following code could be useful since it is not obvious to understand:

m_call = tf.function(local_model.call).get_concrete_function(
    [
        tf.TensorSpec(
            shape=[None, 192, 192, 3], dtype=tf.float32, name=CONCRETE_INPUT
        )
    ]
)

and also why the xai_model needs it.


sanjanalreddy commented on 2022-03-04T23:59:21Z
----------------------------------------------------------------

Agree. It's not clear what the purpose is.

@sanjanalreddy sanjanalreddy self-requested a review March 4, 2022 23:45
Copy link
Collaborator

+1


View entire conversation on ReviewNB

Copy link
Collaborator

Just a brief comment on what the architecture of the model is would be helpful in the markdown above. Since we aren't focusing on model building here, it might be useful to mention what kind of model we are using.


View entire conversation on ReviewNB

Copy link
Collaborator

Agree. It's not clear what the purpose is.


View entire conversation on ReviewNB

@review-notebook-app
Copy link

review-notebook-app bot commented Mar 5, 2022

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2022-03-05T00:04:17Z
----------------------------------------------------------------

Add a note that restart of the kernel is needed


@review-notebook-app
Copy link

review-notebook-app bot commented Mar 5, 2022

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2022-03-05T00:04:18Z
----------------------------------------------------------------

Would be better to set the PROJECT ID using this to have consistency across notebooks in the repo

PROJECT = !(gcloud config get-value core/project)

PROJECT = PROJECT[0]

BUCKET = PROJECT # defaults to PROJECT

REGION = "us-central1" # Replace with your REGION


@review-notebook-app
Copy link

review-notebook-app bot commented Mar 5, 2022

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2022-03-05T00:04:19Z
----------------------------------------------------------------

Add a line on why we have to denormalize the image here


@review-notebook-app
Copy link

review-notebook-app bot commented Mar 5, 2022

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2022-03-05T00:04:19Z
----------------------------------------------------------------

Add a note above this cell that we are using

endpoint.explian() here to get the explanations and what steps should be followed when we need to get explanations.


Copy link
Collaborator

@sanjanalreddy sanjanalreddy left a comment

Choose a reason for hiding this comment

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

Thanks for updating this. Just added minor suggestions to improve the instructions!

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.

Added a few minor comments. Thanks for updating the lab.

Copy link
Collaborator

+1


View entire conversation on ReviewNB

Copy link
Collaborator

In terms of the model, how about just doing transfer learning?

That can shorten the training time, and get better result (and better explainability).


View entire conversation on ReviewNB

@takumiohym takumiohym self-requested a review March 8, 2022 01:55
Copy link
Collaborator Author

When I run this one-liner with BUCKET='kylesteckler-demo' I get an error:

InvalidUrlError: Invalid bucket name in URL "-demo".


View entire conversation on ReviewNB

Copy link
Collaborator

Have you tried quoting the bucket path as follows:

!gsutil ls -d | grep -w "gs://${BUCKET}/" || gsutil mb -l ${REGION} "gs://${BUCKET}"


View entire conversation on ReviewNB

Copy link
Collaborator

New comment: Did you run pre-commit? The code still doesn't look fully pep8 compliant (e.g., only one line between functions, lines looking too long)


View entire conversation on ReviewNB

@BenoitDherin
Copy link
Collaborator

LGTM. nit: It seems at time the code is not fully pep8 compliant.

@review-notebook-app
Copy link

View / edit / reply to this conversation on ReviewNB

sanjanalreddy commented on 2022-03-09T19:02:27Z
----------------------------------------------------------------

Looks like the confidence fell drastically using the tfhub model but nothing to worry about


Copy link
Collaborator

@sanjanalreddy sanjanalreddy 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

@takumiohym takumiohym left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for updating this.

@kylesteckler kylesteckler merged commit d769cc0 into master Mar 14, 2022
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.

4 participants