From 5f303d8017e26f8323c39dd61126b0220a4b2fb6 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 15 Apr 2022 09:21:19 +0200 Subject: [PATCH 1/5] req --- templates/titanic/.meta.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/titanic/.meta.yml b/templates/titanic/.meta.yml index dbe94d793..ae7ec6a84 100644 --- a/templates/titanic/.meta.yml +++ b/templates/titanic/.meta.yml @@ -1,13 +1,13 @@ title: Solving Titanic dataset with Lightning Flash author: PL team created: 2021-10-15 -updated: 2021-12-10 +updated: 2022-04-10 license: CC build: 0 description: | This is a template to show how to contribute a tutorial. requirements: - - https://github.com/PyTorchLightning/lightning-flash/archive/refs/tags/0.5.2.zip#egg=lightning-flash[tabular] + - lightning-flash[tabular] - matplotlib - seaborn accelerator: From fe468cafd08d161d15022c3acf1f1af398f87b08 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 15 Apr 2022 09:35:26 +0200 Subject: [PATCH 2/5] pip --- .actions/assistant.py | 2 +- templates/titanic/tutorial.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.actions/assistant.py b/.actions/assistant.py index ada3a1015..13a1d71b5 100644 --- a/.actions/assistant.py +++ b/.actions/assistant.py @@ -372,7 +372,7 @@ def bash_test(folder: str, output_file: str = PATH_SCRIPT_TEST) -> Optional[str] if AssistantCLI._valid_accelerator(folder): # and install specific packages pip_req, pip_args = AssistantCLI._parse_requirements(folder) - cmd += [f"pip install {pip_req} --quiet {pip_args}", "pip list"] + cmd += [f"pip install {pip_req} {pip_args}", "pip list"] # TODO: add ` --quiet` # Export the actual packages used in runtime cmd.append(f"meta_file=$(python .actions/assistant.py update-env-details {folder} --base_path .)") # show created meta config diff --git a/templates/titanic/tutorial.py b/templates/titanic/tutorial.py index a82976fda..5831135fe 100644 --- a/templates/titanic/tutorial.py +++ b/templates/titanic/tutorial.py @@ -39,7 +39,7 @@ target_fields="Survived", train_file=csv_train, val_split=0.1, - batch_size=8, + batch_size=32, ) # %% [markdown] @@ -49,7 +49,7 @@ model = TabularClassifier.from_data( datamodule, learning_rate=0.1, - optimizer="Adam", + optimizer="AdamW", n_a=8, gamma=0.3, ) @@ -81,6 +81,7 @@ sns.relplot(data=metrics, kind="line") plt.gca().set_ylim([0, 1.25]) plt.gcf().set_size_inches(10, 5) +plt.grid() # %% [markdown] # ## 4. Generate predictions from a CSV From 320be490e868bb18a3b58d1a04dbb122d884982e Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 15 Apr 2022 10:48:19 +0200 Subject: [PATCH 3/5] flash --- templates/titanic/.meta.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/titanic/.meta.yml b/templates/titanic/.meta.yml index ae7ec6a84..594315f82 100644 --- a/templates/titanic/.meta.yml +++ b/templates/titanic/.meta.yml @@ -7,8 +7,9 @@ build: 0 description: | This is a template to show how to contribute a tutorial. requirements: - - lightning-flash[tabular] - - matplotlib + - lightning-flash[tabular]>=0.7 + - pandas>=1.0 + - matplotlib>=3.0 - seaborn accelerator: - CPU From bc068e7c3a362f2eb832aab5706d9ebb573e892c Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 15 Apr 2022 11:11:01 +0200 Subject: [PATCH 4/5] TM --- .actions/assistant.py | 2 +- templates/titanic/.meta.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.actions/assistant.py b/.actions/assistant.py index 13a1d71b5..ada3a1015 100644 --- a/.actions/assistant.py +++ b/.actions/assistant.py @@ -372,7 +372,7 @@ def bash_test(folder: str, output_file: str = PATH_SCRIPT_TEST) -> Optional[str] if AssistantCLI._valid_accelerator(folder): # and install specific packages pip_req, pip_args = AssistantCLI._parse_requirements(folder) - cmd += [f"pip install {pip_req} {pip_args}", "pip list"] # TODO: add ` --quiet` + cmd += [f"pip install {pip_req} --quiet {pip_args}", "pip list"] # Export the actual packages used in runtime cmd.append(f"meta_file=$(python .actions/assistant.py update-env-details {folder} --base_path .)") # show created meta config diff --git a/templates/titanic/.meta.yml b/templates/titanic/.meta.yml index 594315f82..bee360391 100644 --- a/templates/titanic/.meta.yml +++ b/templates/titanic/.meta.yml @@ -8,6 +8,7 @@ description: | This is a template to show how to contribute a tutorial. requirements: - lightning-flash[tabular]>=0.7 + - torchmetrics<0.8 # collision with `pytorch-tabular` which require PL 1.3.6 - pandas>=1.0 - matplotlib>=3.0 - seaborn From ccbde640eca19ec2b5b21027df3dd66d0b5a5e37 Mon Sep 17 00:00:00 2001 From: Jirka Date: Fri, 15 Apr 2022 11:25:41 +0200 Subject: [PATCH 5/5] inference --- templates/titanic/tutorial.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/templates/titanic/tutorial.py b/templates/titanic/tutorial.py index 5831135fe..4eb0d691d 100644 --- a/templates/titanic/tutorial.py +++ b/templates/titanic/tutorial.py @@ -89,13 +89,21 @@ # %% df_test = pd.read_csv(csv_test) -predictions = model.predict(csv_test) -print(predictions[0]) +dm = TabularClassificationData.from_data_frame( + predict_data_frame=df_test, + parameters=datamodule.parameters, + batch_size=datamodule.batch_size, +) +preds = trainer.predict(model, datamodule=dm, output="classes") +print(preds[0][:10]) # %% +import itertools # noqa: E402] + import numpy as np # noqa: E402] -assert len(df_test) == len(predictions) +predictions = list(itertools.chain(*preds)) +# assert len(df_test) == len(predictions) df_test["Survived"] = np.argmax(predictions, axis=-1) df_test.set_index("PassengerId", inplace=True)