image-super-resolution
image-super-resolution copied to clipboard
while training this error raised
Traceback (most recent call last):
File "train.py", line 75, in
and here is the training code:
# -*- coding: utf-8 -*-
# Create the models
from ISR.models import RRDN
from ISR.models import Discriminator
from ISR.models import Cut_VGG19
lr_train_patch_size = 32
layers_to_extract = [5, 9]
scale = 4
hr_train_patch_size = lr_train_patch_size * scale
rrdn = RRDN(arch_params={'C':4, 'D':3, 'G':64, 'G0':64, 'T':10, 'x':scale}, patch_size=lr_train_patch_size)
f_ext = Cut_VGG19(patch_size=hr_train_patch_size, layers_to_extract=layers_to_extract)
discr = Discriminator(patch_size=hr_train_patch_size, kernel_size=3)
# Create a Trainer object using the desired settings and give it the models (f_ext and discr are optional)
from ISR.train import Trainer
loss_weights = {
'generator': 0.0,
'feature_extractor': 0.0833,
'discriminator': 0.01
}
losses = {
'generator': 'mae',
'feature_extractor': 'mse',
'discriminator': 'binary_crossentropy'
}
log_dirs = {'logs': './logs', 'weights': './weights'}
learning_rate = {'initial_value': 0.0004, 'decay_factor': 0.5, 'decay_frequency': 30}
flatness = {'min': 0.0, 'max': 0.15, 'increase': 0.01, 'increase_frequency': 5}
adam_optimizer = {'beta1': 0.9, 'beta2': 0.999, 'epsilon': None}
trainer = Trainer(
generator=rrdn,
discriminator=discr,
feature_extractor=f_ext,
lr_train_dir='low_res/training',
hr_train_dir='high_res/training',
lr_valid_dir='low_res/validation',
hr_valid_dir='high_res/validation',
loss_weights=loss_weights,
losses=losses,
learning_rate=learning_rate,
flatness=flatness,
log_dirs=log_dirs,
adam_optimizer=adam_optimizer,
metrics={'generator': 'PSNR_Y'},
dataname='celebA',
weights_generator=None,
weights_discriminator=None,
n_validation=32,
)
# start train
trainer.train(
epochs=10,
steps_per_epoch=20,
batch_size=32,
#monitored_metrics = {'val_generator_loss': 'min'}
monitored_metrics={'val_generator_PSNR_Y' : 'max'}
)
I'm not sure what happens there. The model is asking for a 4 dimensional input (a batch of images) but it's receiving an array. The code you posted seems correct. Are the HR images in RBG format? Does the error appear right away or only after some training steps?
I am training it on CelebA Dataset. I cropped all the faces from the dataset to size 128x128 and the LR images are 32x32 upscaled to 128x128 using bicubic filter. The image filenames are in numbers like xxxxxx.jpg
the error raised right from the start. I have no idea where I did wrong...=(
I am training it on CelebA Dataset. I cropped all the faces from the dataset to size 128x128 and the LR images are 32x32 upscaled to 128x128 using bicubic filter. The image filenames are in numbers like xxxxxx.jpg
the error raised right from the start. I have no idea where I did wrong...=(
I assume you meant that the LR images are DOWNscaled from 128x128 to 32x32. Basically this line
validation_feats = self.feature_extractor.model.predict(validation_set['hr'])
Is feeding your validation HR images to a VGG model, that expects 4 dimensional inputs (batches of 3 dimensional images (RGB)). For some reason a vector of 1024 points is fed, which is a flattened version of a 32x32 image. Please check the image sizes, make sure that all the LR images are 32x32 and all HR images are 128x128. I still do not understand why it has been flattened, maybe it is a side effect of incorrect image sizes. As soon as I have some time I'll try to replicate the problem.
I run this code with this bug. However, I find when the shape of images exactly in the data root dir(point to lr/hr_train/test_dir) matches param 'scale'(In your code is 4) correcrly, this bug seems do not appear. I tested with a lr of 96x128 and hr of 192x256 dataset for scale 2 and a lr of 96x128 and hr of 384x512 dataset for scale 4.