SimMIM复现

最近在尝试复现SimMIM,但是总也不成功,论文里重建和预测的图像看着都尚可

论文中重建和预测的图是:
原论文

我是用github里的参数文件simmim_pretrain__swin_large__img192_window12__800ep.pth
复现后是:
自己复现

#代码如下:(模型部分并没有改动)

def run_one_image(img, mask, model):
 		# x = torch.tensor(img)
		#
	# # make it a batch-like
	# x = x.unsqueeze(dim=0)
	# x = torch.einsum('nhwc->nchw', x)

	# run MAE
	y,loss,mask = model(img, mask)
	# y = model.unpatchify(y)
	y = torch.einsum('nchw->nhwc', y).detach().cpu()

	# visualize the mask
	# mask = mask.detach()
	# mask = mask.unsqueeze(-1).repeat(1, 1, model.patch_embed.patch_size[0] ** 2 * 3)  # (N, H*W, p*p*3)
	# mask = model.unpatchify(mask)  # 1 is removing, 0 is keeping
	mask = torch.einsum('nchw->nhwc', mask).detach().cpu()

	x = torch.einsum('nchw->nhwc', img)

	# masked image
	im_masked = x * (1 - mask)

	# MAE reconstruction pasted with visible patches
	im_paste = x * (1 - mask) + y * mask

	# make the plt figure larger
	plt.rcParams['figure.figsize'] = [24, 24]

	plt.subplot(1, 4, 1)
	show_image(x[0], "original")

	plt.subplot(1, 4, 2)
	show_image(im_masked[0], "masked")

	plt.subplot(1, 4, 3)
	show_image(y[0], "reconstruction")

	plt.subplot(1, 4, 4)
	show_image(im_paste[0], "reconstruction + visible")

	plt.show()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值