The TensorFlow Frontend (TF FE) is a C++ based OpenVINO Frontend component that is responsible for reading and converting a TensorFlow model to an ov::Model
object
that further can be serialized into the Intermediate Representation (IR) format.
This is an internal API for OpenVINO that is used to implement user-facing API such as OVC tool, Model Conversion API, and OpenVINO Runtime read_model
function
for reading TensorFlow models of the original format in run-time. Also, OpenVINO Model Server uses the frontend for serving models.
Regular users should not use the frontend directly.
The OVC tool and model conversion API now use the TensorFlow Frontend as the default path for conversion to IR.
People from the openvino-tf-frontend-maintainers have the rights to approve and merge PRs to the TensorFlow Frontend component. They can assist with any questions about the component.
The structure of OpenVINO TensorFlow Frontend sources includes the following directories:
Additionally, there is a shared TensorFlow Common directory with same structure and purposes. Its content depend only on common FrontEnd APIs thus is free to use in other FrontEnds.
OpenVINO TensorFlow Frontend uses TensorFlow Protobuf files to read and parse different TensorFlow model formats. The whole workflow can be split into two steps: model loading and conversion.
During loading, the FrontEnd::load()
method creates InputModel
that encapsulates the GraphIterator
object.
GraphIterator
is a reader that iterates through the graph nodes in the topological order.
GraphIterator::get_decoder()
provides a decoder for the current graph node to read its attributes.
Each TensorFlow model format has its implementation of GraphIterator
. Currently, the frontend supports SavedModel, MetaGraph (.meta
), and frozen protobuf (.pb
and .pbtxt
) formats.
The base class GraphIteratorProto
is used for reading and parsing these formats. The architecture of the loading step is shown in the picture below:
After the loading step, InputModel
includes a container of topologically sorted operation Place
objects.
During conversion, each Place
provides a DecoderBase
object to retrieve attributes of the current operation to be transformed into the OpenVINO opset.
Frontend
converts operations in topological order and requires NodeContext
for the current operation node,
which includes Decoder
and OutputVector
inputs from already converted nodes.
The workflow of the conversion step is presented in the diagram below:
OpenVINO TensorFlow Frontend supports extensions. To add an extension, use ov::frontend::tensorflow::Frontend::add_extension()
API.
The next extension types are supported:
ov::frontend::tensorflow::ConversionExtension
or ov::frontend::ConversionExtension
- add new Loader into the conversion pipelineov::TelemetryExtension
- enable telemetry for the frontendov::BaseOpExtension
- enable support of a custom operationov::detail::SOExtension
- allow to support ov::BaseOpExtension
extensions loaded from the external library.TensorFlow conversion into the OpenVINO opset operation requires one pass or two passes:
In most cases, it is sufficient to use just one pass for TensorFlow operation conversion.
Most TensorFlow operations can be converted by one transformation pass using Loader
.
The dictionary of Loaders
is placed in the op_table.cpp file and loaders are in the op directory:
Here is an example of Loader
for TensorFlow Einsum
operation:
In this example, the loader checks the consistency of the operation by using default_op_checks
and retrieves an attribute of the equation by using the NodeContext::get_attribute()
method.
The loader uses OpenVINO Core API for building the OpenVINO sub-graph to replace the TensorFlow operation.
The support of a new TensorFlow operation requires implementing a new Loader
in a separate file in the op directory and registering it into the dictionary of Loaders
.
The main rules for loaders implementation:
Conv2D
must be of rank equal to 4.util.hpp
.In rare cases, TensorFlow operation conversion requires two transformations (Loader
and Internal Transformation
).
In the first step, Loader
must convert a TF operation into Internal Operation that is used temporarily by the conversion pipeline.
The internal operation implementation must also contain the validate_and_infer_types()
method as similar to OpenVINO Core operations.
Here is an example of an implementation for the internal operation SparseSegmentOps
:
In the second step, Internal Transformation
based on ov::pass::MatcherPass
must convert sub-graphs with internal operations into sub-graphs consisting only of the OpenVINO opset.
For more information about ov::pass::MatcherPass
based transformations and their development, read Overview of Transformations API
and OpenVINO Matcher Pass documentation.
The internal transformation must be called in the ov::frontend::tensorflow::FrontEnd::normalize()
method.
It is important to check the order of applying internal transformations to avoid situations when some internal operation
breaks a graph pattern with an internal operation for another internal transformation.
There are two types of tests for the TensorFlow Frontend (TF FE): layer tests and unit tests.
The layer tests are used to validate support of TensorFlow operation by the frontend.
The unit tests cover TensorFlow format reading functionality, conversion pipeline, and internal transformations for Transpose Sinking and conversion of sub-graphs with TF FE internal operations into the OpenVINO opset.
For operation conversion that requires just Loader
, implement layers tests:
In case of two transformation passes using Loader
and Internal Transformation
, implement them in addition to the layer tests:
For building the TF FE unit tests, use the CMake target ov_tensorflow_frontend_tests
. CMake automatically runs
generation scripts to create TensorFlow models used in the testing.
Once the build is complete, launch the ov_tensorflow_frontend_tests
(ov_tensorflow_frontend_tests.exe
for Windows)
executable file to run all tests for the TensorFlow Frontend. The unit tests use the GoogleTest framework for execution.
To get a tests coverage report for the TensorFlow Frontend, read the page on measuring coverage.
The layer tests are Python-based and check that a TensorFlow operation is supported by TF FE. The testing pipeline of the layer tests consists of four steps:
The layer tests include two suites for TensorFlow 1 and TensorFlow 2 Keras operation set support.
To set up environment for running the layer tests, follow these instructions.
To test the whole suite of the TensorFlow 1 operation set support, run the following command:
py.test tensorflow_tests
The command line for one operation:
py.test tensorflow_tests/test_tf_Unique.py
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。