| 129 | } |
| 130 | |
| 131 | void TfDriver::LoadModel(const string& bin_file_path) { |
| 132 | if (!IsValid()) return; |
| 133 | std::ifstream model(bin_file_path); |
| 134 | if (model.fail()) { |
| 135 | Invalidate("Failed to find the model " + bin_file_path); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | tensorflow::GraphDef graphdef; |
| 140 | if (!graphdef.ParseFromIstream(&model)) { |
| 141 | Invalidate("Failed to parse tensorflow graphdef"); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | tensorflow::SessionOptions options; |
| 146 | session_.reset(tensorflow::NewSession(options)); |
| 147 | auto status = session_->Create(graphdef); |
| 148 | if (!status.ok()) { |
| 149 | Invalidate("Failed to create session. " + status.error_message()); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void TfDriver::SetInput(const string& values_as_string, |
| 154 | tensorflow::Tensor* tensor) { |