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条连线. 如果对所有点进行涂色(白/黑),判定是否存 ...
随机推荐
- tpshop购物网站价格筛选功能的测试用例设计
测试对象:红框内的“价格筛选功能” 以下是功能需求: 1. 除了空以外,输入框不能输入数字之外的内容. 备注:如果出现数字之外的内容,输入框禁止输入. 2. 输入框不能小于0 备注:如果出现小于0的数 ...
- C#四则运算器(多态方法实现)
在上一节C#课上,我们学习了用类的继承的方式来做一个四则运算器,然而老师的代码在课上演示的效果并不理想,而且没有使用多态的思想实现,今天我们就来用多态的方式实现四则运算器. 1. 题目及要求 2. A ...
- [Codeforces-888C] - K-Dominant Character
C. K-Dominant Character time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Flash导出安卓端apk
最近外甥女在学校做了一个演示视频,基于flash做的,希望小舅给她导出成可以运行在pc/android端的可执行程序.看了下过程还是蛮复杂的,还只能一天时间.重新照葫芦画瓢做一款是来不及了,由于以前基 ...
- Git知识点整合
Git安装 Windows上安装Git 64 位安装包下载地址 : https://github.com/git-for-windows/git/releases/download/v2.16.2.w ...
- [2017 ACL] 对话系统
Long Papers [Domain adaptation ] 1. Adversarial Adaptation of Synthetic or Stale Data ( Cited by 14 ...
- Python处理PDF和Word文档常用的方法(二)
Python处理word时,需要安装和导入python-docx模块. 安装命令:pip install python-docx 导入命令:import docx 编码编写顺序:用docx.Docum ...
- exec命令详解
基础命令学习目录首页 原文链接: exec: 在bash下输入man exec,找到exec命令解释处,可以看到有”No new process is created.”这样的解释,这就是说exec命 ...
- [zabbix] zabbix数据采集频率、数据连续多次异常触发、告警次数、告警频率
数据采集频率:1分钟采集一次 数据连续多次异常触发:连续三次异常才触发告警 告警次数:告警三次 告警频率:每隔10分钟告警一次 默认模板“Template App Zabbix Agent”监控项“A ...
- Navicat将oracle中数据复制到mysql
1,首先两个数据库都要处于连接状态 2,工具 -- 数据传输 3,选择来源数据库以及要传输的表和目标数据库 4,点击开始 PS:遇到一个问题:[Err] [Dtf] 1426 - Too-big pr ...