forked from Lornatang/SRGAN-PyTorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrgan_config.py
101 lines (86 loc) · 3.28 KB
/
srgan_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright 2022 Dakewe Biotech Corporation. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
import random
import numpy as np
import torch
from torch.backends import cudnn
# Random seed to maintain reproducible results
random.seed(0)
torch.manual_seed(0)
np.random.seed(0)
# Use GPU for training by default
device = torch.device("cuda", 0)
# Turning on when the image size does not change during training can speed up training
cudnn.benchmark = True
# When evaluating the performance of the SR model, whether to verify only the Y channel image data
only_test_y_channel = True
# Model architecture name
d_arch_name = "discriminator"
g_arch_name = "srresnet_x4"
# Model arch config
in_channels = 3
out_channels = 3
channels = 64
num_rcb = 16
# Test upscale factor
upscale_factor = 4
# Current configuration parameter method
mode = "test"
# Experiment name, easy to save weights and log files
exp_name = "SRGAN_x4-DIV2K"
if mode == "train":
# Dataset address
train_gt_images_dir = f"./data/ImageNet/SRGAN/train"
test_gt_images_dir = f"./data/Set5/GTmod12"
test_lr_images_dir = f"./data/Set5/LRbicx{upscale_factor}"
gt_image_size = 96
batch_size = 16
num_workers = 4
# The address to load the pretrained model
pretrained_d_model_weights_path = f""
pretrained_g_model_weights_path = f"./results/SRResNet_x4-DIV2K/g_last.pth.tar"
# Incremental training and migration training
resume_d_model_weights_path = f""
resume_g_model_weights_path = f""
# Total num epochs (200,000 iters)
epochs = 18
# Loss function weight
pixel_weight = 1.0
content_weight = 1.0
adversarial_weight = 0.001
# Feature extraction layer parameter configuration
feature_model_extractor_node = "features.35"
feature_model_normalize_mean = [0.485, 0.456, 0.406]
feature_model_normalize_std = [0.229, 0.224, 0.225]
# Optimizer parameter
model_lr = 1e-4
model_betas = (0.9, 0.999)
model_eps = 1e-8
model_weight_decay = 0.0
# Dynamically adjust the learning rate policy [100,000 | 200,000]
lr_scheduler_step_size = epochs // 2
lr_scheduler_gamma = 0.1
# How many iterations to print the training result
train_print_frequency = 100
valid_print_frequency = 1
if mode == "test":
# Test data address
#lr_dir = f"./data/Set5/LRbicx{upscale_factor}"
#lr_dir = r"C:\Users\KIM\Desktop\sr_datasets\DALLE2\4x_LR"
lr_dir = f"./data/sr_datasets/DALLE2/4x_LR"
sr_dir = f"./results/test/{exp_name}"
#gt_dir = r"C:\Users\KIM\Desktop\sr_datasets\DALLE2\GT"
#gt_dir = f"./data/Set5/GTmod12"
gt_dir = f"./data/sr_datasets/DALLE2/GT"
g_model_weights_path = f"./results/pretrained_models/SRGAN_x4-ImageNet-8c4a7569.pth.tar"