keras 2.0.7__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Keras-2.0.7.dist-info/DESCRIPTION.rst +3 -0
- Keras-2.0.7.dist-info/METADATA +26 -0
- Keras-2.0.7.dist-info/RECORD +73 -0
- Keras-2.0.7.dist-info/WHEEL +6 -0
- Keras-2.0.7.dist-info/metadata.json +1 -0
- Keras-2.0.7.dist-info/top_level.txt +1 -0
- keras/__init__.py +23 -0
- keras/activations.py +107 -0
- keras/applications/__init__.py +6 -0
- keras/applications/imagenet_utils.py +163 -0
- keras/applications/inception_v3.py +394 -0
- keras/applications/mobilenet.py +658 -0
- keras/applications/resnet50.py +282 -0
- keras/applications/vgg16.py +190 -0
- keras/applications/vgg19.py +193 -0
- keras/applications/xception.py +267 -0
- keras/backend/__init__.py +101 -0
- keras/backend/cntk_backend.py +2367 -0
- keras/backend/common.py +186 -0
- keras/backend/tensorflow_backend.py +3862 -0
- keras/backend/theano_backend.py +2485 -0
- keras/callbacks.py +1076 -0
- keras/constraints.py +180 -0
- keras/datasets/__init__.py +8 -0
- keras/datasets/boston_housing.py +36 -0
- keras/datasets/cifar.py +33 -0
- keras/datasets/cifar10.py +40 -0
- keras/datasets/cifar100.py +41 -0
- keras/datasets/imdb.py +112 -0
- keras/datasets/mnist.py +20 -0
- keras/datasets/reuters.py +97 -0
- keras/engine/__init__.py +8 -0
- keras/engine/topology.py +3158 -0
- keras/engine/training.py +2313 -0
- keras/initializers.py +498 -0
- keras/layers/__init__.py +54 -0
- keras/layers/advanced_activations.py +210 -0
- keras/layers/convolutional.py +2129 -0
- keras/layers/convolutional_recurrent.py +561 -0
- keras/layers/core.py +899 -0
- keras/layers/embeddings.py +147 -0
- keras/layers/local.py +389 -0
- keras/layers/merge.py +619 -0
- keras/layers/noise.py +160 -0
- keras/layers/normalization.py +209 -0
- keras/layers/pooling.py +684 -0
- keras/layers/recurrent.py +1189 -0
- keras/layers/wrappers.py +375 -0
- keras/legacy/__init__.py +0 -0
- keras/legacy/interfaces.py +660 -0
- keras/legacy/layers.py +759 -0
- keras/legacy/models.py +27 -0
- keras/losses.py +107 -0
- keras/metrics.py +72 -0
- keras/models.py +1523 -0
- keras/objectives.py +6 -0
- keras/optimizers.py +721 -0
- keras/preprocessing/__init__.py +0 -0
- keras/preprocessing/image.py +1060 -0
- keras/preprocessing/sequence.py +214 -0
- keras/preprocessing/text.py +331 -0
- keras/regularizers.py +83 -0
- keras/utils/__init__.py +23 -0
- keras/utils/conv_utils.py +152 -0
- keras/utils/data_utils.py +644 -0
- keras/utils/generic_utils.py +365 -0
- keras/utils/io_utils.py +153 -0
- keras/utils/layer_utils.py +193 -0
- keras/utils/np_utils.py +42 -0
- keras/utils/test_utils.py +161 -0
- keras/utils/vis_utils.py +137 -0
- keras/wrappers/__init__.py +0 -0
- keras/wrappers/scikit_learn.py +334 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.0
|
|
2
|
+
Name: Keras
|
|
3
|
+
Version: 2.0.7
|
|
4
|
+
Summary: Deep Learning for Python
|
|
5
|
+
Home-page: https://github.com/fchollet/keras
|
|
6
|
+
Author: Francois Chollet
|
|
7
|
+
Author-email: francois.chollet@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Download-URL: https://github.com/fchollet/keras/tarball/2.0.7
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Requires-Dist: pyyaml
|
|
12
|
+
Requires-Dist: six
|
|
13
|
+
Requires-Dist: theano
|
|
14
|
+
Provides-Extra: h5py
|
|
15
|
+
Requires-Dist: h5py; extra == 'h5py'
|
|
16
|
+
Provides-Extra: tests
|
|
17
|
+
Requires-Dist: pytest; extra == 'tests'
|
|
18
|
+
Requires-Dist: pytest-cov; extra == 'tests'
|
|
19
|
+
Requires-Dist: pytest-pep8; extra == 'tests'
|
|
20
|
+
Requires-Dist: pytest-xdist; extra == 'tests'
|
|
21
|
+
Provides-Extra: visualize
|
|
22
|
+
Requires-Dist: pydot (>=1.2.0); extra == 'visualize'
|
|
23
|
+
|
|
24
|
+
UNKNOWN
|
|
25
|
+
|
|
26
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Keras-2.0.7.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10
|
|
2
|
+
Keras-2.0.7.dist-info/METADATA,sha256=Pi2uqzoPDL_oMCpAq5eeJ6OC0naNb-9m8JniTiU6fos,695
|
|
3
|
+
Keras-2.0.7.dist-info/RECORD,,
|
|
4
|
+
Keras-2.0.7.dist-info/WHEEL,sha256=o2k-Qa-RMNIJmUdIc7KU6VWR_ErNRbWNlxDIpl7lm34,110
|
|
5
|
+
Keras-2.0.7.dist-info/metadata.json,sha256=65wwql19xs2hM1lI9BkarOgzlgr__-IGxYng-B5fs9A,769
|
|
6
|
+
Keras-2.0.7.dist-info/top_level.txt,sha256=ptcw_-QuGZ4ZDjMdwi_Z0clZm8QAqFdvzzFnDEOTs9o,6
|
|
7
|
+
keras/__init__.py,sha256=_7AVkXzBao-YKBumKRNPqVWZDcKMuZCUMTK_GdkQfBM,576
|
|
8
|
+
keras/activations.py,sha256=gXjkxYHhIgFXGl6GDKnRghroauNeNccLJLjhCacuVFk,2712
|
|
9
|
+
keras/callbacks.py,sha256=xdato5ZUg7nJsvNYRXvt64nJwTmKhp7sXOCAHZGEGow,40798
|
|
10
|
+
keras/constraints.py,sha256=sLD9Xi-nVAnQAf6tS0FRzN_CmRga5nRytAGqJDmK-h4,6052
|
|
11
|
+
keras/initializers.py,sha256=H0q-KlBPL2AEz79dTA9FwhOcgwZMzGtwdO8mu2OFxMU,15758
|
|
12
|
+
keras/losses.py,sha256=wsDYrCWk-Nre01kon_P7XVTMBa0z_Di1upTt8T4lz70,3104
|
|
13
|
+
keras/metrics.py,sha256=v3h67-sjDGHJUIRYxQmN15wSHmuCiKcb94h1BCw-sr4,2294
|
|
14
|
+
keras/models.py,sha256=qGtZFxxTay_tKjkpiONRyLZ_QLpxtp24x1MVD3GXHT4,61802
|
|
15
|
+
keras/objectives.py,sha256=ck4Iw_cAo6AbKrOPBLBLFnSiVmICvhAbm9Ax-FTyBPM,138
|
|
16
|
+
keras/optimizers.py,sha256=lmyrb3IFYMG1FGFvix22MLEqrKYN97X7XIgFJ7zAiTM,26506
|
|
17
|
+
keras/regularizers.py,sha256=TJ3qrfNsXBkVhIStDESz2jf4WtkJxHBBsQSqGemrHno,2034
|
|
18
|
+
keras/applications/__init__.py,sha256=kQN0OWyEUtaX7_6I5TMXJQQ6V4J6zcHE26Fh8_GU_oo,183
|
|
19
|
+
keras/applications/imagenet_utils.py,sha256=-H_9EFCYsXBnCEL3_A9K5tu3WlmtixFwSED8HCWcD3o,6717
|
|
20
|
+
keras/applications/inception_v3.py,sha256=j9DmiRX9QfwGVE6zHLz4GxIEfBq-e7HRMMSMlRyCADs,14482
|
|
21
|
+
keras/applications/mobilenet.py,sha256=GVUq5JMdIRofCLUec2Q1x0q3h-xOjt6N-SzhPdpxi3U,28721
|
|
22
|
+
keras/applications/resnet50.py,sha256=8mcO0XtLmQql3yMz6gSupf0zqaKgnefkeX2hY6et8cc,11536
|
|
23
|
+
keras/applications/vgg16.py,sha256=CPXZuZDqfnmgZSuT1V9eTMib30UxBzowqnzNkVwSn6A,8283
|
|
24
|
+
keras/applications/vgg19.py,sha256=CnE1V7DfGRt2XiTdy4avObwN8tSLa3dxBAfHY-mQKbc,8545
|
|
25
|
+
keras/applications/xception.py,sha256=H4S-FeYHB8SN2O_KGCsbqtEN0geqVxXlE6r40t3WGAk,11648
|
|
26
|
+
keras/backend/__init__.py,sha256=Kc-HhAdI07dwtbnwd-pnRWxe5LeaTV918yojzwhCykA,3021
|
|
27
|
+
keras/backend/cntk_backend.py,sha256=y1zNCYUr96MJ1aQuCVaaDMsemPJPL7fAyhazKSup3xM,73514
|
|
28
|
+
keras/backend/common.py,sha256=BzUeIRWYMWgpr0dzZbrCYlaa56tD0Vk56UYb08inwRA,4186
|
|
29
|
+
keras/backend/tensorflow_backend.py,sha256=ENsG69409PxDp8MRz0ZHsW57EPp4gLvglltomsGAXlU,118423
|
|
30
|
+
keras/backend/theano_backend.py,sha256=4KWZRC0c80iqZLUQkH-5c9JTNKrr3TWov-E1sCy8Nos,83014
|
|
31
|
+
keras/datasets/__init__.py,sha256=EA5f1F0kJBqz951bPbalwtwZ7CNhdfq8v5208fe1QvQ,175
|
|
32
|
+
keras/datasets/boston_housing.py,sha256=lYkA8rz25DWC6c9RsJMBhx7HkOBcaX_Taud35_CLkoo,1233
|
|
33
|
+
keras/datasets/cifar.py,sha256=3dp4Zzqo5fYcJpJfaFkhiiXJY9LZXnYo3xw7wETFCJA,808
|
|
34
|
+
keras/datasets/cifar10.py,sha256=3MKfEMxebmxys9NGYzfuahNB21DVgTITLYnNBxEABLo,1255
|
|
35
|
+
keras/datasets/cifar100.py,sha256=E1unk-7fJPklNNahzmRV9hjHI__J7mkSozIoZbsUSzc,1266
|
|
36
|
+
keras/datasets/imdb.py,sha256=HD_V88sOyFDMvhrtiLZPOrVRyn16Ve55ZQ_0TSom7to,4135
|
|
37
|
+
keras/datasets/mnist.py,sha256=HhRZcfrUXfkGE_lM4S1bJWcj0ja9xU9mfseDY2tdRwU,600
|
|
38
|
+
keras/datasets/reuters.py,sha256=wknExVedz539iy_31fyQckGUxNgGwwywNkMkBMGWQJE,3636
|
|
39
|
+
keras/engine/__init__.py,sha256=ukuX6twIBAmKspaMcKH_MiKxbpfZNFOMu9Z7VyeeY_Q,277
|
|
40
|
+
keras/engine/topology.py,sha256=FIDmUISDkp4n7va7fhi-1Va1WShx4Y0L0kyf87pByoM,130852
|
|
41
|
+
keras/engine/training.py,sha256=TEwCfhfn7pC2FQEWMz81QWLsNN1xeLoUCxZAGVzrJxE,105038
|
|
42
|
+
keras/layers/__init__.py,sha256=T3cbyoQpr-AG_v4xlbOZAf8Y3PD74qRkj_-4tatLvbc,1584
|
|
43
|
+
keras/layers/advanced_activations.py,sha256=qM_f4tFRhbnN8S8MSamHqdrqBJqk0y4EVuzJZYW4rww,7298
|
|
44
|
+
keras/layers/convolutional.py,sha256=FPVfVdU--6VCyLhr7c0buskVoZib-5EQb6SeMemo8_8,95511
|
|
45
|
+
keras/layers/convolutional_recurrent.py,sha256=Xx2o6GMaTY0PiXhUzCywScf4XKWf2glZ6QwgN22TEj4,26593
|
|
46
|
+
keras/layers/core.py,sha256=bNjkdRD4dRZ5i3iaDcEpnWxqQqsRdIhwkLPAzt-zH2E,34464
|
|
47
|
+
keras/layers/embeddings.py,sha256=psXKBBRX4oN0LFzYLbhfjZbz-QFgFb7wbuq9j7CN4EA,6326
|
|
48
|
+
keras/layers/local.py,sha256=t18lMZvnPTPEC8RW9Q5jQPiBceHG-VpNuwi6pbIfp9w,18505
|
|
49
|
+
keras/layers/merge.py,sha256=XqwDJB9pcE26gd_Bk9Re4JcUQOmoJ38GlR6jCPLy3k0,22499
|
|
50
|
+
keras/layers/noise.py,sha256=BiLk8l4sOx9FjfkH5yRyKnoQrDA4M-oL6jam7s79-1c,5754
|
|
51
|
+
keras/layers/normalization.py,sha256=ZGdl2JJoT3Vxi93Fr9grQiTMHHWtW-OQRvpVuDAfm7g,9276
|
|
52
|
+
keras/layers/pooling.py,sha256=GW4kp1CFNcdDOsXQrN-x505-hdODw3HIkgu_fJIa9Es,26982
|
|
53
|
+
keras/layers/recurrent.py,sha256=GBaXOfbzO5HW-onltRAxknoEYBBIkkUuVs-5Z1rZ9eo,55692
|
|
54
|
+
keras/layers/wrappers.py,sha256=oFIm6qCqgm9SEBhUfrnFusFkpzj2rr47-9zEplMDEbo,13573
|
|
55
|
+
keras/legacy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
56
|
+
keras/legacy/interfaces.py,sha256=k2YUTavlxNmsOaeEivvODpRc3nXc3ZydPslRzKPu09w,29587
|
|
57
|
+
keras/legacy/layers.py,sha256=ie07tXYNKTkeS0dK9pPCnKLXt1kvSEbAtZ0YiwyuHEE,33390
|
|
58
|
+
keras/legacy/models.py,sha256=JBm_38VF9DpuPJF42pkN4nR4hcPoh5P2avRJjI_Dx1s,851
|
|
59
|
+
keras/preprocessing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
60
|
+
keras/preprocessing/image.py,sha256=McepOjOb-ZEHmNCamijadUtPDiDGwBPUD_TZiLNdH8k,43847
|
|
61
|
+
keras/preprocessing/sequence.py,sha256=shdznnhkQvO5OCOtydDmLRzMKXV6mbvg9NNY-GUmZrs,7852
|
|
62
|
+
keras/preprocessing/text.py,sha256=EuGmGUVQw1wIGeRNBhiafu0PuxPsDhfuVU94YkSSGWc,12002
|
|
63
|
+
keras/utils/__init__.py,sha256=LRmFHthw8-soPm9R5IZizcBNtTY_WnkbYdKX4eFNe4o,806
|
|
64
|
+
keras/utils/conv_utils.py,sha256=uEGWaiXRQaEg3X9NDfZTqogw0s-aipgtLq0rd4xh67Q,5142
|
|
65
|
+
keras/utils/data_utils.py,sha256=e_0foSe82Igx_m3eJIq2cMRVrEPdr-3_oD2lOPf2oMM,21459
|
|
66
|
+
keras/utils/generic_utils.py,sha256=1XQlvCMW3SoHwayxx4PmbeH_4NmP63-0apAVird2QUo,12909
|
|
67
|
+
keras/utils/io_utils.py,sha256=Cu6b4y0ivAYqRDGwm4xBnIXyfb_CMcaCuZdUMhhyCKQ,4512
|
|
68
|
+
keras/utils/layer_utils.py,sha256=3K7kSCobBdRqOtLq4oI7YqswDNJDrwaXSwYasDV-N6I,7512
|
|
69
|
+
keras/utils/np_utils.py,sha256=6V1sFhCo-qby9bJuVkhF9cjvV-Xk751HWmp65hREG9k,1117
|
|
70
|
+
keras/utils/test_utils.py,sha256=yoxoJwnLjkvWRySZiWgTDTwKS2pxvqF5WAr0PPwOdpk,5793
|
|
71
|
+
keras/utils/vis_utils.py,sha256=O7yKn_90nlolkRxuD6UpOIrPq0eYUo9ySNdodNky1sY,4754
|
|
72
|
+
keras/wrappers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
73
|
+
keras/wrappers/scikit_learn.py,sha256=u30c2SWJSivFpltpfaGKm2G52YWTyu7tFGe4YqkF718,12734
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"download_url": "https://github.com/fchollet/keras/tarball/2.0.7", "extensions": {"python.details": {"contacts": [{"email": "francois.chollet@gmail.com", "name": "Francois Chollet", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/fchollet/keras"}}}, "extras": ["h5py", "tests", "visualize"], "generator": "bdist_wheel (0.29.0)", "license": "MIT", "metadata_version": "2.0", "name": "Keras", "run_requires": [{"extra": "h5py", "requires": ["h5py"]}, {"extra": "visualize", "requires": ["pydot (>=1.2.0)"]}, {"extra": "tests", "requires": ["pytest-cov", "pytest-pep8", "pytest-xdist", "pytest"]}, {"requires": ["pyyaml", "six", "theano"]}], "summary": "Deep Learning for Python", "version": "2.0.7"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
keras
|
keras/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
|
|
3
|
+
from . import utils
|
|
4
|
+
from . import activations
|
|
5
|
+
from . import applications
|
|
6
|
+
from . import backend
|
|
7
|
+
from . import datasets
|
|
8
|
+
from . import engine
|
|
9
|
+
from . import layers
|
|
10
|
+
from . import preprocessing
|
|
11
|
+
from . import wrappers
|
|
12
|
+
from . import callbacks
|
|
13
|
+
from . import constraints
|
|
14
|
+
from . import initializers
|
|
15
|
+
from . import metrics
|
|
16
|
+
from . import models
|
|
17
|
+
from . import losses
|
|
18
|
+
from . import optimizers
|
|
19
|
+
from . import regularizers
|
|
20
|
+
# Importable from root because it's technically not a layer
|
|
21
|
+
from .layers import Input
|
|
22
|
+
|
|
23
|
+
__version__ = '2.0.7'
|
keras/activations.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
import six
|
|
3
|
+
import warnings
|
|
4
|
+
from . import backend as K
|
|
5
|
+
from .utils.generic_utils import deserialize_keras_object
|
|
6
|
+
from .engine import Layer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def softmax(x, axis=-1):
|
|
10
|
+
"""Softmax activation function.
|
|
11
|
+
|
|
12
|
+
# Arguments
|
|
13
|
+
x : Tensor.
|
|
14
|
+
axis: Integer, axis along which the softmax normalization is applied.
|
|
15
|
+
|
|
16
|
+
# Returns
|
|
17
|
+
Tensor, output of softmax transformation.
|
|
18
|
+
|
|
19
|
+
# Raises
|
|
20
|
+
ValueError: In case `dim(x) == 1`.
|
|
21
|
+
"""
|
|
22
|
+
ndim = K.ndim(x)
|
|
23
|
+
if ndim == 2:
|
|
24
|
+
return K.softmax(x)
|
|
25
|
+
elif ndim > 2:
|
|
26
|
+
e = K.exp(x - K.max(x, axis=axis, keepdims=True))
|
|
27
|
+
s = K.sum(e, axis=axis, keepdims=True)
|
|
28
|
+
return e / s
|
|
29
|
+
else:
|
|
30
|
+
raise ValueError('Cannot apply softmax to a tensor that is 1D')
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def elu(x, alpha=1.0):
|
|
34
|
+
return K.elu(x, alpha)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def selu(x):
|
|
38
|
+
"""Scaled Exponential Linear Unit. (Klambauer et al., 2017)
|
|
39
|
+
|
|
40
|
+
# Arguments
|
|
41
|
+
x: A tensor or variable to compute the activation function for.
|
|
42
|
+
|
|
43
|
+
# References
|
|
44
|
+
- [Self-Normalizing Neural Networks](https://arxiv.org/abs/1706.02515)
|
|
45
|
+
"""
|
|
46
|
+
alpha = 1.6732632423543772848170429916717
|
|
47
|
+
scale = 1.0507009873554804934193349852946
|
|
48
|
+
return scale * K.elu(x, alpha)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def softplus(x):
|
|
52
|
+
return K.softplus(x)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def softsign(x):
|
|
56
|
+
return K.softsign(x)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def relu(x, alpha=0., max_value=None):
|
|
60
|
+
return K.relu(x, alpha=alpha, max_value=max_value)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def tanh(x):
|
|
64
|
+
return K.tanh(x)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def sigmoid(x):
|
|
68
|
+
return K.sigmoid(x)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def hard_sigmoid(x):
|
|
72
|
+
return K.hard_sigmoid(x)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def linear(x):
|
|
76
|
+
return x
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def serialize(activation):
|
|
80
|
+
return activation.__name__
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def deserialize(name, custom_objects=None):
|
|
84
|
+
return deserialize_keras_object(name,
|
|
85
|
+
module_objects=globals(),
|
|
86
|
+
custom_objects=custom_objects,
|
|
87
|
+
printable_module_name='activation function')
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def get(identifier):
|
|
91
|
+
if identifier is None:
|
|
92
|
+
return linear
|
|
93
|
+
if isinstance(identifier, six.string_types):
|
|
94
|
+
identifier = str(identifier)
|
|
95
|
+
return deserialize(identifier)
|
|
96
|
+
elif callable(identifier):
|
|
97
|
+
if isinstance(identifier, Layer):
|
|
98
|
+
warnings.warn((
|
|
99
|
+
'Do not pass a layer instance (such as {identifier}) as the '
|
|
100
|
+
'activation argument of another layer. Instead, advanced '
|
|
101
|
+
'activation layers should be used just like any other '
|
|
102
|
+
'layer in a model.'
|
|
103
|
+
).format(identifier=identifier.__class__.__name__))
|
|
104
|
+
return identifier
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError('Could not interpret '
|
|
107
|
+
'activation function identifier:', identifier)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
from ..utils.data_utils import get_file
|
|
5
|
+
from .. import backend as K
|
|
6
|
+
|
|
7
|
+
CLASS_INDEX = None
|
|
8
|
+
CLASS_INDEX_PATH = 'https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def preprocess_input(x, data_format=None):
|
|
12
|
+
"""Preprocesses a tensor encoding a batch of images.
|
|
13
|
+
|
|
14
|
+
# Arguments
|
|
15
|
+
x: input Numpy tensor, 4D.
|
|
16
|
+
data_format: data format of the image tensor.
|
|
17
|
+
|
|
18
|
+
# Returns
|
|
19
|
+
Preprocessed tensor.
|
|
20
|
+
"""
|
|
21
|
+
if data_format is None:
|
|
22
|
+
data_format = K.image_data_format()
|
|
23
|
+
assert data_format in {'channels_last', 'channels_first'}
|
|
24
|
+
|
|
25
|
+
if data_format == 'channels_first':
|
|
26
|
+
if x.ndim == 3:
|
|
27
|
+
# 'RGB'->'BGR'
|
|
28
|
+
x = x[::-1, ...]
|
|
29
|
+
# Zero-center by mean pixel
|
|
30
|
+
x[0, :, :] -= 103.939
|
|
31
|
+
x[1, :, :] -= 116.779
|
|
32
|
+
x[2, :, :] -= 123.68
|
|
33
|
+
else:
|
|
34
|
+
x = x[:, ::-1, ...]
|
|
35
|
+
x[:, 0, :, :] -= 103.939
|
|
36
|
+
x[:, 1, :, :] -= 116.779
|
|
37
|
+
x[:, 2, :, :] -= 123.68
|
|
38
|
+
else:
|
|
39
|
+
# 'RGB'->'BGR'
|
|
40
|
+
x = x[..., ::-1]
|
|
41
|
+
# Zero-center by mean pixel
|
|
42
|
+
x[..., 0] -= 103.939
|
|
43
|
+
x[..., 1] -= 116.779
|
|
44
|
+
x[..., 2] -= 123.68
|
|
45
|
+
return x
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def decode_predictions(preds, top=5):
|
|
49
|
+
"""Decodes the prediction of an ImageNet model.
|
|
50
|
+
|
|
51
|
+
# Arguments
|
|
52
|
+
preds: Numpy tensor encoding a batch of predictions.
|
|
53
|
+
top: integer, how many top-guesses to return.
|
|
54
|
+
|
|
55
|
+
# Returns
|
|
56
|
+
A list of lists of top class prediction tuples
|
|
57
|
+
`(class_name, class_description, score)`.
|
|
58
|
+
One list of tuples per sample in batch input.
|
|
59
|
+
|
|
60
|
+
# Raises
|
|
61
|
+
ValueError: in case of invalid shape of the `pred` array
|
|
62
|
+
(must be 2D).
|
|
63
|
+
"""
|
|
64
|
+
global CLASS_INDEX
|
|
65
|
+
if len(preds.shape) != 2 or preds.shape[1] != 1000:
|
|
66
|
+
raise ValueError('`decode_predictions` expects '
|
|
67
|
+
'a batch of predictions '
|
|
68
|
+
'(i.e. a 2D array of shape (samples, 1000)). '
|
|
69
|
+
'Found array with shape: ' + str(preds.shape))
|
|
70
|
+
if CLASS_INDEX is None:
|
|
71
|
+
fpath = get_file('imagenet_class_index.json',
|
|
72
|
+
CLASS_INDEX_PATH,
|
|
73
|
+
cache_subdir='models')
|
|
74
|
+
CLASS_INDEX = json.load(open(fpath))
|
|
75
|
+
results = []
|
|
76
|
+
for pred in preds:
|
|
77
|
+
top_indices = pred.argsort()[-top:][::-1]
|
|
78
|
+
result = [tuple(CLASS_INDEX[str(i)]) + (pred[i],) for i in top_indices]
|
|
79
|
+
result.sort(key=lambda x: x[2], reverse=True)
|
|
80
|
+
results.append(result)
|
|
81
|
+
return results
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _obtain_input_shape(input_shape,
|
|
85
|
+
default_size,
|
|
86
|
+
min_size,
|
|
87
|
+
data_format,
|
|
88
|
+
include_top,
|
|
89
|
+
weights='imagenet'):
|
|
90
|
+
"""Internal utility to compute/validate an ImageNet model's input shape.
|
|
91
|
+
|
|
92
|
+
# Arguments
|
|
93
|
+
input_shape: either None (will return the default network input shape),
|
|
94
|
+
or a user-provided shape to be validated.
|
|
95
|
+
default_size: default input width/height for the model.
|
|
96
|
+
min_size: minimum input width/height accepted by the model.
|
|
97
|
+
data_format: image data format to use.
|
|
98
|
+
include_top: whether the model is expected to
|
|
99
|
+
be linked to a classifier via a Flatten layer.
|
|
100
|
+
weights: one of `None` (random initialization)
|
|
101
|
+
or 'imagenet' (pre-training on ImageNet).
|
|
102
|
+
If weights='imagenet' input channels must be equal to 3.
|
|
103
|
+
|
|
104
|
+
# Returns
|
|
105
|
+
An integer shape tuple (may include None entries).
|
|
106
|
+
|
|
107
|
+
# Raises
|
|
108
|
+
ValueError: in case of invalid argument values.
|
|
109
|
+
"""
|
|
110
|
+
if weights != 'imagenet' and input_shape is not None and len(input_shape) == 3:
|
|
111
|
+
if data_format == 'channels_first':
|
|
112
|
+
if input_shape[0] != 3 and input_shape[0] != 1:
|
|
113
|
+
warnings.warn(
|
|
114
|
+
'This model usually expects 1 or 3 input channels. '
|
|
115
|
+
'However, it was passed ' + str(input_shape[0]) + ' input channels.')
|
|
116
|
+
default_shape = (input_shape[0], default_size, default_size)
|
|
117
|
+
else:
|
|
118
|
+
if input_shape[-1] != 3 and input_shape[-1] != 1:
|
|
119
|
+
warnings.warn(
|
|
120
|
+
'This model usually expects 1 or 3 input channels. '
|
|
121
|
+
'However, it was passed ' + str(input_shape[-1]) + ' input channels.')
|
|
122
|
+
default_shape = (default_size, default_size, input_shape[-1])
|
|
123
|
+
else:
|
|
124
|
+
if data_format == 'channels_first':
|
|
125
|
+
default_shape = (3, default_size, default_size)
|
|
126
|
+
else:
|
|
127
|
+
default_shape = (default_size, default_size, 3)
|
|
128
|
+
if include_top:
|
|
129
|
+
if input_shape is not None:
|
|
130
|
+
if input_shape != default_shape:
|
|
131
|
+
raise ValueError('When setting`include_top=True`, '
|
|
132
|
+
'`input_shape` should be ' + str(default_shape) + '.')
|
|
133
|
+
input_shape = default_shape
|
|
134
|
+
else:
|
|
135
|
+
if data_format == 'channels_first':
|
|
136
|
+
if input_shape is not None:
|
|
137
|
+
if len(input_shape) != 3:
|
|
138
|
+
raise ValueError('`input_shape` must be a tuple of three integers.')
|
|
139
|
+
if input_shape[0] != 3 and weights == 'imagenet':
|
|
140
|
+
raise ValueError('The input must have 3 channels; got '
|
|
141
|
+
'`input_shape=' + str(input_shape) + '`')
|
|
142
|
+
if ((input_shape[1] is not None and input_shape[1] < min_size) or
|
|
143
|
+
(input_shape[2] is not None and input_shape[2] < min_size)):
|
|
144
|
+
raise ValueError('Input size must be at least ' +
|
|
145
|
+
str(min_size) + 'x' + str(min_size) + ', got '
|
|
146
|
+
'`input_shape=' + str(input_shape) + '`')
|
|
147
|
+
else:
|
|
148
|
+
input_shape = (3, None, None)
|
|
149
|
+
else:
|
|
150
|
+
if input_shape is not None:
|
|
151
|
+
if len(input_shape) != 3:
|
|
152
|
+
raise ValueError('`input_shape` must be a tuple of three integers.')
|
|
153
|
+
if input_shape[-1] != 3 and weights == 'imagenet':
|
|
154
|
+
raise ValueError('The input must have 3 channels; got '
|
|
155
|
+
'`input_shape=' + str(input_shape) + '`')
|
|
156
|
+
if ((input_shape[0] is not None and input_shape[0] < min_size) or
|
|
157
|
+
(input_shape[1] is not None and input_shape[1] < min_size)):
|
|
158
|
+
raise ValueError('Input size must be at least ' +
|
|
159
|
+
str(min_size) + 'x' + str(min_size) + ', got '
|
|
160
|
+
'`input_shape=' + str(input_shape) + '`')
|
|
161
|
+
else:
|
|
162
|
+
input_shape = (None, None, 3)
|
|
163
|
+
return input_shape
|