RCF-pytorch icon indicating copy to clipboard operation
RCF-pytorch copied to clipboard

怎么单独去做测试?有单独的test.py文件吗

Open long123524 opened this issue 2 years ago • 2 comments

怎么单独去做测试一些照片?

long123524 avatar Mar 02 '22 01:03 long123524

您好,这个问题您解决了吗?怎么单独去测试一些图片?

zhangxiao121 avatar Jul 01 '22 07:07 zhangxiao121

我自己写了个单独测试的代码

import models if name == 'main': resume = 'RCFcheckpoint_epoch12.pth' model = models.RCF() model.eval() checkpoint = torch.load(resume,map_location='cpu') try: model.load_state_dict(checkpoint) except Exception: model.load_state_dict(checkpoint['state_dict'],False) img_path = r'D:\Work\line_extraction\RCF-pytorch-master\BSR\BSDS500\data\images\train\12003.jpg' result_path = './examples/demo.png'

original_img = np.array(cv2.imread(img_path), dtype=np.float32)
h, w, _ = original_img.shape

img = prepare_image_cv2(original_img)
img = torch.from_numpy(img).unsqueeze(0)

outs = model(img)
result = outs[-1].squeeze().detach().cpu().numpy()

result = (result * 255).astype(np.uint8)
Image.fromarray(result).save(result_path)

hahaha1230 avatar Nov 10 '22 14:11 hahaha1230