Comments (2)
Hi, you may refer to our quick start in colab or following codes.
import argparse
import cv2
import glob
import numpy as np
import os
import torch
from basicsr.archs.CAMixerSR_arch import CAMixerSR
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--model_path',
type=str,
default= # noqa: E251
'pretrained_models/LightSR/CAMixerSRx4_DF.pth' # noqa: E501
)
parser.add_argument('--input', type=str, default='datasets/Set14/LRbicx4', help='input test image folder')
parser.add_argument('--output', type=str, default='results/CAMixerSR', help='output folder')
args = parser.parse_args()
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# set up model
model = CAMixerSR(scale=4)
model.load_state_dict(torch.load(args.model_path)['params_ema'], strict=True)
model.eval()
model = model.to(device)
os.makedirs(args.output, exist_ok=True)
for idx, path in enumerate(sorted(glob.glob(os.path.join(args.input, '*')))):
imgname = os.path.splitext(os.path.basename(path))[0]
print('Testing', idx, imgname)
# read image
img = cv2.imread(path, cv2.IMREAD_COLOR).astype(np.float32) / 255.
img = torch.from_numpy(np.transpose(img[:, :, [2, 1, 0]], (2, 0, 1))).float()
img = img.unsqueeze(0).to(device)
# inference
try:
with torch.no_grad():
output = model(img)
except Exception as error:
print('Error', error, imgname)
else:
# save image
output = output.data.squeeze().float().cpu().clamp_(0, 1).numpy()
output = np.transpose(output[[2, 1, 0], :, :], (1, 2, 0))
output = (output * 255.0).round().astype(np.uint8)
cv2.imwrite(os.path.join(args.output, f'{imgname}_CAMixerSR.png'), output)
if __name__ == '__main__':
main()
from camixersr.
Hi, you may refer to our quick start in colab or following codes.
import argparse import cv2 import glob import numpy as np import os import torch from basicsr.archs.CAMixerSR_arch import CAMixerSR def main(): parser = argparse.ArgumentParser() parser.add_argument( '--model_path', type=str, default= # noqa: E251 'pretrained_models/LightSR/CAMixerSRx4_DF.pth' # noqa: E501 ) parser.add_argument('--input', type=str, default='datasets/Set14/LRbicx4', help='input test image folder') parser.add_argument('--output', type=str, default='results/CAMixerSR', help='output folder') args = parser.parse_args() device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # set up model model = CAMixerSR(scale=4) model.load_state_dict(torch.load(args.model_path)['params_ema'], strict=True) model.eval() model = model.to(device) os.makedirs(args.output, exist_ok=True) for idx, path in enumerate(sorted(glob.glob(os.path.join(args.input, '*')))): imgname = os.path.splitext(os.path.basename(path))[0] print('Testing', idx, imgname) # read image img = cv2.imread(path, cv2.IMREAD_COLOR).astype(np.float32) / 255. img = torch.from_numpy(np.transpose(img[:, :, [2, 1, 0]], (2, 0, 1))).float() img = img.unsqueeze(0).to(device) # inference try: with torch.no_grad(): output = model(img) except Exception as error: print('Error', error, imgname) else: # save image output = output.data.squeeze().float().cpu().clamp_(0, 1).numpy() output = np.transpose(output[[2, 1, 0], :, :], (1, 2, 0)) output = (output * 255.0).round().astype(np.uint8) cv2.imwrite(os.path.join(args.output, f'{imgname}_CAMixerSR.png'), output) if __name__ == '__main__': main()
Thanks for your reply.
It works for me.
Thanks a lot!
from camixersr.
Related Issues (20)
- the result of net is something wrong HOT 15
- Flops HOT 1
- 核心work的模块是啥 HOT 13
- AssertionError:bird_HR_x4.png is not in lq_paths HOT 2
- AssertionError: 41033_HR_x4.png is not in lq_paths. HOT 1
- 请问作者有尝试过在这个算法中用GAN吗 HOT 3
- Mask Visualization HOT 1
- The mask of CAMixer, Visualization. HOT 6
- How the offsets work? HOT 4
- 关于在训练时使用gumble softmax的细节 HOT 2
- Cant find the file HOT 1
- 找不到basicsr.utils HOT 2
- File missing
- difference of these pretrained models HOT 2
- Concerning the addition of three conditions in the article, I have some doubts and don't understand them. HOT 3
- How to test with my own local imgs? HOT 5
- How do I go through the training process? HOT 1
- How can I use pretrained models? HOT 4
- train_example.yml中的meta_info_file是什么? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from camixersr.