You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/__init__.py
+12-11Lines changed: 12 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,12 @@
1
1
"""This package includes all the modules related to data loading and preprocessing
2
2
3
-
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.
3
+
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.
4
4
You need to implement four functions:
5
-
-- <__init__> (initialize the class, first call BaseDataset.__init__(self, opt))
6
-
-- <__len__> (return the size of dataset)
7
-
-- <__getitem__> (get a data point)
8
-
-- (optionally) <modify_commandline_options> (add dataset-specific options and set default options).
5
+
-- <__init__>: initialize the class, first call BaseDataset.__init__(self, opt).
6
+
-- <__len__>: return the size of dataset.
7
+
-- <__getitem__>: get a data point from data loader.
8
+
-- <modify_commandline_options>: (optionally) add dataset-specific options and set default options.
9
+
9
10
Now you can use the dataset class by specifying flag '--dataset_mode dummy'.
10
11
See our template dataset class 'template_dataset.py' for more details.
11
12
"""
@@ -15,7 +16,7 @@
15
16
16
17
17
18
deffind_dataset_using_name(dataset_name):
18
-
"""Import the module "data/[datasetname]_dataset.py" given the option '--dataset_mode [datasetname].
19
+
"""Import the module "data/[dataset_name]_dataset.py".
19
20
20
21
In the file, the class called DatasetNameDataset() will
21
22
be instantiated. It has to be a subclass of BaseDataset,
Copy file name to clipboardExpand all lines: docs/overview.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,10 +24,10 @@ To help users better understand and use our codebase, we briefly overview the fu
24
24
*[base_model.py](../models/base_model.py) implements an abstract base class ([ABC](https://docs.python.org/3/library/abc.html)) for models. It also includes commonly used helper functions (e.g., `setup`, `test`, `update_learning_rate`, `save_networks`, `load_networks`), which can be later used in subclasses.
25
25
*[template_model.py](../models/template_model.py) provides a model template with detailed documentation. Check out this file if you plan to implement your own model.
26
26
*[pix2pix_model.py](../models/pix2pix_model.py) implements the pix2pix [model](https://phillipi.github.io/pix2pix/), for learning a mapping from input images to output images given paired data. The model training requires `--dataset_mode aligned` dataset. By default, it uses a `--netG unet256`[U-Net](https://arxiv.org/pdf/1505.04597.pdf) generator, a `--netD basic` discriminator (PatchGAN), and a `--gan_mode vanilla` GAN loss (standard cross-entropy objective).
27
-
*[colorization_model.py](../models/colorization_model.py) implements a subclass of `Pix2PixModel` for image colorization (black & white image to colorful image). The model training requires `-dataset_model colorization` dataset. It trains a pix2pix model, mapping from L channel to ab channel in [Lab](https://en.wikipedia.org/wiki/CIELAB_color_space) color space. By default, the model will automatically set `--input_nc 1` and `--output_nc 2`.
28
-
*[cycle_gan_model.py](../models/cycle_gan_model.py) implements the CycleGAN [model](https://junyanz.github.io/CycleGAN/), for learning image-to-image translation without paired data. The model training requires `--dataset_mode unaligned` dataset. By default, it uses a `--netG resnet_9blocks` ResNet generator, a `--netD basic`discrimiator (PatchGAN introduced by pix2pix), and a least-square GANs [objective](https://arxiv.org/abs/1611.04076) (`--gan_mode lsgan`).
27
+
*[colorization_model.py](../models/colorization_model.py) implements a subclass of `Pix2PixModel` for image colorization (black & white image to colorful image). The model training requires `-dataset_model colorization` dataset. It trains a pix2pix model, mapping from L channel to ab channels in [Lab](https://en.wikipedia.org/wiki/CIELAB_color_space) color space. By default, the `colorization` dataset will automatically set `--input_nc 1` and `--output_nc 2`.
28
+
*[cycle_gan_model.py](../models/cycle_gan_model.py) implements the CycleGAN [model](https://junyanz.github.io/CycleGAN/), for learning image-to-image translation without paired data. The model training requires `--dataset_mode unaligned` dataset. By default, it uses a `--netG resnet_9blocks` ResNet generator, a `--netD basic`discriminator (PatchGAN introduced by pix2pix), and a least-square GANs [objective](https://arxiv.org/abs/1611.04076) (`--gan_mode lsgan`).
29
29
*[networks.py](../models/networks.py) module implements network architectures (both generators and discriminators), as well as normalization layers, initialization methods, optimization scheduler (i.e., learning rate policy), and GAN objective function (`vanilla`, `lsgan`, `wgangp`).
30
-
*[test_model.py](../models/test_model.py) implements a model that can be used to generate CycleGAN results for only one direction. This option will automatically set `--dataset_mode single`, which only loads the images from one set. See the test [instruction](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix#apply-a-pre-trained-model-cyclegan) for more details.
30
+
*[test_model.py](../models/test_model.py) implements a model that can be used to generate CycleGAN results for only one direction. This model will automatically set `--dataset_mode single`, which only loads the images from one set. See the test [instruction](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix#apply-a-pre-trained-model-cyclegan) for more details.
31
31
32
32
[options](../options) directory includes our option modules: training options, test options, and basic options (used in both training and test). `TrainOptions` and `TestOptions` are both subclasses of `BaseOptions`. They will reuse the options defined in `BaseOptions`.
33
33
*[\_\_init\_\_.py](../options/__init__.py) is required to make Python treat the directory `options` as containing packages,
Copy file name to clipboardExpand all lines: models/__init__.py
+36-7Lines changed: 36 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,36 @@
1
+
"""This package contains modules related to objective functions, optimizations, and network architectures.
2
+
3
+
To add a custom model class called 'dummy', you need to add a file called 'dummy_model.py' and define a subclass DummyModel inherited from BaseModel.
4
+
You need to implement the following five functions:
5
+
-- <__init__>: initialize the class; first call BaseModel.__init__(self, opt).
6
+
-- <set_input>: unpack data from dataset and apply preprocessing.
7
+
-- <forward>: produce intermediate results.
8
+
-- <optimize_parameters>: calculate loss, gradients, and update network weights.
9
+
-- <modify_commandline_options>: (optionally) add model-specific options and set default options.
10
+
11
+
In the function <__init__>, you need to define four lists:
12
+
-- self.loss_names (str list): specify the training losses that you want to plot and save.
13
+
-- self.model_names (str list): specify the images that you want to display and save.
14
+
-- self.visual_names (str list): define networks used in our training.
15
+
-- self.optimizers (optimzier list): define and initialize optimizers. You can define one optimizer for each network. If two networks are updated at the same time, you can use itertools.chain to group them. See cycle_gan_model.py for an example.
16
+
17
+
Now you can use the model class by specifying flag '--model dummy'.
18
+
See our template model class 'template_model.py' for an example.
19
+
"""
20
+
1
21
importimportlib
2
22
frommodels.base_modelimportBaseModel
3
23
4
24
5
25
deffind_model_using_name(model_name):
6
-
# Given the option --model [modelname],
7
-
# the file "models/modelname_model.py"
8
-
# will be imported.
26
+
"""Import the module "models/[model_name]_model.py".
27
+
28
+
In the file, the class called DatasetNameModel() will
29
+
be instantiated. It has to be a subclass of BaseModel,
30
+
and it is case-insensitive.
31
+
"""
9
32
model_filename="models."+model_name+"_model"
10
33
modellib=importlib.import_module(model_filename)
11
-
12
-
# In the file, the class called ModelNameModel() will
13
-
# be instantiated. It has to be a subclass of BaseModel,
0 commit comments