-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathmodel_builder_factory.py
65 lines (59 loc) · 2.7 KB
/
model_builder_factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2020 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.
# ==============================================================================
"""Utilities for model builder or input size."""
import efficientnet_builder
from condconv import efficientnet_condconv_builder
from edgetpu import efficientnet_edgetpu_builder
from lite import efficientnet_lite_builder
from tpu import efficientnet_x_builder
def get_model_builder(model_name):
"""Get the model_builder module for a given model name."""
if model_name.startswith('efficientnet-lite'):
return efficientnet_lite_builder
elif model_name.startswith('efficientnet-edgetpu-'):
return efficientnet_edgetpu_builder
elif model_name.startswith('efficientnet-condconv-'):
return efficientnet_condconv_builder
elif model_name.startswith('efficientnet-x-'):
return efficientnet_x_builder
elif model_name.startswith('efficientnet-h-'):
return efficientnet_x_builder
elif model_name.startswith('efficientnet-'):
return efficientnet_builder
else:
raise ValueError(
'Model must be either efficientnet-b* or efficientnet-edgetpu* or'
'efficientnet-condconv*, efficientnet-lite*')
def get_model_input_size(model_name):
"""Get model input size for a given model name."""
if model_name.startswith('efficientnet-lite'):
_, _, image_size, _ = (
efficientnet_lite_builder.efficientnet_lite_params(model_name))
elif model_name.startswith('efficientnet-edgetpu-'):
_, _, image_size, _ = (
efficientnet_edgetpu_builder.efficientnet_edgetpu_params(model_name))
elif model_name.startswith('efficientnet-condconv-'):
_, _, image_size, _, _ = (
efficientnet_condconv_builder.efficientnet_condconv_params(model_name))
elif model_name.startswith('efficientnet-x'):
_, _, image_size, _, _ = efficientnet_x_builder.efficientnet_x_params(
model_name)
elif model_name.startswith('efficientnet'):
_, _, image_size, _ = efficientnet_builder.efficientnet_params(model_name)
else:
raise ValueError(
'Model must be either efficientnet-b* or efficientnet-x-b* or efficientnet-edgetpu* or '
'efficientnet-condconv*, efficientnet-lite*')
return image_size