日期:2024.5.13-5.19
本周进展
1. 部署图像优化模型ESRGAN
上周调研了ESRGAN和RCAN两个模型,本周选择其中之一ESRGAN进行部署。关键代码如下:
model_path = 'models/RRDB_ESRGAN_x4.pth'
model = arch.RRDBNet(3, 3, 64, 23, gc=32)
model.load_state_dict(torch.load(model_path), strict=True)
model.eval()
model = model.to(device)
img = cv2.imread(path, cv2.IMREAD_COLOR)
img = img * 1.0 / 255
img = torch.from_numpy(np.transpose(img[:, :, [2, 1, 0]], (2, 0, 1))).float()
img_LR = img.unsqueeze(0)
img_LR = img_LR.to(device)
with torch.no_grad():
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('result.png', output)
选择一张图片进行尝试,效果如下:
原图:
结果图:
可以看到,效果非常明显。
编写相关脚本并给flask提供接口,由组内其他成员完成前端功能设计。
下周计划
完善优化项目,查找小bug。