Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to scale is missing? #6

Open
seadra opened this issue Mar 21, 2019 · 5 comments
Open

Script to scale is missing? #6

seadra opened this issue Mar 21, 2019 · 5 comments

Comments

@seadra
Copy link

seadra commented Mar 21, 2019

Is this repo for training only? (train.py)

It doesn't look like there is a script which would do the actual image scaling.

@yu45020
Copy link
Owner

yu45020 commented Mar 21, 2019

My codes may seem messy >.<

For the most recent model training, I use sqlite to store pre-processed images. The scaling step is defined at

lr_hr_patch = self.get_img_patches(img)

    def get_img_patches(self, img_file):
        img_pil = Image.open(img_file).convert("RGB")
        img_patch = self.random_cropper(img_pil)
        lr_hr_patches = self.img_augmenter.process(img_patch)
return lr_hr_patches

@seadra
Copy link
Author

seadra commented Mar 21, 2019

Oh, no, what I meant is, for end users and distro packagers, it would be really nice if you could provide the trained models + a waifu2x like command which accepts an input image filename and the output file name (and maybe additional options such as the model and scaling factor).

Then we could just clone your repo, and run something like

pywaifu2x -i input.png -o output.png -s 2 -m dcscn

@yu45020
Copy link
Owner

yu45020 commented Mar 21, 2019

That seems a nice idea, and it will be a good chance for me to learn something new in programming.

By the way, this repo was created as a practice to learn PyTorch, and I didn't expected to create something come close to the original waifu2x's repo.

@seadra
Copy link
Author

seadra commented Mar 22, 2019

I'll be looking forward to it!

One more added benefit is, as far as I know, there is currently no way of using these new models under Linux or macOS without an NVidia GPU.

(waifu2x-caffe does work on CPU, but it's Windows only, waifu2x-converter-cpp works on CPU but doesn't have the new models)

@yu45020
Copy link
Owner

yu45020 commented Mar 22, 2019

The new model is trained in fp16, but PyTorch doesn't support fp32 in CPU. You may still use it in CPU only for inference by changing this line in Nvidia apex at here

class tofp16(nn.Module):
    """
    Utility module that implements::
        def forward(self, input):
            return input.half()
    """

    def __init__(self):
        super(tofp16, self).__init__()

    def forward(self, input):
return input.half() 

to

def forward(self, input):
return input.float()

I once did some comparison on various out of sample test, using fp16 checkpoints to do fp32 inference makes almost no statistical difference. I will add more details in the ReamdMe page and the new checkpoints this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants