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

Updated test.py filename saving scheme to 'Filename_Modelused_Iteration' #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import numpy as np
import torch
import architecture as arch
from pathlib import Path

model_path = sys.argv[1] # models/RRDB_ESRGAN_x4.pth OR models/RRDB_PSNR_x4.pth
device = torch.device('cuda') # if you want to run on CPU, change 'cuda' -> cpu
device = torch.device('cpu') # if you want to run on CPU, change 'cuda' -> cpu
# device = torch.device('cpu')

test_img_folder = 'LR/*'
Expand All @@ -19,9 +20,12 @@
for k, v in model.named_parameters():
v.requires_grad = False
model = model.to(device)
model_used = Path('{:s}'.format(model_path)).stem # get model name to simple string for filename use

print('Model path {:s}. \nTesting...'.format(model_path))


amend = 2 #File already exists, lets amend a 2 to the end of the file name
idx = 0
for path in glob.glob(test_img_folder):
idx += 1
Expand All @@ -37,4 +41,13 @@
output = model(img_LR).data.squeeze().float().cpu().clamp_(0, 1).numpy()
output = np.transpose(output[[2, 1, 0], :, :], (1, 2, 0))
output = (output * 255.0).round()
cv2.imwrite('results/{:s}_rlt.png'.format(base), output)

while os.path.exists('results/{:s}_%s_%s.png'.format(base) % (model_used, amend)):
amend += 1

if os.path.exists('results/{:s}_%s.png'.format(base) % model_used):
cv2.imwrite('results/{:s}_%s_%s.png'.format(base) % (model_used, amend), output)

else:
cv2.imwrite('results/{:s}_%s.png'.format(base) % model_used, output)