Hihocoder之conv2d()
http://hihocoder.com/contest/tupu2018/problem/2
题目2 : Standard 2D Convolution
描述
Implement such below standard convolution
conv2d(input tensor, filters = 8, kernel size=[5,5], stride = 2, zero padding = 'SAME', activation = relu)
The shape of input tensor: [height = 32, width = 32, channels = 3]
输入
The first line will contain an image. The value of pixels is [0, 255]. The image should be preprocessed (/127.5 - 1) before fed into the convolution function. Weights[kernel height, kernel width, input channels, output channels] and biases[output channels] are followed in the next two lines respectively.
输出
Print the result tensor in one line printed in the same way as input file. The precision is (1E-4).
注意
All data are arranged into one line using C-like order, with the last axis index changing fastest, back to the first axis index changing slowest.
- 样例输入
-
Download the sample input from: https://media.hihocoder.com/contests/tupu-campus-hiring-2017/conv_sample_input.txt
- 样例输出
-
Download the sample output from: https://media.hihocoder.com/contests/tupu-campus-hiring-2017/conv_sample_output.txt
题意:实现conv2d()卷积函数。
#input channels = 3, output channels = 8
#input_tensor = 32 * 32 * 3
#weights = 5 * 5 * 3 * 8
#biases = 1*8
参数解释:stride是步长参数;zero padding表示是否用零填充边缘进行,same表示在stride = 1的时候输出矩阵大小不变; activation是激励函数;ReLU函数为f(x) = max(x, 0)。
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
#define Height 32
#define Width 32
#define Channels 3
#define Filters 8
#define kernel 5
#define Eps 1e-5
float weight[kernel][kernel][Channels][Filters];
float biases[Filters];
, , , string padding = "SAME", string activation = "relu")
{
int feaMapH = ceil(Height * 1.0 / stride);
) * stride + kernelSize;
;
int paddingR = (HeightAfterPadding - Height) - paddingL;
vector<vector< vector<float> > >a;
;i < HeightAfterPadding;i++){
vector< vector<float> >b;
; j < HeightAfterPadding;j++){
vector<float>c;
;k < Channels;k++){
c.push_back();
}
b.push_back(c);
}
a.push_back(b);
}
//cout << HeightAfterPadding << endl;
;i < Height;i++){
; j < Width;j++){
;k < Channels;k++){
a[paddingL + i][paddingL + j][k] = ((float)(inputTensor[i][j][k])) / 127.5 - 1.0;
}
}
}
;i <= HeightAfterPadding - kernelSize;i += stride){
; j <= HeightAfterPadding - kernelSize;j += stride){
;nn < filters;nn++){
;
;k < kernelSize;k++){
;l < kernelSize;l++){
;mm < Channels;mm++){
sum += a[i + k][j + l][mm] * weight[k][l][mm][nn];
}
}
}
sum += biases[nn];
if(sum < Eps) cout << "0.0000 " ;
else printf("%.4f ",sum);
}
//cout << endl;
}
}
return ;
}
int main()
{
int a[Height][Width][Channels];
//freopen("conv_sample_input.txt","r",stdin);
;i < Height;i++){
;j < Width;j++){
;k < Channels;k++){
cin >> a[i][j][k];
}
}
}
;i < kernel;i++){
;j < kernel;j++){
;k < Channels;k++){
;l < Filters;l++){
cin >> weight[i][j][k][l];
}
}
}
}
;l < Filters;l++){
cin >> biases[l];
}
conv2d(a,Filters,kernel);
;
}
Hihocoder之conv2d()的更多相关文章
- hihocoder -1121-二分图的判定
hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...
- Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...
- hihoCoder太阁最新面经算法竞赛15
hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...
- 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II
http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...
- 【hihocoder#1413】Rikka with String 后缀自动机 + 差分
搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...
- 【hihoCoder】1148:2月29日
问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...
- 【hihoCoder】1288 : Font Size
题目:http://hihocoder.com/problemset/problem/1288 手机屏幕大小为 W(宽) * H(长),一篇文章有N段,每段有ai个字,要求使得该文章占用的页数不超过P ...
- 【hihoCoder】1082: 然而沼跃鱼早就看穿了一切
题目:http://hihocoder.com/problemset/problem/1082 输入一个字符串,将其中特定的单词替换成另一个单词 代码注意点: 1. getline(istre ...
- 【hihoCoder】1121:二分图一·二分图判定
题目 http://hihocoder.com/problemset/problem/1121 无向图上有N个点,两两之间可以有连线,共有M条连线. 如果对所有点进行涂色(白/黑),判定是否存 ...
随机推荐
- 如何写一个Xss Bot
如何写一个Xss Bot 现在的ctf比赛里 xss的出题方式比较特殊,一般使用xss bot,所以借鉴大佬经验尝试弄一个xss题目. xss bot 就是代替管理员去完成点击页面的任务,bot需要能 ...
- Post请求和Get请求;@RequestBody和@RequestParam
1.@RequestBody用于Post请求,接收json数据,例如:@RequestBody User user 例如:@RequestBody Map map .不要用于Get请求. 2.@Req ...
- Axure 制作 轮播 左右按钮轮播图
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 ...
- 微信小程序自定义 tabbar
一定的需求情况下,无法使用小程序原生的 tabbar 的时候,需要自行实现一个和 tabbar 功能一模一样的自制组件. 查阅了海量的博客和文档之后,亲自踩坑.总结了三种在不使用微信小程序原生 tab ...
- 【总结】Java面试题
部分转自 https://blog.csdn.net/junchi_/article/details/79754032 一.String特性.StringBuffer 和 StringBuilder ...
- [文章存档]如何检测 Azure Web 应用沙盒环境文件系统存储量
链接:https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-h ...
- hadoop之定制自己的Partitioner
partitioner负责shuffle过程的分组部分,目的是让map出来的数据均匀分布在reducer上,当然,如果我们不需要数据均匀,那么这个时候可以自己定制符合要求的partitioner. 下 ...
- YQCB冲刺周第六天
站立会议如上图 任务看板: 今天的任务为依旧为将用户记录的数据添加到数据库中,以及金额球的设置. 遇到的问题为金额球在jsp页面的显示.
- CentOS中Intel i350T4驱动安装
2015.3.31 在linux*中直接按解决方法中安装i350驱动即可 *************************************************************** ...
- NABCD模型分析
1.N——need需求 目前,学习英语是所有学生会面临的问题.提高词汇量对学习英语是十分必要的,尤其是对大学生来说对手机的使用特别频繁,我们提高英语词汇量也应该把手机更好的利用起来,利用自己对手机的使 ...