|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import torch |
|
|
|
|
|
|
|
|
from basicsr.models import create_model |
|
|
from basicsr.train import parse_options |
|
|
from basicsr.utils import FileClient, imfrombytes, img2tensor, padding, tensor2img, imwrite |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
|
opt = parse_options(is_train=False) |
|
|
opt['num_gpu'] = torch.cuda.device_count() |
|
|
|
|
|
img_path = opt['img_path'].get('input_img') |
|
|
output_path = opt['img_path'].get('output_img') |
|
|
|
|
|
|
|
|
|
|
|
file_client = FileClient('disk') |
|
|
|
|
|
img_bytes = file_client.get(img_path, None) |
|
|
try: |
|
|
img = imfrombytes(img_bytes, float32=True) |
|
|
except: |
|
|
raise Exception("path {} not working".format(img_path)) |
|
|
|
|
|
img = img2tensor(img, bgr2rgb=True, float32=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opt['dist'] = False |
|
|
model = create_model(opt) |
|
|
|
|
|
model.feed_data(data={'lq': img.unsqueeze(dim=0)}) |
|
|
|
|
|
if model.opt['val'].get('grids', False): |
|
|
model.grids() |
|
|
|
|
|
model.test() |
|
|
|
|
|
if model.opt['val'].get('grids', False): |
|
|
model.grids_inverse() |
|
|
|
|
|
visuals = model.get_current_visuals() |
|
|
sr_img = tensor2img([visuals['result']]) |
|
|
imwrite(sr_img, output_path) |
|
|
|
|
|
print(f'inference {img_path} .. finished. saved to {output_path}') |
|
|
|
|
|
if __name__ == '__main__': |
|
|
main() |
|
|
|
|
|
|