/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #ifndef TENSORFLOW_LITE_TOOLS_MODEL_LOADER_H_ #define TENSORFLOW_LITE_TOOLS_MODEL_LOADER_H_ #ifndef _WIN32 #include <unistd.h> #endif // !_WIN32 #include <cstddef> #include <cstdlib> #include <memory> #include <string> #include <vector> #include "absl/strings/string_view.h" #include "tensorflow/lite/core/model_builder.h" namespace tflite { namespace tools { // Class to load the Model. class ModelLoader { … }; // Load the Model from a file path. class PathModelLoader : public ModelLoader { … }; // Load the Model from buffer. The buffer is owned by the caller. class BufferModelLoader : public ModelLoader { … }; #ifndef _WIN32 // Load the Model from a file descriptor. This class is not available on // Windows. class MmapModelLoader : public ModelLoader { … }; // Load the Model from a pipe file descriptor. // IMPORTANT: This class tries to read the model from a pipe file descriptor, // and the caller needs to ensure that this pipe should be read from in a // different process / thread than written to. It may block when running in the // same process / thread. class PipeModelLoader : public ModelLoader { … }; #endif // !_WIN32 // Create the model loader from a string path. Path can be one of the following: // 1) File descriptor path: path must be in the format of // "fd:%model_fd%:%model_offset%:%model_size%". Returns null if path cannot be // parsed. // 2) Pipe descriptor path: path must be in the format of // "pipe:%read_pipe%:%write_pipe%:%model_size%". This function also closes the // write_pipe when write_pipe >= 0, so it should be called at the read thread / // process. Returns null if path cannot be parsed. // 3) File path: Always return a PathModelLoader. // 4) Buffer path: path must be in the format of // "buffer:%buffer_handle%:%buffer_size%". This model loader does not own the // buffer_handle, and the caller needs to ensure the buffer_handle out-lives the // model loader. std::unique_ptr<ModelLoader> CreateModelLoaderFromPath(const std::string& path); } // namespace tools } // namespace tflite #endif // TENSORFLOW_LITE_TOOLS_MODEL_LOADER_H_