Skip to content

Commit 92d4afb

Browse files
committed
remove name functions & update overview
1 parent 2df0919 commit 92d4afb

16 files changed

+45
-86
lines changed

data/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def create_dataset(opt):
3636
"""Create dataset given the option."""
3737
dataset = find_dataset_using_name(opt.dataset_mode)
3838
instance = dataset(opt)
39-
print("dataset [%s] was created" % (instance.name()))
39+
print("dataset [%s] was created" % type(instance).__name__)
4040
return instance
4141

4242

data/aligned_dataset.py

-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,3 @@ def __getitem__(self, index):
4343

4444
def __len__(self):
4545
return len(self.AB_paths)
46-
47-
def name(self):
48-
return 'AlignedDataset'

data/base_dataset.py

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ def __init__(self, opt):
1313
def modify_commandline_options(parser, is_train):
1414
return parser
1515

16-
@abstractmethod
17-
def name(self):
18-
return 'BaseDataset'
19-
2016
@abstractmethod
2117
def __len__(self):
2218
return 0

data/colorization_dataset.py

-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,3 @@ def __getitem__(self, index):
3333

3434
def __len__(self):
3535
return len(self.A_paths)
36-
37-
def name(self):
38-
return 'ColorizationDataset'

data/single_dataset.py

-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,3 @@ def __getitem__(self, index):
2222

2323
def __len__(self):
2424
return len(self.A_paths)
25-
26-
def name(self):
27-
return 'SingleImageDataset'

data/template_dataset.py

-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<__init__>: Initialize this dataset class.
1111
<__getitem__>: Return a data point and its metadata information.
1212
<__len__>: Return the number of images.
13-
<name>: Return the name of this dataset.
1413
"""
1514
from data.base_dataset import BaseDataset, get_transform
1615
# from data.image_folder import make_dataset
@@ -73,7 +72,3 @@ def __getitem__(self, index):
7372
def __len__(self):
7473
"""Return the total number of images."""
7574
return len(self.image_paths)
76-
77-
def name(self):
78-
"""Return the name of this dataset."""
79-
return 'TemplateDataset'

data/unaligned_dataset.py

-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,3 @@ def __getitem__(self, index):
4444

4545
def __len__(self):
4646
return max(self.A_size, self.B_size)
47-
48-
def name(self):
49-
return 'UnalignedDataset'

docs/overview.md

+42-41
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
## Overview of Code Structure
2-
[train.py](./train.py) is a general-purpose training script. It works for various models (with model option `--model`: e.g., `pix2pix`, `cyclegan`, `colorization`) and different datasets (with dataset option `--dataset_mode`: e.g., `aligned`, `unaligned`, `single`, `colorization`). See the main [README](../README.md) and Training/test [tips](tips.md) for more details.
3-
4-
[test.py](./test.py) is a general-purpose test script. Once you have trained your models with `train.py`, you can use this script to test the model. It will load a saved model from `--checkpoints_dir` and save the results to `--results_dir`. See the main [README](../README.md) and Training/test [tips](tips.md) for more details.
5-
6-
7-
[data](./data) directory contains all the modules related to datasets.
8-
* [\_\_init\_\_.py](./data/__init__.py) implements the interface between this package and training/test script. You should call `from data import CreateDataLoader` and `data_loader = CreateDataLoader(opt)` to create a dataloader given an option `opt`.
9-
* [base_dataset.py](./data/base_dataset.py) implements an abstract base dataset class. It also includes common transformation functions `get_transform` and `get_simple_transform` which can be used in dataset classes. To add a custom dataset class called `dummy`, you need to add a file called `dummy_dataset.py` and define a subclass `DummyDataset` inherited from `BaseDataset`. You need to implement functions: `name`, `__len__`, `__getitem__`, and `modify_commandline_options`. You can use this dataset using `--dataset_mode dummy`.
10-
* [image_folder.py](./data/image_folder.py) implements a modified Image folder class. We
11-
modify the original PyTorch code so that it also loads images from the current directory as well as the subdirectories.
12-
* [template_dataset.py](./data/template_dataset.py) provides a class template with detailed documentation. Check out this file if you plan to implement your own dataset class.
13-
* [aligned_dataset.py](./data/aligned_dataset.py) includes a dataset class that can load aligned image pairs.
14-
* [unaligned_dataset.py](./data/unaligned_dataset.py) includes a dataset class that can load unaligned/unpaired datasets.
15-
* [single_dataset.py](./data/single_dataset.py) includes a dataset class that can load a collection of single images. It is used in `test.py` when only model in one direction is being tested.
16-
* [colorization_dataset.py](./data/colorization_dataset.py) implements a dataset class that can load a collection of RGB images and convert it into (L, ab) pairs. It is used with pix2pix-based colorization model.
17-
18-
19-
[models](./models) directory contains all the modules related to core core formulations and network.
20-
* [\_\_init\_\_.py](./models/__init__.py)
21-
* [base_model.py](./models/base_model.py)
22-
* [template_model.py](./models/template_model.py)
23-
* [pix2pix_model.py](./models/pix2pix_model.py)
24-
* [colorization_model.py](./models/colorization_model.py)
25-
* [cycle_gan_model.py](./models/cycle_gan_model.py)
26-
* [networks.py](./models/networks.py) module implements network architectures (both generators and discriminators), as well as normalization layers, initialization, optimization scheduler (learning rate policy), and GAN loss function.
27-
* [test_model.py](./models/test_model.py)
28-
29-
[options](./options) directory includes option modules: training options, test options and basic options (used in both training and test).
30-
* [\_\_init\_\_.py](./options/__init__.py) an empty file to make the `options` directory a package.
31-
* [base_options.py](./options/base_options.py) includes options that are used in both training and test. It also implements a few helper functions such as parsing, printing, and saving the options. It also gathers additional options defined in `modify_commandline_options` functions in both dataset class and model class.
32-
* [train_options.py](./options/train_options.py) includes options that are only used in training time.
33-
* [test_options.py](./options/test_options.py) includes options that are only used in test time.
34-
35-
36-
[util](./util) directory includes a misc collection of useful utility functions.
37-
* [\_\_init\_\_.py](./util/__init__.py): an empty file to make the `util` directory a package.
38-
* [get_data.py](./util/get_data.py)
39-
* [html.py](./util/html.py)
40-
* [image_pool.py](./util/image_pool.py)
41-
* [util.py](./util/util.py)
42-
* [visualizer.py](./util/visualizer.py)
2+
We give a brief overview of each directory and each file. Please see the documentation in each file for more details. If you have questions, you may find useful information in [training/test tips](tips.md) and [frequently asked questions](qa.md).
3+
4+
[train.py](../train.py) is a general-purpose training script. It works for various models (with option `--model`: e.g., `pix2pix`, `cyclegan`, `colorization`) and different datasets (with option `--dataset_mode`: e.g., `aligned`, `unaligned`, `single`, `colorization`). See the main [README](.../README.md) and Training/test [tips](tips.md) for more details.
5+
6+
[test.py](../test.py) is a general-purpose test script. Once you have trained your model with `train.py`, you can use this script to test the model. It will load a saved model from `--checkpoints_dir` and save the results to `--results_dir`. See the main [README](.../README.md) and Training/test [tips](tips.md) for more details.
7+
8+
9+
[data](../data) directory contains all the modules related to data loading and data preprocessing.
10+
* [\_\_init\_\_.py](../data/__init__.py) implements the interface between this package and training/test script. In the `train.py` and `test.py`, we call `from data import CreateDataLoader` and `data_loader = CreateDataLoader(opt)` to create a dataloader given the option `opt`.
11+
* [base_dataset.py](../data/base_dataset.py) implements an abstract base class for datasets. It also includes common transformation functions `get_transform` and `get_simple_transform` which can be used in subclasses. To add a custom dataset class called `dummy`, you need to add a file called `dummy_dataset.py` and define a subclass `DummyDataset` inherited from `BaseDataset`. You need to implement four functions: `name`, `__len__`, `__getitem__`, and optionally `modify_commandline_options`. You can then use this dataset class by specifying flag `--dataset_mode dummy`.
12+
* [image_folder.py](../data/image_folder.py) implements an image folder class. We modify the official PyTorch image folder [code](https://github.com/pytorch/vision/blob/master/torchvision/datasets/folder.py) so that this class can load images from both the current directory and its subdirectories.
13+
* [template_dataset.py](../data/template_dataset.py) provides a dataset class template with detailed documentation. Check out this file if you plan to implement your own dataset class.
14+
* [aligned_dataset.py](../data/aligned_dataset.py) includes a dataset class that can load aligned image pairs. It assumes a single image directory `/path/to/data/train`, which contains image pairs in the form of {A,B}. See [here](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/tips.md#prepare-your-own-datasets-for-pix2pix) on how to prepare aligned datasets. During test time, you need to prepare a directory `/path/to/data/test` for test data.
15+
* [unaligned_dataset.py](../data/unaligned_dataset.py) includes a dataset class that can load unaligned/unpaired datasets. It assumes that two directories to host training images from domain A `/path/to/data/trainA` and from domain B `/path/to/data/trainB` separately. Then you can train the model with the dataset flag `--dataroot /path/to/data`. Similarly, you need to prepare two directories `/path/to/data/testA` and `/path/to/data/testB` during test time.
16+
* [single_dataset.py](../data/single_dataset.py) includes a dataset class that can load a set of single images. It is used in `test.py` when only model in one direction is being tested. The option `--model test` is used for generating CycleGAN results only for one side. This option will automatically set `--dataset_mode single`.
17+
* [colorization_dataset.py](../data/colorization_dataset.py) implements a dataset class that can load a set of nature images in RGB, and convert RGB format into (L, ab) pairs. It is required by pix2pix-based colorization model (`--model colorization`).
18+
19+
20+
[models](../models) directory contains core modules related to objective functions, optimizations, and network architectures.
21+
* [\_\_init\_\_.py](../models/__init__.py)
22+
* [base_model.py](../models/base_model.py)
23+
* [template_model.py](../models/template_model.py)
24+
* [pix2pix_model.py](../models/pix2pix_model.py)
25+
* [colorization_model.py](../models/colorization_model.py)
26+
* [cycle_gan_model.py](../models/cycle_gan_model.py)
27+
* [networks.py](../models/networks.py) module implements network architectures (both generators and discriminators), as well as normalization layers, initialization, optimization scheduler (learning rate policy), and GAN loss function.
28+
* [test_model.py](../models/test_model.py)
29+
30+
[options](../options) directory includes our option modules: training options, test options and basic options (used in both training and test).
31+
* [\_\_init\_\_.py](../options/__init__.py) an empty file to make the `options` directory a package.
32+
* [base_options.py](../options/base_options.py) includes options that are used in both training and test. It also implements a few helper functions such as parsing, printing, and saving the options. It also gathers additional options defined in `modify_commandline_options` functions in both dataset class and model class.
33+
* [train_options.py](../options/train_options.py) includes options that are only used in training time.
34+
* [test_options.py](../options/test_options.py) includes options that are only used in test time.
35+
36+
37+
[util](../util) directory includes a misc collection of useful utility functions.
38+
* [\_\_init\_\_.py](../util/__init__.py): an empty file to make the `util` directory a package.
39+
* [get_data.py](../util/get_data.py)
40+
* [html.py](../util/html.py)
41+
* [image_pool.py](../util/image_pool.py)
42+
* [util.py](../util/util.py)
43+
* [visualizer.py](../util/visualizer.py)

models/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ def get_option_setter(model_name):
3434
def create_model(opt):
3535
model = find_model_using_name(opt.model)
3636
instance = model(opt)
37-
print("model [%s] was created" % (instance.name()))
37+
print("model [%s] was created" % type(instance).__name__)
3838
return instance

models/base_model.py

-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ def modify_commandline_options(parser, is_train):
2828
"""Modify parser to add command line options; change the default values if needed"""
2929
return parser
3030

31-
@abstractmethod
32-
def name(self):
33-
"""Return the name of this class"""
34-
pass
35-
3631
@abstractmethod
3732
def set_input(self, input):
3833
"""Unpack input data from the dataloader and perform necessary pre-processing steps."""

models/colorization_model.py

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66

77
class ColorizationModel(Pix2PixModel):
8-
def name(self):
9-
return 'ColorizationModel'
10-
118
@staticmethod
129
def modify_commandline_options(parser, is_train=True):
1310
Pix2PixModel.modify_commandline_options(parser, is_train)

models/cycle_gan_model.py

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77

88
class CycleGANModel(BaseModel):
9-
def name(self):
10-
return 'CycleGANModel'
11-
129
@staticmethod
1310
def modify_commandline_options(parser, is_train=True):
1411
parser.set_defaults(no_dropout=True) # default CycleGAN did not use dropout

models/pix2pix_model.py

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66

77
class Pix2PixModel(BaseModel):
8-
def name(self):
9-
return 'Pix2PixModel'
10-
118
@staticmethod
129
def modify_commandline_options(parser, is_train=True):
1310
# changing the default values to match the pix2pix paper (https://phillipi.github.io/pix2pix/)

models/template_model.py

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222

2323
class TemplateModel(BaseModel):
24-
def name(self):
25-
"""Return the name of this model"""
26-
return 'TemplateModel'
27-
2824
@staticmethod
2925
def modify_commandline_options(parser, is_train=True):
3026
"""Add new dataset-specific options and rewrite default values for existing options.

models/test_model.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44

55
class TestModel(BaseModel):
6-
def name(self):
7-
return 'TestModel'
8-
96
@staticmethod
107
def modify_commandline_options(parser, is_train=True):
118
assert not is_train, 'TestModel cannot be used in train mode'

options/base_options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(self, parser):
3232
parser.add_argument('--load_iter', type=int, default='0', help='which iteration to load? if load_iter > 0, the code will load models by iter_[load_iter]; otherwise, the code will load models by [epoch]')
3333
parser.add_argument('--num_threads', default=4, type=int, help='# threads for loading data')
3434
parser.add_argument('--checkpoints_dir', type=str, default='./checkpoints', help='models are saved here')
35-
parser.add_argument('--norm', type=str, default='instance', help='instance normalization or batch normalization [batch | norm | none]')
35+
parser.add_argument('--norm', type=str, default='instance', help='instance normalization or batch normalization [instance | batch | none]')
3636
parser.add_argument('--serial_batches', action='store_true', help='if true, takes images in order to make batches, otherwise takes them randomly')
3737
parser.add_argument('--no_dropout', action='store_true', help='no dropout for the generator')
3838
parser.add_argument('--max_dataset_size', type=int, default=float("inf"), help='Maximum number of samples allowed per dataset. If the dataset directory contains more than max_dataset_size, only a subset is loaded.')

0 commit comments

Comments
 (0)