#include "daal.h"
#include "service.h"
#include "neural_net_predict_dense_batch.h"
using namespace std;
using namespace daal;
using namespace daal::algorithms;
using namespace daal::algorithms::neural_networks;
using namespace daal::services;
string testDatasetFile = "../data/batch/neural_network_test.csv";
string testGroundTruthFile = "../data/batch/neural_network_test_ground_truth.csv";
string fc1WeightsFile = "../data/batch/fc1_weights.csv";
string fc1BiasesFile = "../data/batch/fc1_biases.csv";
string fc2WeightsFile = "../data/batch/fc2_weights.csv";
string fc2BiasesFile = "../data/batch/fc2_biases.csv";
TensorPtr predictionData;
prediction::ModelPtr predictionModel;
prediction::ResultPtr predictionResult;
void createModel();
void testModel();
void printResults();
int main()
{
createModel();
testModel();
printResults();
return 0;
}
void createModel()
{
predictionData = readTensorFromCSV(testDatasetFile);
LayerIds ids;
prediction::TopologyPtr topology = configureNet(&ids);
predictionModel = prediction::Model::create(*topology);
checkPtr(predictionModel.get());
TensorPtr fc1Weights = readTensorFromCSV(fc1WeightsFile);
TensorPtr fc1Biases = readTensorFromCSV(fc1BiasesFile);
forward::Input *fc1Input = predictionModel->getLayer(ids.fc1)->getLayerInput();
fc1Input->set(forward::weights, fc1Weights);
fc1Input->set(forward::biases, fc1Biases);
predictionModel->getLayer(ids.fc1)->getLayerParameter()->weightsAndBiasesInitialized = true;
TensorPtr fc2Weights = readTensorFromCSV(fc2WeightsFile);
TensorPtr fc2Biases = readTensorFromCSV(fc2BiasesFile);
forward::Input *fc2Input = predictionModel->getLayer(ids.fc2)->getLayerInput();
fc2Input->set(forward::weights, fc2Weights);
fc2Input->set(forward::biases, fc2Biases);
predictionModel->getLayer(ids.fc2)->getLayerParameter()->weightsAndBiasesInitialized = true;
}
void testModel()
{
prediction::Batch<> net;
net.parameter.batchSize = predictionData->getDimensionSize(0);
net.input.set(prediction::model, predictionModel);
net.input.set(prediction::data, predictionData);
net.compute();
predictionResult = net.getResult();
}
void printResults()
{
TensorPtr predictionGroundTruth = readTensorFromCSV(testGroundTruthFile);
printTensors<int, float>(predictionGroundTruth, predictionResult->get(prediction::prediction),
"Ground truth", "Neural network predictions: each class probability",
"Neural network classification results (first 20 observations):", 20);
}