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

Function ReadEntireFile

tensorflow/examples/label_image/main.cc:92–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static Status ReadEntireFile(tensorflow::Env* env, const string& filename,
93 Tensor* output) {
94 tensorflow::uint64 file_size = 0;
95 TF_RETURN_IF_ERROR(env->GetFileSize(filename, &file_size));
96
97 string contents;
98 contents.resize(file_size);
99
100 std::unique_ptr<tensorflow::RandomAccessFile> file;
101 TF_RETURN_IF_ERROR(env->NewRandomAccessFile(filename, &file));
102
103 tensorflow::StringPiece data;
104 TF_RETURN_IF_ERROR(file->Read(0, file_size, &data, &(contents)[0]));
105 if (data.size() != file_size) {
106 return tensorflow::errors::DataLoss("Truncated read of '", filename,
107 "' expected ", file_size, " got ",
108 data.size());
109 }
110 output->scalar<tstring>()() = tstring(data);
111 return Status::OK();
112}
113
114// Given an image file name, read in the data, try to decode it as an image,
115// resize it to the requested size, and then scale the values as desired.

Callers 1

ReadTensorFromImageFileFunction · 0.70

Calls 6

tstringClass · 0.85
GetFileSizeMethod · 0.45
resizeMethod · 0.45
NewRandomAccessFileMethod · 0.45
ReadMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected