This is a very simple example which uses the Arm NN SDK API to create a neural network which consists of nothing else but a single fully connected layer with a single weights value. It's as minimalistic as it can get.
- Note
- Most of our users won't use our API to create a network manually. Usually you would use one of our software tools like the TfLite Parser that will translate a TfLite model into Arm NN for you. Still it's a very nice example to see how an Arm NN network is created, optimized and executed.
(You can find more complex examples using the TfLite Parser in samples/ObjectDetection and samples/SpeechRecognition. And another example using PyArmnn in samples/ImageClassification)
#include <iostream>
{
float number;
std::cout << "Please enter a number: " << std::endl;
std::cin >> number;
float weightsData[] = {1.0f};
IConnectableLayer*
const constantWeightsLayer = myNetwork->AddConstantLayer(weights,
"const weights");
IConnectableLayer*
const fullyConnectedLayer = myNetwork->AddFullyConnectedLayer(fullyConnectedDesc,
"fully connected");
if (!optNet)
{
std::cerr << "Error: Failed to optimise the input network." << std::endl;
return 1;
}
run->LoadNetwork(networkIdentifier, std::move(optNet));
std::vector<float> inputData{number};
std::vector<float> outputData(1);
inputTensorInfo = run->GetInputTensorInfo(networkIdentifier, 0);
inputData.data())}};
outputData.data())}};
run->EnqueueWorkload(networkIdentifier, inputTensors, outputTensors);
std::cout << "Your number was " << outputData[0] << std::endl;
return 0;
}