104 std::ifstream f(file, std::ios::binary);
105 if (f.fail() || !f.is_open())
110 f.seekg(0, std::ios::end);
111 const auto fsize = f.tellg();
112 f.seekg(0, std::ios::beg);
120 char* data =
static_cast<char*
>(std::malloc(fsize));
124 TF_Buffer* buf = TF_NewBuffer();
134 if (graphPath ==
nullptr)
140 if (buffer ==
nullptr)
145 TF_Graph* graph = TF_NewGraph();
146 TF_Status* status = TF_NewStatus();
147 TF_ImportGraphDefOptions* opts = TF_NewImportGraphDefOptions();
149 TF_GraphImportGraphDef(graph, buffer, opts, status);
150 TF_DeleteImportGraphDefOptions(opts);
151 TF_DeleteBuffer(buffer);
153 if (TF_GetCode(status) != TF_OK)
155 TF_DeleteGraph(graph);
159 TF_DeleteStatus(status);
173 TF_Status* status = TF_NewStatus();
174 TF_CloseSession(session, status);
175 if (TF_GetCode(status) != TF_OK)
177 TF_CloseSession(session, status);
179 TF_DeleteSession(session, status);
180 if (TF_GetCode(status) != TF_OK)
182 TF_DeleteSession(session, status);
184 TF_DeleteStatus(status);
256 const std::int64_t* dims,
257 std::size_t num_dims,
266 TF_Tensor* tensor = TF_AllocateTensor(data_type, dims,
static_cast<int>(num_dims), len);
267 if (tensor ==
nullptr)
272 void* tensor_data = TF_TensorData(tensor);
273 if (tensor_data ==
nullptr)
275 TF_DeleteTensor(tensor);
281 std::memcpy(tensor_data, data, std::min(len, TF_TensorByteSize(tensor)));
301 if (tensor !=
nullptr)
303 TF_DeleteTensor(tensor);
435 #if defined(_MSC_VER)