main.cpp 2.48 KB
#include"Layers.hpp"
#include"SimpleConvNet.hpp"
#include"fstream"
using namespace std;
int main() {

	input_dim id = { 3, 32, 32 };
	conv_param cp = { 32,32,64, 3,1,1 };
	SimpleConvNet SCN(id, cp);

	freopen("input.txt", "r", stdin);
	vector<Mat> X;
	int nx = 1, dim = 3, row = 32, col = 32;
	double tmp;
	for (int i = 0; i < nx; i++) {
		vector<double> rev;
		for (int d = 0; d < dim; d++) {
			for (int r = 0; r < row; r++) {
				for (int c = 0; c < col; c++) {
					scanf("%lf", &tmp);
					rev.push_back(tmp);
				}
			}
		}
		X.push_back(Mat(dim, row, col, rev));
	}
	freopen("pred.txt", "r", stdin);
	nx = 2, dim = 3, row = 32, col = 32;
	for (int i = 0; i < nx; i++) {
		vector<double> rev;
		for (int d = 0; d < dim; d++) {
			for (int r = 0; r < row; r++) {
				for (int c = 0; c < col; c++) {
					scanf("%lf", &tmp);
					rev.push_back(tmp);
				}
			}
		}
		X.push_back(Mat(dim, row, col, rev));
	}

	auto x = SCN.predict(X);

	auto pred = SCN.argmax(x);

	int num = 0, pd;



	char receipt[100];
	int total = 0;
	
	ifstream fin;
	ofstream fout;
	fin.open("receipt.txt");
	char c;
	int cnt=0;

	while(fin.get(c)){
		receipt[cnt] = c;
		cnt++;
	}
	fin.close();

	fout.open("receipt.txt");	
	for(int i=0; i<cnt; i++){
		fout << receipt[i];
	}

	switch(pred[0]){
		case 0:
			cout << "can\n";
			fout << 0;
			break;
		case 1:
			cout << "ramen\n";
			fout << 1;
			break;
 		case 2:
			cout << "cigarette\n";
			fout << 2;
			break;
		case 3:
			cout << "instant rice\n";
			fout << 3;
			break;
		case 4:
			cout << "wet tissue\n";
			fout << 4;
			break;
		default:
			cout << "try again\n";
			break;
	}

	fout.close();

	fin.open("receipt.txt");
	cnt=0;

	while(fin.get(c)){
		receipt[cnt] = c;
		cnt++;
	}
	fin.close();
	cout << "\n\n===================receipt===================\n\n\n";
	for(int i = 0; i<cnt; i++){
		switch(receipt[i]){
		case '0':
			cout << "can---------------------------------1,200Won\n";
			total += 1200;
			break;
		case '1':
			cout << "ramen-------------------------------1,000Won\n";
			total += 1000;			
			break;
 		case '2':
			cout << "cigarette---------------------------4,500Won\n";
			total += 4500;
			break;
		case '3':
			cout << "instant rice------------------------1,500Won\n";
			total += 1500;
			break;
		case '4':
			cout << "wet tissue--------------------------2,000Won\n";
			total += 2000;
			break;
		default:
			break;
		}
	}
	cout << "\nTotal-------------------------------" << total << "Won\n";
	cout << "\n\n=============================================\n\n\n";
	return 0;
}