1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | #ifndef TENSORFLOW_LITE_TOOLS_VERIFIER_H_ |
17 | #define TENSORFLOW_LITE_TOOLS_VERIFIER_H_ |
18 | |
19 | #include <stdio.h> |
20 | |
21 | #include "tensorflow/lite/core/api/error_reporter.h" |
22 | #include "tensorflow/lite/core/api/op_resolver.h" |
23 | #include "tensorflow/lite/error_reporter.h" // Legacy. |
24 | #include "tensorflow/lite/model.h" // Legacy. |
25 | |
26 | namespace tflite { |
27 | |
28 | class AlwaysTrueResolver : public OpResolver { |
29 | public: |
30 | AlwaysTrueResolver() {} |
31 | const TfLiteRegistration* FindOp(tflite::BuiltinOperator op, |
32 | int version) const override { |
33 | static TfLiteRegistration null_registration = {nullptr, nullptr, nullptr, |
34 | nullptr}; |
35 | return &null_registration; |
36 | } |
37 | const TfLiteRegistration* FindOp(const char* op, int version) const override { |
38 | static TfLiteRegistration null_registration = {nullptr, nullptr, nullptr, |
39 | nullptr}; |
40 | return &null_registration; |
41 | } |
42 | }; |
43 | |
44 | // Verifies the integrity of a Tensorflow Lite flatbuffer model file. |
45 | // Currently, it verifies: |
46 | // * The file is following a legit flatbuffer schema. |
47 | // * The model is in supported version. |
48 | // * All ops used in the model are supported by OpResolver. |
49 | // DEPRECATED: |
50 | // This function is deprecated, because it doesn't take delegates into |
51 | // account, and as a result may report errors if the model contains |
52 | // operators that are not supported by the OpResolver but that would be |
53 | // rewritten by any TfLiteDelegate that you are using. |
54 | // Suggested replacement: |
55 | // Use the version below that doesn't takes an OpResolver (and |
56 | // doesn't check the validity of the ops) instead of this function, |
57 | // and delay verification of the ops until after you have constructed |
58 | // the Interpreter. To verify that the operators in the model are supported |
59 | // by the delegate(s) and/or by the OpResolver, construct the Interpreter, |
60 | // applying the TfLiteDelegate(s) using InterpreterBuilder::AddDelegate, |
61 | // and then just check the return value from Interpreter::AllocateTensors(). |
62 | bool Verify(const void* buf, size_t len, const OpResolver& resolver, |
63 | ErrorReporter* error_reporter); |
64 | |
65 | // Verifies the integrity of a Tensorflow Lite flatbuffer model file. |
66 | // Currently, it verifies: |
67 | // * The file is following a legit flatbuffer schema. |
68 | // * The model is in supported version. |
69 | // * Some basic consistency checks on the graph. |
70 | // * Some validity checks on the tensors. |
71 | bool Verify(const void* buf, size_t len, ErrorReporter* error_reporter); |
72 | |
73 | } // namespace tflite |
74 | |
75 | #endif // TENSORFLOW_LITE_TOOLS_VERIFIER_H_ |
76 | |