keras 0.2.0__py2.7.egg
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.
- EGG-INFO/PKG-INFO +11 -0
- EGG-INFO/SOURCES.txt +51 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/requires.txt +6 -0
- EGG-INFO/top_level.txt +1 -0
- EGG-INFO/zip-safe +1 -0
- keras/__init__.py +15 -0
- keras/__init__.pyc +0 -0
- keras/activations.py +49 -0
- keras/activations.pyc +0 -0
- keras/backend/__init__.py +39 -0
- keras/backend/__init__.pyc +0 -0
- keras/backend/common.py +31 -0
- keras/backend/common.pyc +0 -0
- keras/backend/tensorflow_backend.py +602 -0
- keras/backend/tensorflow_backend.pyc +0 -0
- keras/backend/theano_backend.py +622 -0
- keras/backend/theano_backend.pyc +0 -0
- keras/callbacks.py +295 -0
- keras/callbacks.pyc +0 -0
- keras/constraints.py +45 -0
- keras/constraints.pyc +0 -0
- keras/datasets/__init__.py +0 -0
- keras/datasets/__init__.pyc +0 -0
- keras/datasets/cifar.py +22 -0
- keras/datasets/cifar.pyc +0 -0
- keras/datasets/cifar10.py +31 -0
- keras/datasets/cifar10.pyc +0 -0
- keras/datasets/cifar100.py +28 -0
- keras/datasets/cifar100.pyc +0 -0
- keras/datasets/data_utils.py +50 -0
- keras/datasets/data_utils.pyc +0 -0
- keras/datasets/imdb.py +66 -0
- keras/datasets/imdb.pyc +0 -0
- keras/datasets/mnist.py +23 -0
- keras/datasets/mnist.pyc +0 -0
- keras/datasets/reuters.py +148 -0
- keras/datasets/reuters.pyc +0 -0
- keras/initializations.py +86 -0
- keras/initializations.pyc +0 -0
- keras/layers/__init__.py +0 -0
- keras/layers/__init__.pyc +0 -0
- keras/layers/advanced_activations.py +156 -0
- keras/layers/advanced_activations.pyc +0 -0
- keras/layers/containers.py +405 -0
- keras/layers/containers.pyc +0 -0
- keras/layers/convolutional.py +505 -0
- keras/layers/convolutional.pyc +0 -0
- keras/layers/core.py +1428 -0
- keras/layers/core.pyc +0 -0
- keras/layers/embeddings.py +88 -0
- keras/layers/embeddings.pyc +0 -0
- keras/layers/noise.py +55 -0
- keras/layers/noise.pyc +0 -0
- keras/layers/normalization.py +123 -0
- keras/layers/normalization.pyc +0 -0
- keras/layers/ntm.py +326 -0
- keras/layers/ntm.pyc +0 -0
- keras/layers/recurrent.py +354 -0
- keras/layers/recurrent.pyc +0 -0
- keras/models.py +743 -0
- keras/models.pyc +0 -0
- keras/objectives.py +59 -0
- keras/objectives.pyc +0 -0
- keras/optimizers.py +229 -0
- keras/optimizers.pyc +0 -0
- keras/preprocessing/__init__.py +0 -0
- keras/preprocessing/__init__.pyc +0 -0
- keras/preprocessing/image.py +246 -0
- keras/preprocessing/image.pyc +0 -0
- keras/preprocessing/sequence.py +124 -0
- keras/preprocessing/sequence.pyc +0 -0
- keras/preprocessing/text.py +176 -0
- keras/preprocessing/text.pyc +0 -0
- keras/regularizers.py +86 -0
- keras/regularizers.pyc +0 -0
- keras/utils/__init__.py +0 -0
- keras/utils/__init__.pyc +0 -0
- keras/utils/generic_utils.py +133 -0
- keras/utils/generic_utils.pyc +0 -0
- keras/utils/io_utils.py +71 -0
- keras/utils/io_utils.pyc +0 -0
- keras/utils/layer_utils.py +93 -0
- keras/utils/layer_utils.pyc +0 -0
- keras/utils/np_utils.py +53 -0
- keras/utils/np_utils.pyc +0 -0
- keras/utils/test_utils.py +27 -0
- keras/utils/test_utils.pyc +0 -0
- keras/utils/theano_utils.py +44 -0
- keras/utils/theano_utils.pyc +0 -0
- keras/utils/visualize_util.py +41 -0
- keras/utils/visualize_util.pyc +0 -0
- keras/wrappers/__init__.py +0 -0
- keras/wrappers/__init__.pyc +0 -0
- keras/wrappers/scikit_learn.py +266 -0
- keras/wrappers/scikit_learn.pyc +0 -0
- tests/__init__.py +0 -0
- tests/__init__.pyc +0 -0
- tests/manual/__init__.py +0 -0
- tests/manual/__init__.pyc +0 -0
- tests/manual/check_autoencoder.py +134 -0
- tests/manual/check_autoencoder.pyc +0 -0
- tests/manual/check_callbacks.py +236 -0
- tests/manual/check_callbacks.pyc +0 -0
- tests/manual/check_constraints.py +100 -0
- tests/manual/check_constraints.pyc +0 -0
- tests/manual/check_masked_recurrent.py +130 -0
- tests/manual/check_masked_recurrent.pyc +0 -0
- tests/manual/check_model_utils.py +44 -0
- tests/manual/check_model_utils.pyc +0 -0
- tests/manual/check_save_weights.py +40 -0
- tests/manual/check_save_weights.pyc +0 -0
- tests/manual/check_wrappers.py +126 -0
- tests/manual/check_wrappers.pyc +0 -0
- tests/manual/check_yaml.py +101 -0
- tests/manual/check_yaml.pyc +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import print_function
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from keras.utils.test_utils import get_test_data
|
|
6
|
+
from keras.preprocessing import sequence
|
|
7
|
+
from keras.optimizers import SGD, RMSprop, Adagrad
|
|
8
|
+
from keras.utils import np_utils
|
|
9
|
+
from keras.models import Sequential, Graph
|
|
10
|
+
from keras.layers.core import Dense, Dropout, Activation, Merge
|
|
11
|
+
from keras.layers.embeddings import Embedding
|
|
12
|
+
from keras.layers.recurrent import LSTM, GRU
|
|
13
|
+
from keras.datasets import imdb
|
|
14
|
+
from keras.models import model_from_yaml
|
|
15
|
+
|
|
16
|
+
'''
|
|
17
|
+
This is essentially the IMDB test. Deserialized models should yield
|
|
18
|
+
the same config as the original one.
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
max_features = 10000
|
|
22
|
+
maxlen = 100
|
|
23
|
+
batch_size = 32
|
|
24
|
+
|
|
25
|
+
(X_train, y_train), (X_test, y_test) = imdb.load_data(nb_words=max_features, test_split=0.2)
|
|
26
|
+
|
|
27
|
+
X_train = sequence.pad_sequences(X_train, maxlen=maxlen)
|
|
28
|
+
X_test = sequence.pad_sequences(X_test, maxlen=maxlen)
|
|
29
|
+
|
|
30
|
+
model = Sequential()
|
|
31
|
+
model.add(Embedding(max_features, 128))
|
|
32
|
+
model.add(LSTM(128, 128))
|
|
33
|
+
model.add(Dropout(0.5))
|
|
34
|
+
model.add(Dense(128, 1, W_regularizer='identity', b_constraint='maxnorm'))
|
|
35
|
+
model.add(Activation('sigmoid'))
|
|
36
|
+
|
|
37
|
+
model.get_config(verbose=1)
|
|
38
|
+
|
|
39
|
+
#####################################
|
|
40
|
+
# save model w/o parameters to yaml #
|
|
41
|
+
#####################################
|
|
42
|
+
|
|
43
|
+
yaml_no_params = model.to_yaml()
|
|
44
|
+
|
|
45
|
+
no_param_model = model_from_yaml(yaml_no_params)
|
|
46
|
+
no_param_model.get_config(verbose=1)
|
|
47
|
+
|
|
48
|
+
######################################
|
|
49
|
+
# save multi-branch sequential model #
|
|
50
|
+
######################################
|
|
51
|
+
|
|
52
|
+
seq = Sequential()
|
|
53
|
+
seq.add(Merge([model, model], mode='sum'))
|
|
54
|
+
seq.get_config(verbose=1)
|
|
55
|
+
merge_yaml = seq.to_yaml()
|
|
56
|
+
merge_model = model_from_yaml(merge_yaml)
|
|
57
|
+
|
|
58
|
+
large_model = Sequential()
|
|
59
|
+
large_model.add(Merge([seq,model], mode='concat'))
|
|
60
|
+
large_model.get_config(verbose=1)
|
|
61
|
+
large_model.to_yaml()
|
|
62
|
+
|
|
63
|
+
####################
|
|
64
|
+
# save graph model #
|
|
65
|
+
####################
|
|
66
|
+
|
|
67
|
+
X = np.random.random((100, 32))
|
|
68
|
+
X2 = np.random.random((100, 32))
|
|
69
|
+
y = np.random.random((100, 4))
|
|
70
|
+
y2 = np.random.random((100,))
|
|
71
|
+
|
|
72
|
+
(X_train, y_train), (X_test, y_test) = get_test_data(nb_train=1000, nb_test=200, input_shape=(32,),
|
|
73
|
+
classification=False, output_shape=(4,))
|
|
74
|
+
|
|
75
|
+
graph = Graph()
|
|
76
|
+
|
|
77
|
+
graph.add_input(name='input1', ndim=2)
|
|
78
|
+
|
|
79
|
+
graph.add_node(Dense(32, 16), name='dense1', input='input1')
|
|
80
|
+
graph.add_node(Dense(32, 4), name='dense2', input='input1')
|
|
81
|
+
graph.add_node(Dense(16, 4), name='dense3', input='dense1')
|
|
82
|
+
|
|
83
|
+
graph.add_output(name='output1', inputs=['dense2', 'dense3'], merge_mode='sum')
|
|
84
|
+
graph.compile('rmsprop', {'output1': 'mse'})
|
|
85
|
+
|
|
86
|
+
graph.get_config(verbose=1)
|
|
87
|
+
|
|
88
|
+
history = graph.fit({'input1': X_train, 'output1': y_train}, nb_epoch=10)
|
|
89
|
+
original_pred = graph.predict({'input1': X_test})
|
|
90
|
+
|
|
91
|
+
graph_yaml = graph.to_yaml()
|
|
92
|
+
graph.save_weights('temp.h5', overwrite=True)
|
|
93
|
+
|
|
94
|
+
reloaded_graph = model_from_yaml(graph_yaml)
|
|
95
|
+
reloaded_graph.load_weights('temp.h5')
|
|
96
|
+
reloaded_graph.get_config(verbose=1)
|
|
97
|
+
|
|
98
|
+
reloaded_graph.compile('rmsprop', {'output1': 'mse'})
|
|
99
|
+
new_pred = reloaded_graph.predict({'input1': X_test})
|
|
100
|
+
|
|
101
|
+
assert(np.sum(new_pred['output1'] - original_pred['output1']) == 0)
|
|
Binary file
|