Skip to content

Instantly share code, notes, and snippets.

@woctezuma
Last active January 17, 2022 14:26
Show Gist options
  • Save woctezuma/20e4dd3d49da09bf339d909f29c5527e to your computer and use it in GitHub Desktop.
Save woctezuma/20e4dd3d49da09bf339d909f29c5527e to your computer and use it in GitHub Desktop.
Google Colab: PSFRGAN

Reference: https://github.com/chaofengc/PSFR-GAN

Prepare code:

%cd /content
!git clone https://github.com/chaofengc/PSFR-GAN.git

%mkdir -p /content/PSFR-GAN/pretrain_models
%cd /content/PSFR-GAN/pretrain_models
!gdown --id 1UhzMSORSul88iVfSYQYuEal83lEoNN7l
!gdown --id 1UiHeUHVNKiEq_s5dcBv6jez6TqrAduMg
!gdown --id 1UcTeI_-YmQeNypHW98VRuIF13xEPmPWm
!gdown --id 1Unn2eznkclqUhK_o50YUyaV7eoTE4Su3
!gdown --id 1P6jZRPKPq6g2DsVJevszbM1vL5HDO1fR

Prepare data:

%cd /content/PSFR-GAN

url = 'https://i.imgur.com/7gPVDg4.png'
!wget {url}

from pathlib import Path
test_img_path = Path(url).name

Run:

%cd /content/PSFR-GAN
!python test_enhance_single_unalign.py \
 --test_img_path {test_img_path} \
 --results_dir results \
 --gpus 1

Export:

!tar czvf PSFRGAN.tar.gz /content/PSFR-GAN/results
@woctezuma
Copy link
Author

This is an answer to: chaofengc/PSFRGAN#4

@ivaxsirc
Copy link

This is for a URL defined if you want your own local files?

Thanks

@woctezuma
Copy link
Author

For local files, replace the part about the url with:

%cd /content/PSFR-GAN

test_img_path  = '7gPVDg4.png'

@ivaxsirc
Copy link

Thanks for your quick answer

I've tried with

%cd /content/PSFR-GAN

from google.colab import files
uploaded = files.upload()
from pathlib import Path
test_img_path = Path(uploaded).name

But not works,,
Says
TypeError: expected str, bytes or os.PathLike object, not dict

I want to upload any file.
What i'm wrong?

@woctezuma
Copy link
Author

woctezuma commented Jan 13, 2022

After you have uploaded the file, then you just have to set the variable like this:

test_img_path  = '7gPVDg4.png'

Do not use pathlib for this. The variable has to be a string, which is the file path to your image.
The reason why I used pathlib was to extract the filename from the URL, that is all. If there is no URL, then no need for pathlib.

@ivaxsirc
Copy link

I put this

%cd /content/PSFR-GAN
from google.colab import files
uploaded = files.upload()
test_img_path = 'X&A family2.png'

After

%cd /content/PSFR-GAN
!python test_enhance_single_unalign.py
--test_img_path {test_img_path}
--results_dir results
--gpus 1

And gave me this error

/content/PSFR-GAN
/bin/bash: A: command not found
----------------- Options ---------------
D_num: 3
Dinput_nc: 3
Dnorm: in
Gin_size: 512 [default: 512]
Gnorm: spade
Gout_size: 512 [default: 512]
Pimg_size: 512 [default: 512]
Pnorm: bn
aspect_ratio: 1.0
batch_size: 16
checkpoints_dir: ./check_points
crop_size: 256
data_device: cuda:0 [default: None]
dataroot: None
dataset_name: single
debug: False
device: cuda:0 [default: None]
epoch: latest
eval: False
gpu_ids: [0] [default: None]
gpus: 1
init_gain: 0.02
init_type: normal
input_nc: 3
isTrain: False [default: None]
load_iter: 0 [default: 0]
load_size: 256
max_dataset_size: inf
model: enhance
n_layers_D: 4
name: experiment_name
ndf: 64
ngf: 64
no_flip: False
ntest: inf
num_test: 50
num_threads: 8
output_nc: 3
parse_net_weight: ./pretrain_models/parse_multi_iter_90000.pth
phase: test
preprocess: none
psfr_net_weight: ./pretrain_models/psfrgan_epoch15_net_G.pth
results_dir: ./results/
save_masks_dir: ../datasets/FFHQ/masks512
seed: 123
serial_batches: False
src_dir:
suffix:
test_img_path: X [default: ]
test_upscale: 1
verbose: False
----------------- End -------------------
======> Loading images, crop and align faces.
Traceback (most recent call last):
File "test_enhance_single_unalign.py", line 101, in
img = dlib.load_rgb_image(img_path)
RuntimeError: Unable to open file: X

@woctezuma
Copy link
Author

woctezuma commented Jan 13, 2022

I think the problem are the spaces and the "&" in the filename.

@ivaxsirc
Copy link

Yes, it works now are the spaces, thks

I have a question, maybe you can help me

I have some images of a face with very poor quality, I have tried it and it comes out horrible,

I have many images of that person's face in very good quality.
My question is the following, is there a way to train the program so that on the good quality images of the face, then it knows how to interpret them with the poor quality one?

Considering that it is the same face.

I do not know if I explained well.
Thks

@woctezuma
Copy link
Author

woctezuma commented Jan 14, 2022

I have not done it, so I can only give a few hints here:

Ideally, you would want to fine-tune the pre-trained model with your data. I guess you need to use --continue_train.

@ivaxsirc
Copy link

ivaxsirc commented Jan 17, 2022 via email

@woctezuma
Copy link
Author

woctezuma commented Jan 17, 2022

Thank you, this is interesting. Chaofeng pointed to relevant repositories for your objective:

  • csxmli2016/GFRNet at ECCV 2018: this looks like your problem of interest,
  • csxmli2016/ASFFNet at CVPR 2020: this repository does not have public code, and it does not look like it will ever have.

Maybe you can find other recent papers or open-source repositories which would cite these papers.
From there, maybe you would be able to find software implementations in the programming languages which you are more accustomed with.

Sadly, I cannot help you with these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment