File size: 1,284 Bytes
b772627
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <armnnDeserializer/IDeserializer.hpp>
#include <armnn/IRuntime.hpp>

#include <cstdint>
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>

int main(int argc, char** argv)
{
    if (argc != 2)
    {
        std::cerr << "usage: " << argv[0] << " MODEL.armnn\n";
        return 2;
    }

    std::ifstream input(argv[1], std::ios::binary);
    if (!input)
    {
        std::cerr << "could not open model\n";
        return 2;
    }

    std::vector<uint8_t> bytes{
        std::istreambuf_iterator<char>(input),
        std::istreambuf_iterator<char>()};

    try
    {
        auto deserializer = armnnDeserializer::IDeserializer::Create();
        auto network = deserializer->CreateNetworkFromBinary(bytes);
        auto runtime = armnn::IRuntime::Create(armnn::IRuntime::CreationOptions());
        auto optimized = armnn::Optimize(*network, {armnn::Compute::CpuRef}, runtime->GetDeviceSpec());
        if (!optimized)
        {
            std::cerr << "optimization failed\n";
            return 1;
        }
        std::cout << "loaded and optimized " << bytes.size() << " bytes\n";
        return 0;
    }
    catch (const std::exception& error)
    {
        std::cerr << "load failed: " << error.what() << "\n";
        return 1;
    }
}