计算卷积和池化后图片尺寸
程序员文章站
2023-12-31 17:32:34
...
计算卷积和池化后图片尺寸
#include "math.h"
#include <iostream>
using namespace std;
void Conv(int width, int height, int filter, int padding, int stride) {
cout << "-------------------------------" << endl;
cout << "width:" << floor((width - filter + 2 * padding) / stride) + 1 << endl;
cout << "height:" << floor((height - filter + 2 * padding) / stride) + 1 << endl;
cout << "-------------------------------" << endl;
}
void Pool(int width, int height, int filter, int stride) {
cout << "-------------------------------" << endl;
cout << "width:" << floor((width - filter ) / stride) + 1 << endl;
cout << "height:" << floor((height - filter ) / stride) + 1 << endl;
cout << "-------------------------------" << endl;
}
int main() {
int choice;
cout << "计算卷积后图片尺寸按1,计算池化后图片尺寸按2" << endl;
cin >> choice;
if (choice == 1) {
int width, height, filter, padding, stride;
cout << "按顺序输入图片宽,高,卷积核大小,padding,步长" << endl;
cin >> width >> height >> filter >> padding >> stride;
Conv( width, height, filter, padding, stride);
}
else {
int width, height, filter, stride;
cout << "按顺序输入图片宽,高,池化核大小,步长" << endl;
cin >> width >> height >> filter >> stride;
Pool(width, height, filter, stride);
}
int stop = 0;
cout << "终止程序请输入1,否则输入任意数字" << endl;
cin >> stop;
while (stop != 1) {
cout << "计算卷积后图片尺寸按1,计算池化后图片尺寸按2" << endl;
cin >> choice;
if (choice == 1) {
int width, height, filter, padding, stride;
cout << "按顺序输入图片宽,高,卷积核大小,padding,步长" << endl;
cin >> width >> height >> filter >> padding >> stride;
Conv(width, height, filter, padding, stride);
}
else {
int width, height, filter, stride;
cout << "按顺序输入图片宽,高,池化核大小,步长" << endl;
cin >> width >> height >> filter >> stride;
Pool(width, height, filter, stride);
}
cout << "终止程序请输入1,否则输入任意数字" << endl;
cin >> stop;
}
}