归一化:
/*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加速
这部分结束