Skip to content

Commit

Permalink
Add tests for docs plots on GPU (#1229)
Browse files Browse the repository at this point in the history
* Add tests for docs plots on GPU

* Update to use path

* Add license to file

* Fix tests plots on gpu to run only on source files

* Fix debug code

* Fix plot detection tutorial

* Fix

Co-authored-by: Itay Gabbay <itay@deepchecks.com>
  • Loading branch information
matanper and ItayGabbay committed Apr 10, 2022
1 parent 0fc6e9c commit 1f10d97
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def infer_on_batch(self, batch, model, device):
from deepchecks.vision.suites import full_suite

suite = full_suite()
result = suite.run(training_data, val_data, model, device)
result = suite.run(training_data, val_data, model, device=device)

#%%
# Observing the results:
Expand Down
6 changes: 3 additions & 3 deletions docs/source/tutorials/vision/plot_detection_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def infer_on_batch(self, batch, model, device):
training_data = TomatoData(data_loader=train_loader, label_map=LABEL_MAP)
val_data = TomatoData(data_loader=val_loader, label_map=LABEL_MAP)

training_data.validate_format(model)
val_data.validate_format(model)
training_data.validate_format(model, device=device)
val_data.validate_format(model, device=device)

# And observe the output:

Expand All @@ -334,7 +334,7 @@ def infer_on_batch(self, batch, model, device):
from deepchecks.vision.suites import full_suite

suite = full_suite()
result = suite.run(training_data, val_data, model, device)
result = suite.run(training_data, val_data, model, device=device)

#%%
# Observing the results:
Expand Down
34 changes: 34 additions & 0 deletions tests/vision/docs/test_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ----------------------------------------------------------------------------
# Copyright (C) 2021 Deepchecks (https://www.deepchecks.com)
#
# This file is part of Deepchecks.
# Deepchecks is distributed under the terms of the GNU Affero General
# Public License (version 3 or later).
# You should have received a copy of the GNU Affero General Public License
# along with Deepchecks. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------------
#
from pathlib import Path
from runpy import run_path

import torch
import wandb

# Since we have a plot that's calling `wandb.login` we need to setup first
wandb.setup(wandb.Settings(mode="disabled", program=__name__, program_relpath=__name__, disable_code=True))

DOCS_COMPILED_DIR = 'examples'


def test_plots_on_gpu():
"""If there is GPU available running all the docs plot files. Only makes sure the plots don't crash, and not \
testing any other display or functionality."""
if torch.cuda.is_available():
path = Path(__file__).parent.parent.parent.parent / "docs" / "source"

# Take only source file and excluding compiled files
source_files = set(path.glob("**/plot_*.py")) - set(path.glob(f"**/{DOCS_COMPILED_DIR}/plot_*.py"))
if not source_files:
raise ValueError("No plots found in docs/source")
for file in source_files:
run_path(str(file))

0 comments on commit 1f10d97

Please sign in to comment.