Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surajpaib committed Oct 16, 2021
1 parent 9cfd8a0 commit 052732e
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 229 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Your First Run (maps to aerial photo)
# Your First Run (facades)

For both types of install, running the basic maps to aerial photo example is the same.
For both types of install, running the basic facades example is the same.

Once the installation is complete and you can access the [CLI as shown](using_cli.md), run
```console
ganslate your-first-run
```
On running this, a few options will show up that can be customized. You may also leave it at its default values. Once the prompts
are completed, you will have a folder generated with a demo `maps` project in the path you specified.
are completed, you will have a folder generated with a demo `facades` project in the path you specified.

### Training
Next, you can run the training using the command below,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"project_name": "maps_project",
"number_of_iterations": 117700,
"project_name": "facades_project",
"number_of_iterations": 100000,
"batch_size": 1,
"logging_frequency": 500,
"checkpointing_frequency": 2000,
"generator_model": ["Resnet2D", "Unet2D"],
"cycle_consistency_ssim_percentage": 0.84,
"path": "."
"path": ".",
"enable_cuda": true
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
project: null

train:
output_dir: "./checkpoints/maps_default"
cuda: True
output_dir: "./checkpoints/facades_default"
cuda: {{ cookiecutter.enable_cuda }}
n_iters: {{ cookiecutter.number_of_iterations }}
n_iters_decay: {{ cookiecutter.number_of_iterations }}
batch_size: {{ cookiecutter.batch_size }}
Expand All @@ -16,7 +16,7 @@ train:

dataset:
_target_: ganslate.data.UnpairedImageDataset
root: "{{ cookiecutter.path }}/{{ cookiecutter.project_name }}/maps/train/"
root: "{{ cookiecutter.path }}/{{ cookiecutter.project_name }}/facades/train/"
num_workers: 4
image_channels: 3
preprocess: ["resize", "random_flip"]
Expand Down Expand Up @@ -55,7 +55,7 @@ train:
# freq: {{ cookiecutter.logging_frequency }} * 10
# dataset:
# _target_: ganslate.data.PairedImageDataset # Paired dataset for validation
# root: "{{ cookiecutter.path }}/{{ cookiecutter.project_name }}/maps/val"
# root: "{{ cookiecutter.path }}/{{ cookiecutter.project_name }}/facades/val"
# num_workers: 4
# image_channels: 3
# preprocess: ["resize"]
Expand All @@ -69,7 +69,7 @@ infer:
load_iter: 1
dataset:
_target_: ganslate.data.UnpairedImageDataset
root: "{{ cookiecutter.path }}/{{ cookiecutter.project_name }}/maps/test/"
root: "{{ cookiecutter.path }}/{{ cookiecutter.project_name }}/facades/test/"
num_workers: 4
image_channels: 3
preprocess: ["resize"]
Expand Down
15 changes: 11 additions & 4 deletions ganslate/utils/cli/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ def new_project(path):
cookiecutter(template, output_dir=path)

# First run
def setup_first_run(path, no_input=False, extra_context={}):
template = str(COOKIECUTTER_TEMPLATES_DIR / "your_first_run")
project_path = cookiecutter(template, output_dir=path, no_input=no_input,\
overwrite_if_exists=True, extra_context=extra_context)
download_datasets.download("facades", project_path)


@interface.command(help="Fetch resources for the maps first run")
@click.argument("path", default="./")
def your_first_run(path):
template = str(COOKIECUTTER_TEMPLATES_DIR / "your_first_run")
project_path = cookiecutter(template, output_dir=path)
download_datasets.download("maps", project_path)

click.echo(setup_first_run(path))

# Download project
@interface.command(help="Download a project.")
@click.argument("name")
Expand All @@ -73,6 +78,8 @@ def download_dataset(name, path):
help=("C++ support is faster and preferred, use Python fallback "
"only when CUDA is not installed natively.")
)


def install_nvidia_apex(cpp):
# TODO: Installing with C++ support is a pain due to CUDA installations,
# waiting for https://github.com/pytorch/pytorch/issues/40497#issuecomment-908685435
Expand Down
5 changes: 4 additions & 1 deletion ganslate/utils/cli/scripts/download_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def download(name, path):
print(f"Fetching {name} datasets from {url}:")
wget.download(url, out=path_to_zip_file)

if Path(f"{path}/{name}").is_dir():
shutil.rmtree(Path(f"{path}/{name}"))

print(f"Extracting zip file to {path}")
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
zip_ref.extractall(path)
Expand Down Expand Up @@ -70,4 +73,4 @@ def download(name, path):

args = parser.parse_args()

download_datasets(args.name, args.path)
download(args.name, args.path)
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ nav:
- Configuration: package_overview/7_configuration.md

- Basic Tutorials:
- First Run: tutorials_basic/1_first_run_with_aerial2maps.md
- First Run: tutorials_basic/1_first_run.md
- Your New Project: tutorials_basic/2_new_project.md

- Advanced Tutorials:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ganslate
version = 0.1.0
version = 0.1.1
author = "ganslate team"
# author-email =
url = https://github.com/Maastro-CDS-Imaging-Group/ganslate
Expand Down
Empty file added tests/__init__,py
Empty file.
60 changes: 0 additions & 60 deletions tests/dataset_check.py

This file was deleted.

Binary file removed tests/ssim/ssim_a.png
Binary file not shown.
Binary file removed tests/ssim/ssim_b.png
Binary file not shown.
Binary file removed tests/ssim/ssim_grad_a.png
Binary file not shown.
Binary file removed tests/ssim/ssim_grad_b.png
Binary file not shown.
100 changes: 0 additions & 100 deletions tests/ssim/ssim_test.py

This file was deleted.

28 changes: 28 additions & 0 deletions tests/test_first_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path

from ganslate.utils.cli.interface import setup_first_run
from ganslate.engines.utils import init_engine

# test_with_pytest.py
def test_first_run():
"""[summary]
Generate setup for first run and check if the directory and files are
created.
"""
setup_first_run(".", True, extra_context={"number_of_iterations": 2,
"project_name": "first_run_test",
"logging_frequency": 1,
"enable_cuda": False
})

generated_project_dir = Path("first_run_test")
assert generated_project_dir.is_dir()
assert (generated_project_dir / "facades" / "train" / "A" ).is_dir()
assert (generated_project_dir / "facades" / "train" / "B" ).is_dir()


def test_training():
"""[summary]
Run 10 iterations of dummy training and see if it works.
"""
assert init_engine('train', ["config=first_run_test/default.yaml"]).run()
51 changes: 0 additions & 51 deletions tests/test_metrics.py

This file was deleted.

0 comments on commit 052732e

Please sign in to comment.