流程:
定义数据池:
1。残差块
struct 残差块 //标准残差块
{
BN层数据 * bn0;
层数据 * conv1;
BN层数据 * bn1;
层数据 * conv2;
BN层数据 * bn2;
层数据 * conv3;
};
2。总模型
struct RVN模型
{
//层数据 * conv0;//3->64 0
//BN层数据 * bn0;//64 1
//残差块64 * res64;//64->128 3-17
SpatialMaxPooling 18
//残差块128 * res128;//128->64->128 19-32
//残差块256 * res256;//128->256 34-48
//
//残差半场 * half1;//48-688
//残差半场 * half2;//689-1329
//层数据 * conv1;//256->256 1333
//BN层数据 * bn1;//156 1334
//层数据 * conv2;//256->200 1336
//SpatialUpSamplingBilinear 1337
//Sigmoid 1338
BN层数据 * bn;//273个
层数据 * conv;//276个
//构造函数
RVN模型();
};
RVN模型::RVN模型()
{
int size;
//为所有 276 个卷积层 和 273 个正则化层 分配内存
size= sizeof(层数据)*276;
conv=(层数据 *)malloc(size);
size = sizeof(BN层数据)*273;
bn=(BN层数据 *)malloc(size);
}
3。主函数:
void RVN(char * savefilename,RVN模型 & sr)
{
int wid=bmp.width;
int hei=bmp.height;
int wh=wid * hei;
cout<<"输入图像宽度:"<<wid<<endl;
cout<<" 高度:"<<hei<<endl;
//
卷积层 rgb(wid,hei,3);//亮度
rgb.data=new float[wid * hei*3 ];
bmp2RGB(rgb);
//卷积层乘以(rgb,1.0f/255.f);
层数据 * 层;
int pad;
//
//缩放到 192x192
卷积层 di(192,192,3);
di.data=new float[192*192*3];
wid=192;
hei=192;
wh=wid * hei;
卷积层双三次插值(rgb,di);
//卷积层复制(&rgb,&di);
//save_卷积层2jpg(&di,"di");
卷积层 *源=&di;
卷积层 *目标=&rgb;
层数据 * conv;
BN层数据 * bn;
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
//load_mat2卷积层2("me/input_1.txt",源);
//save_卷积层2jpg(源,"input_1");
//conv_1
conv=sr.conv-1+1;
卷积前传2步长无RELU(conv);
// load_mat2卷积层2("me/conv_1.txt",源);
//save_卷积层2jpg(源,"conv_1");
//instance_norm(*源);
//卷积层乘以(*源,1.0f/255.f);
//batch_norm_1
bn=sr.bn-1+1;
//instance_norm(*源);
//vl_Scale(源,bn->权重,bn->偏移);
批正则前传(bn);
//load_mat2卷积层2("me/batch_norm_1.txt",源);
//save_卷积层2txt(源,"batch_norm_1-me.txt");
vl_nnrelu(源);
cout<<"add_1..."<<endl;
//非标准残差块--------------------------
卷积层 activation_1(wid,hei,源->depth);
activation_1.data=new float[wid * hei * 源->depth];
卷积层复制(源,&activation_1);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//batch_norm_2 (BatchNorm) (None, 64, 96, 96) 256 activation_1[0][0]
bn=sr.bn-1+2;
批正则前传(bn);
vl_nnrelu(源);
//conv_2 (Conv) (None, 64, 96, 96) 4160 activation_2[0][0]
conv=sr.conv-1+2;
卷积前传无RELU(conv);
//batch_norm_3 (BatchNorm) (None, 64, 96, 96) 256 conv_2[0][0]
bn=sr.bn-1+3;
批正则前传(bn);
vl_nnrelu(源);
//conv_3 (Conv) (None, 64, 96, 96) 36928 activation_3[0][0]
conv=sr.conv-1+3;
卷积前传无RELU(conv);
//batch_norm_4 (BatchNorm) (None, 64, 96, 96) 256 conv_3[0][0]
bn=sr.bn-1+4;
批正则前传(bn);
vl_nnrelu(源);
//conv_4 (Conv) (None, 128, 96, 96) 8320 activation_4[0][0]
conv=sr.conv-1+4;
卷积前传无RELU(conv);
卷积层 conv_4(wid,hei,源->depth);
conv_4.data=new float[wid * hei * 源->depth];
卷积层复制(源,&conv_4);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//- - - - - ->跳到后面
Resize卷积层(*源,wid,hei,activation_1.depth);
卷积层复制(&activation_1,源);
del卷积层(activation_1);
//conv_5 (Conv) (None, 128, 96, 96) 8320 activation_1[0][0]
conv=sr.conv-1+5;
卷积前传无RELU(conv);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_1 (Add) (None, 128, 96, 96) 0 conv_4[0][0]
// conv_5[0][0]
卷积层相加(&conv_4,源);//4+5
del卷积层(conv_4);
cout<<"最大池化 1..."<<endl;
//add_1->max_pooling2d_1
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
cout<<"add_2..."<<endl;
//max_pooling2d_1->add_2
//起个头残差块前传(*源,*目标,5,sr);
残差块顺次前传(*源,*目标,5,6,sr);
cout<<"add_3..."<<endl;
//非标准残差块--------------------------
卷积层 add_2(wid,hei,源->depth);
add_2.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_2);
//batch_norm_8 (BatchNorm) (None, 128, 48, 48) 512 add_2[0][0]
bn=sr.bn-1+8;
批正则前传(bn);
vl_nnrelu(源);
//conv_9 (Conv) (None, 128, 48, 48) 16512 activation_8[0][0]
conv=sr.conv-1+9;
卷积前传无RELU(conv);
//batch_norm_9 (BatchNorm) (None, 128, 48, 48) 512 conv_9[0][0]
bn=sr.bn-1+9;
批正则前传(bn);
vl_nnrelu(源);
//conv_10 (Conv) (None, 128, 48, 48) 147584 activation_9[0][0]
conv=sr.conv-1+10;
卷积前传无RELU(conv);
//batch_norm_10 (BatchNorm) (None, 128, 48, 48) 512 conv_10[0][0]
bn=sr.bn-1+10;
批正则前传(bn);
vl_nnrelu(源);
//conv_11 (Conv) (None, 256, 48, 48) 33024 activation_10[0][0]
conv=sr.conv-1+11;
卷积前传无RELU(conv);
卷积层 conv_11(wid,hei,源->depth);
conv_11.data=new float[wid * hei * 源->depth];
卷积层复制(源,&conv_11);
//- - - - - ->跳到后面
Resize卷积层(*源,wid,hei,add_2.depth);
卷积层复制(&add_2,源);
del卷积层(add_2);
//add_2->conv_12
conv=sr.conv-1+12;
卷积前传无RELU(conv);
//conv_11 + conv_12 -> add_3
卷积层相加(&conv_11,源);
del卷积层(conv_11);
//load_mat2卷积层2("me/add_3.txt",源);
cout<<"上半场..."<<endl;
wid =48;hei =48;
Resize卷积层(*源,wid,hei,256);
卷积层 add_3(wid,hei,源->depth);
add_3.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_3);
cout<<"add_3->add_6"<<endl;
//add_3->add_4
//起个头残差块前传(*源,*目标,11,sr);
残差块顺次前传(*源,*目标,11,13,sr);
//add_4->add_5
//起个头残差块前传(*源,*目标,14,sr);
残差块顺次前传(*源,*目标,14,16,sr);
//add_5->add_6
//起个头残差块前传(*源,*目标,17,sr);
残差块顺次前传(*源,*目标,17,19,sr);
卷积层 add_6(wid,hei,源->depth);
add_6.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_6);
cout<<"add_6->add_9"<<endl;
//add_6->add_7
//起个头残差块前传(*源,*目标,20,sr);
残差块顺次前传(*源,*目标,20,22,sr);
//add_7->add_8
残差块顺次前传(*源,*目标,23,25,sr);
//add_8->add_9
残差块顺次前传(*源,*目标,26,28,sr);
卷积层 add_9(wid,hei,源->depth);
add_9.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_9);
cout<<"add_9->add_12"<<endl;
//add_9->add_10
残差块顺次前传(*源,*目标,29,31,sr);
//add_10->add_11
残差块顺次前传(*源,*目标,32,34,sr);
//add_11->add_12
残差块顺次前传(*源,*目标,35,37,sr);
卷积层 add_12(wid,hei,源->depth);
add_12.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_12);
cout<<"add_12->add_15"<<endl;
//add_12->add_13
残差块前传(*源,*目标,66,71,76,68,73,78,sr);
//->add_14
残差块前传(*源,*目标,81,86,91,83,88,93,sr);
//->add_15
残差块前传(*源,*目标,96,101,106,98,103,108,sr);
卷积层 add_15(wid,hei,源->depth);
add_15.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_15);
//- - - - - ->跳到后面
卷积层复制(&add_12,源);
del卷积层(add_12);
cout<<"最大池化 2..."<<endl;
//add_12->max_pooling2d_2
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//max_pooling2d_2->add_16
残差块顺次前传(*源,*目标,38,40,sr);
cout<<"add_16->add_17"<<endl;
//add_16->add_17
残差块顺次前传(*源,*目标,41,43,sr);
//add_17->add_18
残差块顺次前传(*源,*目标,44,46,sr);
//->add_19
残差块顺次前传(*源,*目标,47,49,sr);
cout<<"add_19->add_20..."<<endl;
//->add_20
残差块跳X前传(*源,*目标,50,52,sr,2);//???
cout<<"add_20->add_21..."<<endl;
//->add_21
残差块跳X前传(*源,*目标,56,58,sr,3);
cout<<"add_21->add_22..."<<endl;
//->add_22
残差块前传(*源,*目标,65,69,74,67,71,76,sr);
//->add_23
残差块前传(*源,*目标,80,84,89,82,86,91,sr);
cout<<"add_23->add_24..."<<endl;
//->add_24
残差块前传(*源,*目标,95,99,104,97,101,106,sr);
cout<<"邻近插值..."<<endl;
//add_24->up_sampling2d_1
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_8
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_15 + up_sampling2d_1->add_25
卷积层相加(&add_15,源);
del卷积层(add_15);
cout<<"add_25->add_26"<<endl;
//->add_26
//起个头残差块前传(*源,*目标,111,sr);
残差块跳X前传(*源,*目标,111,113,sr,4);
卷积层 add_26(wid,hei,源->depth);
add_26.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_26);
//- - - - - ->跳到后面
卷积层复制(&add_9,源);
del卷积层(add_9);
cout<<"最大池化3"<<endl;
//add_9->max_pooling2d_3
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//max_pooling2d_3->add_27
残差块跳X前传(*源,*目标,51,53,sr,2);
cout<<"add_27->add_28"<<endl;
//->add_28
残差块跳X前传(*源,*目标,57,59,sr,3);
//->add_29
残差块跳X前传(*源,*目标,67,69,sr,5);
cout<<"add_29->add_30"<<endl;
//->add_30
残差块跳X前传(*源,*目标,82,84,sr,5);
cout<<"add_30->add_31"<<endl;
//->add_31
残差块跳X前传(*源,*目标,97,99,sr,5);
//->add_32
残差块跳X前传(*源,*目标,110,112,sr,4);
cout<<"邻近插值..."<<endl;
//add_32->up_sampling2d_2
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_8
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_26 +up_sampling2d_2->add_33
卷积层相加(&add_26,源);
del卷积层(add_26);
//->add_34
残差块跳X前传(*源,*目标,123,125,sr,3);
卷积层 add_34(wid,hei,源->depth);
add_34.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_34);
//- - - - - ->跳到后面
卷积层复制(&add_6,源);
del卷积层(add_6);
cout<<"最大池化4"<<endl;
//add_6->max_pooling2d_4
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//max_pooling2d_4->add_35
残差块跳X前传(*源,*目标,58,60,sr,3);
//->add_36
残差块跳X前传(*源,*目标,68,70,sr,5);
cout<<"add_36->add_37..."<<endl;
//->add_37
残差块跳X前传(*源,*目标,83,85,sr,5);
//->add_38
残差块跳X前传(*源,*目标,98,100,sr,5);
cout<<"add_38->add_39..."<<endl;
//->add_39
残差块跳X前传(*源,*目标,112,114,sr,4);
cout<<"add_39->add_40..."<<endl;
//->add_40
残差块跳X前传(*源,*目标,122,124,sr,3);
cout<<"邻近插值..."<<endl;
//add_40->up_sampling2d_3
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_8
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_34 + up_sampling2d_3 -> add_41
卷积层相加(&add_34,源);
del卷积层(add_34);
//add_41->add_42
残差块跳X前传(*源,*目标,132,134,sr,2);
卷积层 add_42(wid,hei,源->depth);
add_42.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_42);
//- - - - - ->跳到后面
卷积层复制(&add_3,源);
//add_3->max_pooling2d_5
cout<<"最大池化5"<<endl;
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//max_pooling2d_5->add_43
残差块前传(*源,*目标,70,75,79,72,77,81,sr);
cout<<"add_43->add_44..."<<endl;
//->add_44
残差块前传(*源,*目标,85,90,94,87,92,96,sr);
//->add_45
残差块前传(*源,*目标,100,105,109,102,107,111,sr);
cout<<"add_45->add_46..."<<endl;
//->add_46
残差块跳X前传(*源,*目标,113,115,sr,4);
//->add_47
残差块跳X前传(*源,*目标,124,126,sr,3);
cout<<"add_47->add_48..."<<endl;
//->add_48
残差块跳X前传(*源,*目标,131,133,sr,2);
cout<<"邻近插值..."<<endl;
//add_48->up_sampling2d_4
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_42 +up_sampling2d_4->add_49
卷积层相加(&add_42,源);
del卷积层(add_42);
//add_49->add_50
残差块跳X前传(*源,*目标,137,139,sr,1);
//附加
//add_50->conv_142
conv=sr.conv-1+142;
卷积前传无RELU(conv);
//batch_norm_140
bn=sr.bn-1+140;
批正则前传(bn);
vl_nnrelu(源);
//conv_143
conv=sr.conv-1+143;
卷积前传无RELU(conv);
//batch_norm_141
bn=sr.bn-1+141;
批正则前传(bn);
vl_nnrelu(源);
//add_3+activation_141->add_51
卷积层相加(&add_3,源);//add_99
del卷积层(add_3);
cout<<"下半场..."<<endl;
卷积层 add_51(wid,hei,源->depth);
add_51.data=new float[wid * hei * 源->depth];
//load_mat2卷积层2("me/add_51.txt",源);
//save_卷积层2jpg(源,"add_51");
卷积层复制(源,&add_51);
cout<<"add_51->add_54..."<<endl;
//add_51->add_52
残差块前传(*源,*目标,142,143,144,144,145,146,sr);
//add_52->add_53
残差块前传(*源,*目标,145,146,147,147,148,149,sr);
//add_53->add_54
残差块前传(*源,*目标,148,149,150,150,151,152,sr);
卷积层 add_54(wid,hei,源->depth);
add_54.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_54);
cout<<"add_54->add_57..."<<endl;
//add_54->add_55
残差块前传(*源,*目标,151,152,153,153,154,155,sr);
//add_55->add_56
残差块前传(*源,*目标,154,155,156,156,157,158,sr);
//add_56->add_57
残差块前传(*源,*目标,157,158,159,159,160,161,sr);
//load_mat2卷积层2("me/add_57.txt",源);
卷积层 add_57(wid,hei,源->depth);
add_57.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_57);
cout<<"add_57->add_60..."<<endl;
//add_57->add_58
残差块顺次前传(*源,*目标,160,162,sr);
//add_58->add_59
残差块顺次前传(*源,*目标,163,165,sr);
//add_59->add_60
残差块顺次前传(*源,*目标,166,168,sr);
卷积层 add_60(wid,hei,源->depth);
add_60.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_60);
cout<<"add_60->add_63..."<<endl;
//add_60->add_61
//残差块前传(*源,*目标,197,202,207,199,204,209,sr);
残差块跳X前传(*源,*目标,197,199,sr,5);
//add_61->add_62
残差块前传(*源,*目标,212,217,222,214,219,224,sr);
//add_62->add_63
残差块前传(*源,*目标,227,232,237,229,234,239,sr);
卷积层 add_63(wid,hei,源->depth);
add_63.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_63);
//- - - - - ->跳到后面
cout<<"第6最大池化"<<endl;
//add_60->max_pooling2d_6
卷积层复制(&add_60,源);
del卷积层(add_60);
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
cout<<"池化后9残差块"<<endl;
//max_pooling2d_6->add_64
残差块顺次前传(*源,*目标,169,171,sr);
cout<<"add_64->add_72..."<<endl;
//add_64->add_65
残差块顺次前传(*源,*目标,172,174,sr);
//add_65->add_66
残差块顺次前传(*源,*目标,175,177,sr);
//add_66->add_67
残差块顺次前传(*源,*目标,178,180,sr);
//add_67->add_68
残差块前传(*源,*目标,181,183,185,183,185,187,sr);
//add_68->add_69
残差块前传(*源,*目标,187,190,193,189,192,195,sr);
//add_69->add_70
残差块前传(*源,*目标,196,200,205,198,202,207,sr);
//add_70->add_71
残差块前传(*源,*目标,211,215,220,213,217,222,sr);
//add_71->add_72
残差块前传(*源,*目标,226,230,235,228,232,237,sr);
cout<<"邻近插值..."<<endl;
//add_72->up_sampling2d_5
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_5
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_63 + up_sampling2d_5 ->add_73
卷积层相加(&add_63,源);
del卷积层(add_63);
//add_73->add_74
残差块顺次前传(*源,*目标,160,162,sr);
//load_mat2卷积层2("me/add_74.txt",源);
卷积层 add_74(wid,hei,源->depth);
add_74.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_74);
//- - - - - ->跳到后面
卷积层复制(&add_57,源);
del卷积层(add_57);
//add_57->max_pooling2d_7
cout<<"第7最大池化"<<endl;
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
cout<<"第一6残差块"<<endl;
//conv_188 + max_pooling2d_7 ->add_75
残差块前传(*源,*目标,182,184,186,184,186,188,sr);
//起个头残差块前传(*源,*目标,182,sr);
//add_75 - - - - - - ->add_80
//add_75->add_76
残差块前传(*源,*目标,188,191,194,190,193,196,sr);
//起个头残差块前传(*源,*目标,188,sr);
//add_76->add_77
残差块前传(*源,*目标,198,203,208,200,205,210,sr);
//起个头残差块前传(*源,*目标,198,sr);
//load_mat2卷积层2("me/add_77.txt",源);
//add_77->add_78
残差块前传(*源,*目标,213,218,223,215,220,225,sr);
//add_78->add_79
残差块前传(*源,*目标,228,233,238,230,235,240,sr);
//add_79->add_80
残差块前传(*源,*目标,241,245,249,243,247,251,sr);
//load_mat2卷积层2("me/add_80.txt",源);
cout<<"邻近插值..."<<endl;
//add_80->up_sampling2d_6
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_6
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//add_74 + up_sampling2d_6 -> add_81
卷积层相加(&add_74,源);
del卷积层(add_74);
//add_81->add_82
残差块前传(*源,*目标,254,257,260,256,259,262,sr);
//load_mat2卷积层2("me/add_82.txt",源);
//---------后面已成功
卷积层 add_82(wid,hei,源->depth);
add_82.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_82);
//- - - - - ->跳到后面
卷积层复制(&add_54,源);
//add_54-max_pooling2d_8
cout<<"第8最大池化"<<endl;
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
cout<<"第二6残差块"<<endl;
//max_pooling2d_8 -> add_83
残差块前传(*源,*目标,189,192,195,191,194,197,sr);
//add_83------------->add_88
//add_83->add_84
残差块前传(*源,*目标,199,204,209,201,206,211,sr);
//add_84->add_85
残差块前传(*源,*目标,214,219,224,216,221,226,sr);
//add_85->add_86
残差块前传(*源,*目标,229,234,239,231,236,241,sr);
//add_86->add_87
残差块前传(*源,*目标,243,247,251,245,249,253,sr);
//add_87->add_88
残差块前传(*源,*目标,253,256,259,255,258,261,sr);
//load_mat2卷积层2("me/add_88.txt",源);
cout<<"邻近插值..."<<endl;
//add_88->up_sampling2d_7
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_7
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//save_卷积层2txt(源,"up_sampling2d_7-me.txt");
//add_82 + up_sampling2d_7 -> add_89
卷积层相加(&add_82,源);
del卷积层(add_82);
//add_89->add_90
残差块前传(*源,*目标,263,265,267,265,267,269,sr);
//load_mat2卷积层2("me/add_90.txt",源);
卷积层 add_90(wid,hei,源->depth);
add_90.data=new float[wid * hei * 源->depth];
卷积层复制(源,&add_90);
//- - - - - ->跳到后面
//---------后面已成功
卷积层复制(&add_51,源);
//add_51-> max_pooling2d_9
cout<<"第9最大池化"<<endl;
wid /=2;hei /=2;
Resize卷积层(*目标,wid,hei,源->depth);
vl_nnpool(源,目标);
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//wid =24;hei =24;
// load_mat2卷积层2("me/max_pooling2d_9.txt",源);
//save_卷积层2jpg(源,"max_pooling2d_9");
cout<<"第三6残差块"<<endl;
//conv_212 + max_pooling2d_9->add_91
残差块前传(*源,*目标,201,206,210,203,208,212,sr);//池化后残差块
//add_91->add_92
残差块前传(*源,*目标,216,221,225,218,223,227,sr);
//add_92->add_93
残差块前传(*源,*目标,231,236,240,233,238,242,sr);
//load_mat2卷积层2("me/add_93.txt",源);
//add_93->add_94
残差块前传(*源,*目标,244,248,252,246,250,254,sr);
//load_mat2卷积层2("me/add_94.txt",源);
//add_94->add_95
残差块前传(*源,*目标,255,258,261,257,260,263,sr);
//load_mat2卷积层2("me/add_95.txt",源);
//add_95->add_96
残差块前传(*源,*目标,262,264,266,264,266,268,sr);
//wid =48;hei =48;
//load_mat2卷积层2("me/add_96.txt",源);
cout<<"邻近插值..."<<endl;
wid *=2;hei *=2;
Resize卷积层(*目标,wid,hei,源->depth);
最近邻插值(*源,*目标);// up_sampling2d_8
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//load_mat2卷积层2("me/add_90.txt",目标);
//add_90 + up_sampling2d_8 -> add_97
卷积层相加(&add_90,源);
del卷积层(add_90);
//load_mat2卷积层2("me/add_97.txt",源);//成功
cout<<"后1残差块"<<endl;
//add_97->add_98
残差块前传(*源,*目标,268,269,270,270,271,272,sr);
//附加
//load_mat2卷积层2("me/add_98.txt",源);
conv=sr.conv-1+273;
卷积前传无RELU(conv);
bn=sr.bn-1+271;
批正则前传(bn);
vl_nnrelu(源);
// load_mat2卷积层2("me/activation_271.txt",源);
conv=sr.conv-1+274;
卷积前传无RELU(conv);
bn=sr.bn-1+272;
批正则前传(bn);
vl_nnrelu(源);
卷积层相加(&add_51,源);//add_99
del卷积层(add_51);
//load_mat2卷积层2("me/add_99.txt",源);
conv=sr.conv-1+275;//275
卷积前传无RELU(conv);
//load_mat2卷积层2("me/conv_275.txt",源);
bn=sr.bn-1+273;//273
批正则前传(bn);
vl_nnrelu(源);
load_mat2卷积层2("me/activation_273.txt",源);
// save_卷积层2jpg(源,"activation_273");
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
conv=sr.conv-1+276;//276
卷积前传无RELU(conv);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
//cout<<*(sr.conv2->权重_数据)<<","<<*(sr.conv2->偏移_数据)<<","<<sr.conv2->偏移长度<<endl;
//cout<<*(conv->权重_数据)<<","<<*(conv->偏移_数据)<<","<<conv->偏移长度<<endl;
//load_mat2卷积层2("me/conv_276.txt",源);
//save_卷积层2txt(源,"out.txt");
//save_卷积层2jpg(源,"out");
//*
//------------------放大4倍------------------------------
wid *=4;hei *=4;
Resize卷积层(*目标,wid,hei,源->depth);
双线性插值(*源,*目标);// 1137
std::swap (目标,源);
cout<<源->width<<","<<源->height<<","<<源->depth<<endl;
vl_sigmoid(源);
卷积层乘以(*源,255.f);
卷积层 *灰度 = 转换体素到灰度图(*源);
cout<<"保存灰度图: gray0.jpg"<<endl;
save_卷积层2jpg(灰度,"gray");
//save_卷积层2txt(灰度,"gray.txt");
/*/
cout<<"保存体素..."<<endl;
save_卷积层2txt(源,"vol.txt");
cout<<"转换文件已经保存为: vol.txt"<<endl;
//save_卷积层2txt(源,"tishu.txt");
//cout<<"转换文件已经保存为: tishu.txt"<<endl;
//*/
体素到点云并保存(*源);
}
而后按前文在meshlab中处理
效果图:
输入图
由于一些我未知的原因,并没有达到原模型的效果,估计有python下的七八分吧。
下载:
3D人脸重建win32程序
3D人脸重建 RVN(win下),由VRN-Keras-master下的vrn-unguided-keras.h5改编而来,而且并没有完全达到 python 下的效果,算抛砖引玉吧。