Skip to content

Commit 30c6e65

Browse files
committed
Merge pull request keras-team#124 from julienr/compile_theano_mode
Add theano_mode argument to models.compile.
2 parents 626b0b8 + 6873b38 commit 30c6e65

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

docs/sources/models.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ model = keras.models.Sequential()
1212
- __optimizer__: str (name of optimizer) or optimizer object. See [optimizers](optimizers.md).
1313
- __loss__: str (name of objective function) or objective function. See [objectives](objectives.md).
1414
- __class_mode__: one of "categorical", "binary". This is only used for computing classification accuracy or using the predict_classes method.
15+
- __theano_mode__: A `theano.compile.mode.Mode` instance controlling specifying compilation options.
1516
- __fit__(X, y, batch_size=128, nb_epoch=100, verbose=1, validation_split=0., validation_data=None, shuffle=True, show_accuracy=False): Train a model for a fixed number of epochs.
1617
- __Arguments__:
1718
- __X__: data.
@@ -103,4 +104,4 @@ Epoch 1
103104
Epoch 2
104105
10960/37800 [=======>......................] - ETA: 4s - loss: 0.0109 - acc.: 0.9420
105106
'''
106-
```
107+
```

keras/models.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def add(self, layer):
7171
def get_output(self, train):
7272
return self.layers[-1].get_output(train)
7373

74-
def compile(self, optimizer, loss, class_mode="categorical", y_dim_components=1):
74+
def compile(self, optimizer, loss, class_mode="categorical", y_dim_components=1, theano_mode=None):
7575
self.optimizer = optimizers.get(optimizer)
7676
self.loss = objectives.get(loss)
7777

@@ -107,15 +107,15 @@ def compile(self, optimizer, loss, class_mode="categorical", y_dim_components=1)
107107
updates = self.optimizer.get_updates(self.params, self.regularizers, self.constraints, train_loss)
108108

109109
self._train = theano.function([self.X, self.y], train_loss,
110-
updates=updates, allow_input_downcast=True)
110+
updates=updates, allow_input_downcast=True, mode=theano_mode)
111111
self._train_with_acc = theano.function([self.X, self.y], [train_loss, train_accuracy],
112-
updates=updates, allow_input_downcast=True)
112+
updates=updates, allow_input_downcast=True, mode=theano_mode)
113113
self._predict = theano.function([self.X], self.y_test,
114-
allow_input_downcast=True)
114+
allow_input_downcast=True, mode=theano_mode)
115115
self._test = theano.function([self.X, self.y], test_score,
116-
allow_input_downcast=True)
116+
allow_input_downcast=True, mode=theano_mode)
117117
self._test_with_acc = theano.function([self.X, self.y], [test_score, test_accuracy],
118-
allow_input_downcast=True)
118+
allow_input_downcast=True, mode=theano_mode)
119119

120120

121121
def train(self, X, y, accuracy=False):
@@ -328,4 +328,4 @@ def load_weights(self, filepath):
328328
g = f['layer_{}'.format(k)]
329329
weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]
330330
self.layers[k].set_weights(weights)
331-
f.close()
331+
f.close()

0 commit comments

Comments
 (0)