| 39 | } |
| 40 | |
| 41 | auto GetModel(css &daqName, const bool allow_fp16, |
| 42 | const int compile_preference) { |
| 43 | std::unique_ptr<Model> model; |
| 44 | ModelBuilder builder; |
| 45 | if (hasEnding(daqName, ".daq")) { |
| 46 | DaqReader daq_reader; |
| 47 | // Set the last argument to true to use mmap. It may be more efficient |
| 48 | // than memory buffer. |
| 49 | daq_reader.ReadDaq(daqName, builder, false); |
| 50 | #ifdef DNN_READ_ONNX |
| 51 | } else if (hasEnding(daqName, ".onnx")) { |
| 52 | OnnxReader onnx_reader; |
| 53 | // Set the last argument to true to use mmap. It may be more efficient |
| 54 | // than memory buffer. |
| 55 | onnx_reader.ReadOnnx(daqName, builder); |
| 56 | #endif |
| 57 | } else { |
| 58 | throw std::invalid_argument( |
| 59 | "Wrong model name " + daqName + |
| 60 | ". It must end with .daq or .onnx (.onnx is only " |
| 61 | "supported when DNN_READ_ONNX is ON)"); |
| 62 | } |
| 63 | model = builder.AllowFp16(allow_fp16).Compile(compile_preference); |
| 64 | return model; |
| 65 | } |
| 66 | |
| 67 | auto PrefCodeToStr(const int &preference_code) { |
| 68 | if (preference_code == ANEURALNETWORKS_PREFER_FAST_SINGLE_ANSWER) { |