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

Function SaveImage

tensorflow/examples/multibox_detector/main.cc:138–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138Status SaveImage(const Tensor& tensor, const string& file_path) {
139 LOG(INFO) << "Saving image to " << file_path;
140 CHECK(tensorflow::str_util::EndsWith(file_path, ".png"))
141 << "Only saving of png files is supported.";
142
143 auto root = tensorflow::Scope::NewRootScope();
144 using namespace ::tensorflow::ops; // NOLINT(build/namespaces)
145
146 string encoder_name = "encode";
147 string output_name = "file_writer";
148
149 tensorflow::Output image_encoder =
150 EncodePng(root.WithOpName(encoder_name), tensor);
151 tensorflow::ops::WriteFile file_saver = tensorflow::ops::WriteFile(
152 root.WithOpName(output_name), file_path, image_encoder);
153
154 tensorflow::GraphDef graph;
155 TF_RETURN_IF_ERROR(root.ToGraphDef(&graph));
156
157 std::unique_ptr<tensorflow::Session> session(
158 tensorflow::NewSession(tensorflow::SessionOptions()));
159 TF_RETURN_IF_ERROR(session->Create(graph));
160 std::vector<Tensor> outputs;
161 TF_RETURN_IF_ERROR(session->Run({}, {}, {output_name}, &outputs));
162
163 return Status::OK();
164}
165
166// Reads a model graph definition from disk, and creates a session object you
167// can use to run it.

Callers 1

PrintTopDetectionsFunction · 0.85

Calls 9

EndsWithFunction · 0.85
EncodePngFunction · 0.85
WithOpNameMethod · 0.80
WriteFileFunction · 0.50
NewSessionFunction · 0.50
SessionOptionsStruct · 0.50
ToGraphDefMethod · 0.45
CreateMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected