-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add basic CLI #97
Closed
Closed
Add basic CLI #97
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48c94ae
Add basic cli skaffold
indyfree ede6f84
Improve error handling
indyfree d85c0f3
Only log tensorflow errors
indyfree 8b6970d
Add initial usecase
indyfree 7e3be25
Allow face to pass no hyperparams
indyfree 194beea
Revove old changes
indyfree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import click | ||
|
||
from carla import DataCatalog, MLModelCatalog | ||
from carla.recourse_methods import * | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
click.echo("Hello World") | ||
|
||
|
||
@cli.command() | ||
@click.option( | ||
"--data", | ||
"data_name", | ||
default="adult", | ||
help="The dataset to generate counterfactuals on", | ||
type=click.Choice(["adult", "compas"], case_sensitive=False), | ||
) | ||
@click.option( | ||
"--model", | ||
"model_name", | ||
required=True, | ||
default="ann", | ||
help="The black-box model to use", | ||
type=click.Choice(["ann", "lr"], case_sensitive=False), | ||
) | ||
@click.option( | ||
"--method", | ||
"method_name", | ||
required=True, | ||
default="gs", | ||
help="The counterfactual method to run", | ||
type=click.Choice(["gs", "face"], case_sensitive=False), | ||
) | ||
@click.option( | ||
"--sample-size", | ||
required=True, | ||
default=5, | ||
help="The number of factual samples from the dataset", | ||
) | ||
def run(data_name, method_name, model_name, sample_size): | ||
click.echo("Run a single counterfactual method") | ||
dataset = DataCatalog(data_name) | ||
model = MLModelCatalog(dataset, model_name) | ||
|
||
if method_name == "gs": | ||
method = GrowingSpheres(model) | ||
elif method_name == "face": | ||
method = Face(model) | ||
else: | ||
raise ValueError(f"Recourse model {model_name} unknown.") | ||
|
||
factuals = dataset.raw.sample(sample_size) | ||
counterfactuals = method.get_counterfactuals(factuals) | ||
click.echo(counterfactuals) | ||
|
||
|
||
@cli.command() | ||
def benchmark(): | ||
click.echo("Benchmark") | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,15 @@ | |
from urllib.error import HTTPError | ||
from urllib.request import urlretrieve | ||
|
||
import logging | ||
|
||
import tensorflow as tf | ||
import torch | ||
|
||
|
||
tf.get_logger().setLevel(logging.ERROR) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove more tensorflow warnings |
||
|
||
|
||
def load_model( | ||
name: str, | ||
dataset: str, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ | |
packages=find_packages(exclude=("test",)), | ||
include_package_data=True, | ||
install_requires=[ | ||
"Click==8.0.1", | ||
"dice-ml==0.5", | ||
"h5py==2.10.0", | ||
"ipython", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Philoso-Fish do we really need ipyhon btw? That seems to be more for notebooks etc? |
||
"keras==2.3.0", | ||
"lime==0.2.0.1", | ||
"mip==1.12.0", | ||
"numpy==1.19.4", | ||
|
@@ -45,9 +50,10 @@ | |
"tensorflow==1.14.0", | ||
"torch==1.7.0", | ||
"torchvision==0.8.1", | ||
"h5py==2.10.0", | ||
"dice-ml==0.5", | ||
"ipython", | ||
"keras==2.3.0", | ||
], | ||
entry_points={ | ||
"console_scripts": [ | ||
"carla = carla.carla:cli", | ||
], | ||
}, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @Philoso-Fish , this one supresses the ugly:
warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really great 👍