Skip to content

Commit

Permalink
Integration with redesigned preprocessing & applications modules. (ke…
Browse files Browse the repository at this point in the history
…ras-team#10952)

* Update preprocessing/applications integration

* Fix mobilenet_v2 filename.

* Applications / preprocessing fixes.

* Fix applications imports
  • Loading branch information
fchollet authored Aug 22, 2018
1 parent 23c40e6 commit 6d30ab7
Show file tree
Hide file tree
Showing 16 changed files with 738 additions and 61 deletions.
28 changes: 21 additions & 7 deletions keras/applications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
from __future__ import print_function

from .. import backend
from .. import engine
from .. import layers
from .. import models
from .. import utils

import keras_applications

keras_applications.set_keras_submodules(
backend=backend,
layers=layers,
models=models,
utils=utils)
if not hasattr(keras_applications, 'get_submodules_from_kwargs'):
keras_applications.set_keras_submodules(
backend=backend,
layers=layers,
models=models,
utils=utils)


def keras_modules_injection(base_fun):

def wrapper(*args, **kwargs):
if hasattr(keras_applications, 'get_submodules_from_kwargs'):
kwargs['backend'] = backend
kwargs['layers'] = layers
kwargs['models'] = models
kwargs['utils'] = utils
return base_fun(*args, **kwargs)

return wrapper


from .vgg16 import VGG16
from .vgg19 import VGG19
Expand All @@ -23,6 +37,6 @@
from .inception_resnet_v2 import InceptionResNetV2
from .xception import Xception
from .mobilenet import MobileNet
from .mobilenetv2 import MobileNetV2
from .mobilenet_v2 import MobileNetV2
from .densenet import DenseNet121, DenseNet169, DenseNet201
from .nasnet import NASNetMobile, NASNetLarge
30 changes: 25 additions & 5 deletions keras/applications/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@
from __future__ import print_function

from keras_applications import densenet
from . import keras_modules_injection

DenseNet121 = densenet.DenseNet121
DenseNet169 = densenet.DenseNet169
DenseNet201 = densenet.DenseNet201
decode_predictions = densenet.decode_predictions
preprocess_input = densenet.preprocess_input

@keras_modules_injection
def DenseNet121(*args, **kwargs):
return densenet.DenseNet121(*args, **kwargs)


@keras_modules_injection
def DenseNet169(*args, **kwargs):
return densenet.DenseNet169(*args, **kwargs)


@keras_modules_injection
def DenseNet201(*args, **kwargs):
return densenet.DenseNet201(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return densenet.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return densenet.preprocess_input(*args, **kwargs)
13 changes: 11 additions & 2 deletions keras/applications/imagenet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
from __future__ import print_function

from keras_applications import imagenet_utils
from . import keras_modules_injection

preprocess_input = imagenet_utils.preprocess_input
decode_predictions = imagenet_utils.decode_predictions

@keras_modules_injection
def decode_predictions(*args, **kwargs):
return imagenet_utils.decode_predictions(
*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return imagenet_utils.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/inception_resnet_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import inception_resnet_v2
from . import keras_modules_injection

InceptionResNetV2 = inception_resnet_v2.InceptionResNetV2
decode_predictions = inception_resnet_v2.decode_predictions
preprocess_input = inception_resnet_v2.preprocess_input

@keras_modules_injection
def InceptionResNetV2(*args, **kwargs):
return inception_resnet_v2.InceptionResNetV2(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return inception_resnet_v2.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return inception_resnet_v2.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/inception_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import inception_v3
from . import keras_modules_injection

InceptionV3 = inception_v3.InceptionV3
decode_predictions = inception_v3.decode_predictions
preprocess_input = inception_v3.preprocess_input

@keras_modules_injection
def InceptionV3(*args, **kwargs):
return inception_v3.InceptionV3(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return inception_v3.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return inception_v3.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/mobilenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import mobilenet
from . import keras_modules_injection

MobileNet = mobilenet.MobileNet
decode_predictions = mobilenet.decode_predictions
preprocess_input = mobilenet.preprocess_input

@keras_modules_injection
def MobileNet(*args, **kwargs):
return mobilenet.MobileNet(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return mobilenet.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return mobilenet.preprocess_input(*args, **kwargs)
21 changes: 21 additions & 0 deletions keras/applications/mobilenet_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from keras_applications import mobilenet_v2
from . import keras_modules_injection


@keras_modules_injection
def MobileNetV2(*args, **kwargs):
return mobilenet_v2.MobileNetV2(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return mobilenet_v2.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return mobilenet_v2.preprocess_input(*args, **kwargs)
11 changes: 2 additions & 9 deletions keras/applications/mobilenetv2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from keras_applications import mobilenet_v2

MobileNetV2 = mobilenet_v2.MobileNetV2
decode_predictions = mobilenet_v2.decode_predictions
preprocess_input = mobilenet_v2.preprocess_input
# Only for backwards compatibility.
from .mobilenet_v2 import *
24 changes: 20 additions & 4 deletions keras/applications/nasnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,24 @@
from __future__ import print_function

from keras_applications import nasnet
from . import keras_modules_injection

NASNetMobile = nasnet.NASNetMobile
NASNetLarge = nasnet.NASNetLarge
decode_predictions = nasnet.decode_predictions
preprocess_input = nasnet.preprocess_input

@keras_modules_injection
def NASNetMobile(*args, **kwargs):
return nasnet.NASNetMobile(*args, **kwargs)


@keras_modules_injection
def NASNetLarge(*args, **kwargs):
return nasnet.NASNetLarge(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return nasnet.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return nasnet.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/resnet50.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import resnet50
from . import keras_modules_injection

ResNet50 = resnet50.ResNet50
decode_predictions = resnet50.decode_predictions
preprocess_input = resnet50.preprocess_input

@keras_modules_injection
def ResNet50(*args, **kwargs):
return resnet50.ResNet50(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return resnet50.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return resnet50.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/vgg16.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import vgg16
from . import keras_modules_injection

VGG16 = vgg16.VGG16
decode_predictions = vgg16.decode_predictions
preprocess_input = vgg16.preprocess_input

@keras_modules_injection
def VGG16(*args, **kwargs):
return vgg16.VGG16(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return vgg16.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return vgg16.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/vgg19.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import vgg19
from . import keras_modules_injection

VGG19 = vgg19.VGG19
decode_predictions = vgg19.decode_predictions
preprocess_input = vgg19.preprocess_input

@keras_modules_injection
def VGG19(*args, **kwargs):
return vgg19.VGG19(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return vgg19.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return vgg19.preprocess_input(*args, **kwargs)
18 changes: 15 additions & 3 deletions keras/applications/xception.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from __future__ import print_function

from keras_applications import xception
from . import keras_modules_injection

Xception = xception.Xception
decode_predictions = xception.decode_predictions
preprocess_input = xception.preprocess_input

@keras_modules_injection
def Xception(*args, **kwargs):
return xception.Xception(*args, **kwargs)


@keras_modules_injection
def decode_predictions(*args, **kwargs):
return xception.decode_predictions(*args, **kwargs)


@keras_modules_injection
def preprocess_input(*args, **kwargs):
return xception.preprocess_input(*args, **kwargs)
Loading

0 comments on commit 6d30ab7

Please sign in to comment.