RCF-pytorch
RCF-pytorch copied to clipboard
怎么单独去做测试?有单独的test.py文件吗
怎么单独去做测试一些照片?
您好,这个问题您解决了吗?怎么单独去测试一些图片?
我自己写了个单独测试的代码
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)