1# Copyright 2016 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"""Keras Applications are canned architectures with pre-trained weights.""" 16# pylint: disable=g-import-not-at-top 17# pylint: disable=g-bad-import-order 18from __future__ import absolute_import 19from __future__ import division 20from __future__ import print_function 21 22import keras_applications 23 24from tensorflow.python.keras import backend 25from tensorflow.python.keras import engine 26from tensorflow.python.keras import layers 27from tensorflow.python.keras import models 28from tensorflow.python.keras import utils 29from tensorflow.python.util import tf_inspect 30 31# `get_submodules_from_kwargs` has been introduced in 1.0.5, but we would 32# like to be able to handle prior versions. Note that prior to 1.0.5, 33# `keras_applications` did not expose a `__version__` attribute. 34if not hasattr(keras_applications, 'get_submodules_from_kwargs'): 35 36 if 'engine' in tf_inspect.getfullargspec( 37 keras_applications.set_keras_submodules)[0]: 38 keras_applications.set_keras_submodules( 39 backend=backend, 40 layers=layers, 41 models=models, 42 utils=utils, 43 engine=engine) 44 else: 45 keras_applications.set_keras_submodules( 46 backend=backend, 47 layers=layers, 48 models=models, 49 utils=utils) 50 51 52def keras_modules_injection(base_fun): 53 """Decorator injecting tf.keras replacements for Keras modules. 54 55 Arguments: 56 base_fun: Application function to decorate (e.g. `MobileNet`). 57 58 Returns: 59 Decorated function that injects keyword argument for the tf.keras 60 modules required by the Applications. 61 """ 62 63 def wrapper(*args, **kwargs): 64 if hasattr(keras_applications, 'get_submodules_from_kwargs'): 65 kwargs['backend'] = backend 66 if 'layers' not in kwargs: 67 kwargs['layers'] = layers 68 kwargs['models'] = models 69 kwargs['utils'] = utils 70 return base_fun(*args, **kwargs) 71 return wrapper 72 73 74from tensorflow.python.keras.applications.densenet import DenseNet121 75from tensorflow.python.keras.applications.densenet import DenseNet169 76from tensorflow.python.keras.applications.densenet import DenseNet201 77from tensorflow.python.keras.applications.inception_resnet_v2 import InceptionResNetV2 78from tensorflow.python.keras.applications.inception_v3 import InceptionV3 79from tensorflow.python.keras.applications.mobilenet import MobileNet 80from tensorflow.python.keras.applications.mobilenet_v2 import MobileNetV2 81from tensorflow.python.keras.applications.nasnet import NASNetLarge 82from tensorflow.python.keras.applications.nasnet import NASNetMobile 83from tensorflow.python.keras.applications.resnet50 import ResNet50 84from tensorflow.python.keras.applications.vgg16 import VGG16 85from tensorflow.python.keras.applications.vgg19 import VGG19 86from tensorflow.python.keras.applications.xception import Xception 87 88del absolute_import 89del division 90del print_function 91