MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CreateFunctionsFromTextProto

Function CreateFunctionsFromTextProto

tensorflow/c/c_api_experimental.cc:178–211  ·  view source on GitHub ↗

On success, returns a set of TF_Function instances from `text_proto` of GraphDef type. These functions must be deleted by calling TF_DeleteFunction. If `mutate_proto_func` is non-NULL, run it over each FunctionDef proto, before creating a TF_Function out of the possibly mutated proto.

Source from the content-addressed store, hash-verified

176// If `mutate_proto_func` is non-NULL, run it over each FunctionDef proto,
177// before creating a TF_Function out of the possibly mutated proto.
178static std::vector<UniqueFuncPtr> CreateFunctionsFromTextProto(
179 const char* text_proto,
180 std::function<void(FunctionDef*)>* mutate_proto_func, TF_Status* status) {
181 tensorflow::GraphDef gdef;
182 if (!tensorflow::protobuf::TextFormat::ParseFromString(text_proto, &gdef)) {
183 status->status = tensorflow::errors::Internal(
184 "Invalid text proto for GraphDef: ", text_proto);
185 return {};
186 }
187 const auto& fdef_lib = gdef.library();
188 if (fdef_lib.gradient_size() > 0) {
189 status->status = tensorflow::errors::Internal(
190 "GradientDef is not supported in reading Dataset related functions: ",
191 text_proto);
192 return {};
193 }
194 std::vector<UniqueFuncPtr> ret;
195 for (const FunctionDef& fdef : fdef_lib.function()) {
196 // Make a copy so that we can mutate it.
197 FunctionDef fdef_to_load = fdef;
198 if (mutate_proto_func) {
199 (*mutate_proto_func)(&fdef_to_load);
200 }
201 VLOG(1) << "Adding func to graph: " << fdef_to_load.DebugString();
202 std::vector<char> binary_proto_buf(fdef_to_load.ByteSizeLong());
203 fdef_to_load.SerializeToArray(binary_proto_buf.data(),
204 binary_proto_buf.size());
205 TF_Function* func = TF_FunctionImportFunctionDef(
206 binary_proto_buf.data(), binary_proto_buf.size(), status);
207 if (!status->status.ok()) return {};
208 ret.push_back(UniqueFuncPtr(func, TF_DeleteFunction));
209 }
210 return ret;
211}
212
213TF_Tensor* TF_DequeueNamedTensor(TF_Session* session, int tensor_id,
214 TF_Status* status) {

Callers

nothing calls this directly

Calls 9

InternalFunction · 0.85
libraryMethod · 0.45
functionMethod · 0.45
DebugStringMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
okMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected