32位C++改编 对抗(SRGAN)之生成(generator)超分辨重建 ---(三)图像归一化(BatchNorm)和前处理

归一化:

/*y=(x-均值)/sqrt(方差+微小值)+位移 */
void tf_BatchNorm(卷积层 * out,float * mean,float * var,float * beta) //这里 gamma=1
{
	float * s=out->data;
	float p;
	int wh=out->width*out->height; 

	float m,v,b;

	//int k=0;

	for (int c=0; c<out->depth; ++c)
	{
		m=*mean++;v=1.0/sqrt(*var++ +0.001);b=*beta++;
		for (int i=0; i<wh; ++i)
		{
				
				p  = *s;//
					*s++ = (p-m)*v+b;
			
		}
		//if(k<10)
		//{
		//	cout<<"beta: "<<b<<endl;

		//}
	}

}

前处理:

    # 读入并预处理图像
    def preprocess_test(name):
        im = sic.imread(name).astype(np.float32)
        # 检查灰度图像
        if im.shape[-1] != 3:
            h, w = im.shape
            temp = np.empty((h, w, 3), dtype=np.uint8)
            temp[:, :, :] = im[:, :, np.newaxis]
            im = temp.copy()
        im = im / np.max(im)

        return im

从这里可以看到 并不是简单的 / 255,而是 / 最大值。

从这里的前后处理得到启发:

以前的那个espcn 2 和 3 倍重建都是比较灰暗,如果也作这样处理是不是会更好呢。

void 亮度扩展(卷积层 & hR)
{
	float * s=hR.data, *s0;
	float p;
	int wh=hR.width * hR.height; 
	float imax=0;

	s0 = s;
	for(int j=0;j<hR.depth;j++)
		for (int i=0; i<wh; ++i)
		{
				imax  =max( *s0++,imax);
			
		}

	s0 = s;
	for(int j=0;j<hR.depth;j++)
		for (int i=0; i<wh; ++i)
		{
				*s0++  /=imax;//除以最大值
			
		}
}

输入图espcn未扩展(3倍)扩展亮度(3倍)

这样是不是明亮一点了。

espcn3倍重建下载:

链接: https://pan.baidu.com/s/16MWK02SxBF9NVT8kA6ug7w 提取码: eg4y 
已加亮处理和OpenBLAS加速

这部分结束

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值