| 90 | } |
| 91 | |
| 92 | static 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. |
no test coverage detected