Repository navigation
Expand file tree
/
Copy pathmnn_session.h
More file actions
72 lines (57 loc) · 2.14 KB
/
Copy pathmnn_session.h
File metadata and controls
72 lines (57 loc) · 2.14 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/************************************************
* Copyright MaybeShewill-CV. All Rights Reserved.
* Author: MaybeShewill-CV
* File: mnn_session.h
* Date: 26-8-20
************************************************/
#ifndef MORTRED_MODELS_BACKEND_MNN_SESSION_H
#define MORTRED_MODELS_BACKEND_MNN_SESSION_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "MNN/Interpreter.hpp"
#include "common/status_code.h"
#include "models/backend/backend_config.h"
#include "models/backend/session.h"
namespace mortred {
namespace models {
namespace backend {
using mortred::common::StatusCode;
/***
* RAII MNN inference session. Owns the interpreter and session, caches the
* io tensors by name and re-fetches them after dynamic resizes (MNN may
* reallocate tensor pointers on resizeSession).
*/
class MnnSession : public InferenceSession {
public:
MnnSession() = default;
~MnnSession() override;
MnnSession(const MnnSession&) = delete;
MnnSession& operator=(const MnnSession&) = delete;
/*** build the session; returns non-OK status and fills err on failure */
StatusCode init(const BackendConfig& config, std::string* err = nullptr);
const std::vector<TensorInfo>& inputs() const override {
return _m_input_infos;
}
const std::vector<TensorInfo>& outputs() const override {
return _m_output_infos;
}
StatusCode run(const std::vector<NamedTensor>& inputs,
std::vector<NamedTensor>& outputs) override;
private:
StatusCode refresh_io_tensors();
std::unique_ptr<MNN::Interpreter> _m_interpreter;
MNN::Session* _m_session = nullptr;
std::map<std::string, MNN::Tensor*> _m_input_tensors;
std::map<std::string, MNN::Tensor*> _m_output_tensors;
std::map<std::string, MNN::Tensor::DimensionType> _m_input_dim_types;
std::map<std::string, MNN::Tensor::DimensionType> _m_input_device_dim_types;
std::vector<TensorInfo> _m_input_infos;
std::vector<TensorInfo> _m_output_infos;
std::string _m_model_file_path;
};
} // namespace backend
} // namespace models
} // namespace mortred
#endif // MORTRED_MODELS_BACKEND_MNN_SESSION_H