原理
假设输入矩阵的大小为(H,W),卷积核的大小为(h,w),输出矩阵大小为(output_h,output_w),步长为S,周围填充为P,则:
output_h = (H + 2 * P - h) / S + 1
output_w = (W + 2 * P - w) / S + 1
代码
#include <iostream>
#include <vector>
using namespace std;
std::vector<std::vector<float>> conv2d(std::vector<std::vector<float>> input, std::vector<std::vector<float>> kernel, int stride, int padding) {
// 获取kernel_size,默认高和宽一样
int kernel_size = kernel.size();
// 获取输入矩阵大小
int input_width = input.size();
int input_height = input[0].size();
// 计算输出矩阵大小
int outout_width = (input_width + 2 * padding - kernel_size) / stride + 1;
int outout_height

最低0.47元/天 解锁文章
555

被折叠的 条评论
为什么被折叠?



