Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 1 | # Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved. |
| 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | # not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 16 | # Description: |
| 17 | # Dispatcher for reading a neural network model. |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 18 | from . import tflite_reader |
| 19 | from .errors import InputFileError |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 20 | |
| 21 | |
| 22 | class ModelReaderOptions: |
| 23 | def __init__(self, batch_size=1): |
| 24 | self.batch_size = batch_size |
| 25 | |
| 26 | def __str__(self): |
| 27 | return type(self).__name__ + ": " + str(self.__dict__) |
| 28 | |
| 29 | __repr__ = __str__ |
| 30 | |
| 31 | |
| 32 | def read_model(fname, options, feed_dict={}, output_node_names=[], initialisation_nodes=[]): |
| 33 | if fname.endswith(".tflite"): |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 34 | return tflite_reader.read_tflite( |
| 35 | fname, |
| 36 | options.batch_size, |
| 37 | feed_dict=feed_dict, |
| 38 | output_node_names=output_node_names, |
| 39 | initialisation_nodes=initialisation_nodes, |
| 40 | ) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 41 | else: |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 42 | raise InputFileError(fname, "Unsupported file extension. Only .tflite files are supported") |