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条连线. 如果对所有点进行涂色(白/黑),判定是否存 ...
随机推荐
- python 网页转pdf
主要使用的是wkhtmltopdf的Python封装——pdfkit centos环境 安装:Install python-pdfkit pip install pdfkit 安装:Install w ...
- golang -- 字符串就地取反
字符串 定义 在golang中字符串是一种不可变的字节序列,它可以包含任意的数据,包括0值字节,但主要是人类可以阅读的文本.golang中默认字符串被解读为utf-8编码的Unicode码点(文字符号 ...
- 小刘的深度学习---CNN
前言: 前段时间我在树莓派上通过KNN,SVM等机器学习的算法实现了门派识别的项目,所用到的数据集是经典的MNIST.可能是因为手写数字与印刷体存在一些区别,识别率并是很不高.基于这样的情况,我打算在 ...
- Cocos2dx源码赏析(2)之渲染
Cocos2dx源码赏析(2)之渲染 这篇,继续从源码的角度来跟踪下Cocos2dx引擎的渲染过程,以此来梳理下Cocos2dx引擎是如何将精灵等元素显示在屏幕上的. 从上一篇对Cocos2dx启动流 ...
- 时间戳使用的bug,你见过么
博主本人前几天给公司项目里写了个禁言和解除禁言的功能,项目中涉及到对时间的处理,因为学得时候也没很注意,就按自己的思路去写了,运行起来发现了一个天大的bug,就是写的延后一年尽然,刚开始就执行了,而且 ...
- whoami,who,w命令详解
http://www.voidcn.com/blog/wszzdanm/article/p-6145895.html 命令功能:显示登录用户的信息 命令格式: 常用选项: 举例: w 显示已经登录的用 ...
- 编写webpack 插件
Webpack插件为第三方开发者释放了Webpack的最大可能性.利用多级回调开发者可以把他们自己的需要的功能引入到Webpack里面来.Build插件比Build loader 更进一步.因为你需要 ...
- JS进阶系列之原型、原型链
最近在看 JavaScript忍者秘籍 这本书的时候,再加上最近遇到的关于原型.原型链的面试题,所以萌生了要把这些知识梳理一遍的想法,所以以下是我自己对原型.原型链的看法 什么是原型 提到原型,我们可 ...
- Daily Scrum 11.19 部分测试报告
下面是我们的部分测试报告: 功能测试部分: 1Exception in thread "Thread-11" java.lang.IllegalArgumentException: ...
- Scrum Meeting 10.28
今天大部分同学仍停留在学习阶段,进度快的同学已经在配置SQLserver. 成员 今日完成任务 明日计划 所用时间 徐越 配置SQLserver,试用java程序连接数据库 学习servlet,htt ...