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条连线. 如果对所有点进行涂色(白/黑),判定是否存 ...
随机推荐
- 随机图片api
什么是随机图片api 随机图片api是什么呢?通俗的讲就是当你访问一个api时,浏览器会随机返回给你一张图片. 其实原理很简单,把你要随机的图片放在一起,然后写一个php,当php被访问时,就随机指向 ...
- 【微服务架构】SpringCloud组件和概念介绍(一)
一:什么是微服务(Microservice) 微服务英文名称Microservice,Microservice架构模式就是将整个Web应用组织为一系列小的Web服务.这些小的Web服务可以独立地编译及 ...
- Discuz3.3精仿小米风格整站模板制作——1、新建模板方案
术语说明: 模板——模板是一堆按照规定命名方式的html文件,用于指定整个论坛不同页面的外观. 标签——标签和模板共同作用以实现论坛换肤功能,其中标签主要控制页面显示什么数据,显示多少条等. 风格—— ...
- nodejs加载模块心得,mongoose的继承,schematype的mixd介绍
1. require("xxx")可以是原生模块, 也可以是根目录“/node_modules”下的某个模块 2. 多个模块的package.json使用同一个相同模块的时候,将改 ...
- Centos7 zabbix 分布式监控
分布式监控 zabbix Server ===> zabbix agent (只能同一个局域网监控) 分布式监控: a. 分担压力,降低负载 b. 多机房 ...
- type命令详解
转自:http://codingstandards.iteye.com/blog/831504 在脚本中type可用于检查命令或函数是否存在,存在返回0,表示成功:不存在返回正值,表示不成功. $ t ...
- 第十一次ScrumMeeting博客
第十一次ScrumMeeting博客 本次会议于11月29日(三)22时整在3公寓725房间召开,持续30分钟. 与会人员:刘畅.辛德泰张安澜.赵奕.方科栋. 1. 每个人的工作(有Issue的内容和 ...
- C++ 类 复制构造函数 The Copy Constructor
一.复制构造函数的定义 复制构造函数是一种特殊的构造函数,具有一般构造函数的所有特性.复制构造函数创建一个新的对象,作为另一个对象的拷贝.复制构造函数只含有一个形参,而且其形参为本类对象的引用.复制构 ...
- ubuntu下编译ffmpeg+SDL+ffplay提取motion vector
编译ffmpeg: 第一步: 从官网http://ffmpeg.org/下载最新版本. 解压tar -xjvf ffmpeg-3.3.1.tar.bz2 进入目录cd ffmpeg-3.3.1 第二步 ...
- POJ 2151 Check the difficulty of problems 概率dp+01背包
题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...