图像&视频编辑工具箱MMEditing使用示例:图像生成(generation)

      MMEditing的介绍及安装参考:https://blog.csdn.net/fengbingchun/article/details/126331541,这里给出图像生成的测试代码,论文:《Image-to-Image Translation with Conditional Adversarial Networks》:

      (1).下载模型(checkpoint):

def download_checkpoint(path, name, url):
	if os.path.isfile(path+name) == False:
		print("checkpoint(model) file does not exist, now download ...")
		subprocess.run(["wget", "-P", path, url])

path = "../../data/model/"
checkpoint = "pix2pix_vanilla_unet_bn_1x1_80k_facades_20200524-6206de67.pth"
url = "https://download.openmmlab.com/mmediting/synthesizers/pix2pix/pix2pix_facades/pix2pix_vanilla_unet_bn_1x1_80k_facades_20200524-6206de67.pth"
download_checkpoint(path, checkpoint, url)

      (2).根据配置文件和checkpoint文件构建模型:

config = "../../src/mmediting/configs/synthesizers/pix2pix/pix2pix_vanilla_unet_bn_1x1_80k_facades.py"
model = init_model(config, path+checkpoint, device)

      (3).准备测试图像:源图来自于网络,这里进行了拼接,两幅图宽、高一致,左图为鞋子的源图,右图为草图

image_path = "../../data/image/"
image_name = "11.png"

     

      (4).进行推理产生新图:

result = generation_inference(model, image)
print(f"result shape: {result.shape}; max value: {np.max(result)}") # result shape: (256, 768, 3); max value: 255

      (5).显示执行结果及保存图像:

cv2.imwrite("../../data/result_generation_pix2pix.jpg", result)
cv2.imshow("show", result)
cv2.waitKey(0)

      结果如下图所示:

      GitHubhttps://github.com/fengbingchun/PyTorch_Test 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值