Giter Site home page Giter Site logo

Comments (4)

leftthomas avatar leftthomas commented on July 17, 2024

@CaptainEven change the in channel of the network to 1, and other misc

from srgan.

CaptainEven avatar CaptainEven commented on July 17, 2024

Hi, i changed input channels from 3 to 1 in Generator and Discriminator but an error occured like this: File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\container.py", line 67, in forward
input = module(input)
File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 325, in call
result = self.forward(*input, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\conv.py", line 277, in forward
self.padding, self.dilation, self.groups)
File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py", line 90, in conv2d
return f(input, weight, bias)
RuntimeError: Given groups=1, weight[64, 3, 3, 3], so expected input[8, 1, 88, 88] to have 3 channels, but got 1 channels instead
got any idea or suggestion?

from srgan.

leftthomas avatar leftthomas commented on July 17, 2024

@CaptainEven Because you only change that, you should also change other misc, not just only there, you should change the image preprocessing code, visualization code, some save image code and PSNR computation code, etc.

from srgan.

apyrros avatar apyrros commented on July 17, 2024

In data_utils.py simply add .convert('RGB') to convert a grayscale image to RGB and add three channels. It is a built-in function in PIL.

class TrainDatasetFromFolder(Dataset):
def init(self, dataset_dir, crop_size, upscale_factor):
super(TrainDatasetFromFolder, self).init()
self.image_filenames = [join(dataset_dir, x) for x in listdir(dataset_dir) if is_image_file(x)]
crop_size = calculate_valid_crop_size(crop_size, upscale_factor)
self.hr_transform = train_hr_transform(crop_size)
self.lr_transform = train_lr_transform(crop_size, upscale_factor)

def __getitem__(self, index):
    hr_image = self.hr_transform(Image.open(self.image_filenames[index]).convert('RGB'))
    lr_image = self.lr_transform(hr_image)
    return lr_image, hr_image

def __len__(self):
    return len(self.image_filenames)

class ValDatasetFromFolder(Dataset):
def init(self, dataset_dir, upscale_factor):
super(ValDatasetFromFolder, self).init()
self.upscale_factor = upscale_factor
self.image_filenames = [join(dataset_dir, x) for x in listdir(dataset_dir) if is_image_file(x)]

def __getitem__(self, index):
    hr_image = Image.open(self.image_filenames[index]).convert('RGB')
    w, h = hr_image.size
    crop_size = calculate_valid_crop_size(min(w, h), self.upscale_factor)
    lr_scale = Resize(crop_size // self.upscale_factor, interpolation=Image.BICUBIC)
    hr_scale = Resize(crop_size, interpolation=Image.BICUBIC)
    hr_image = CenterCrop(crop_size)(hr_image)
    lr_image = lr_scale(hr_image)
    hr_restore_img = hr_scale(lr_image)
    return ToTensor()(lr_image), ToTensor()(hr_restore_img), ToTensor()(hr_image)

from srgan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.