Add documentation for core layers
This commit is contained in:
parent
f35d529f42
commit
25ad4000f9
@ -82,7 +82,7 @@ model.add(Activation('relu'))
|
||||
model.add(MaxPooling2D(poolsize=(2, 2)))
|
||||
model.add(Dropout(0.25))
|
||||
|
||||
model.add(Flatten(64*8*8))
|
||||
model.add(Flatten())
|
||||
model.add(Dense(64*8*8, 256))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dropout(0.5))
|
||||
@ -145,7 +145,7 @@ model.add(Convolution2D(128, 128, 3, 3))
|
||||
model.add(Activation('relu'))
|
||||
model.add(MaxPooling2D(poolsize=(2, 2)))
|
||||
|
||||
model.add(Flatten(128*4*4))
|
||||
model.add(Flatten())
|
||||
model.add(Dense(128*4*4, 256))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dropout(0.5))
|
||||
|
@ -38,4 +38,4 @@ model.add(Activation(tanh))
|
||||
|
||||
## On Advanced Activations
|
||||
|
||||
Activations that are more complex than a simple Theano function (eg. learnable activations, configurable activations, etc.) are available as [Advanced Activation layers](/layers/advanced_activations), and can be found in the module `keras.layers.advanced_activations`. These include PReLU and LeakyReLU.
|
||||
Activations that are more complex than a simple Theano function (eg. learnable activations, configurable activations, etc.) are available as [Advanced Activation layers](layers/advanced_activations.md), and can be found in the module `keras.layers.advanced_activations`. These include PReLU and LeakyReLU.
|
@ -63,7 +63,7 @@ model.add(Activation('relu'))
|
||||
model.add(MaxPooling2D(poolsize=(2, 2)))
|
||||
model.add(Dropout(0.25))
|
||||
|
||||
model.add(Flatten(64*8*8))
|
||||
model.add(Flatten())
|
||||
model.add(Dense(64*8*8, 256))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dropout(0.5))
|
||||
@ -126,7 +126,7 @@ model.add(Convolution2D(128, 128, 3, 3))
|
||||
model.add(Activation('relu'))
|
||||
model.add(MaxPooling2D(poolsize=(2, 2)))
|
||||
|
||||
model.add(Flatten(128*4*4))
|
||||
model.add(Flatten())
|
||||
model.add(Dense(128*4*4, 256))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dropout(0.5))
|
||||
|
@ -1,5 +1,3 @@
|
||||
# Core
|
||||
|
||||
## Base class
|
||||
|
||||
```python
|
||||
@ -8,55 +6,167 @@ keras.layers.core.Layer()
|
||||
|
||||
__Methods__:
|
||||
|
||||
```python
|
||||
connect(self, previous_layer)
|
||||
```
|
||||
|
||||
## Core layers
|
||||
- Connect the input of the current layer to the output of the argument layer.
|
||||
|
||||
### Dense
|
||||
- __Returns__: None.
|
||||
|
||||
- __Arguments__:
|
||||
- __previous_layer__: Layer object.
|
||||
|
||||
|
||||
|
||||
```python
|
||||
output(self, train)
|
||||
```
|
||||
|
||||
- Get the output of the layer.
|
||||
|
||||
- __Returns__: Theano tensor.
|
||||
|
||||
- __Arguments__:
|
||||
- __train__: Boolean. Specifies whether output is computed in training mode or in testing mode, which can change the logic, for instance in there are any `Dropout` layers in the network.
|
||||
|
||||
|
||||
|
||||
```python
|
||||
get_input(self, train)
|
||||
```
|
||||
|
||||
- Get the input of the layer.
|
||||
|
||||
- __Returns__: Theano tensor.
|
||||
|
||||
- __Arguments__:
|
||||
- __train__: Boolean. Specifies whether output is computed in training mode or in testing mode, which can change the logic, for instance in there are any `Dropout` layers in the network.
|
||||
|
||||
|
||||
|
||||
```python
|
||||
get_weights(self)
|
||||
```
|
||||
|
||||
- Get the weights of the parameters of the layer.
|
||||
|
||||
- __Returns__: List of numpy arrays (one per layer parameter).
|
||||
|
||||
|
||||
|
||||
```python
|
||||
set_weights(self, weights)
|
||||
```
|
||||
|
||||
- Set the weights of the parameters of the layer.
|
||||
|
||||
- __Arguments__:
|
||||
- __weights__: List of numpy arrays (one per layer parameter). Should be in the same order as what `get_weights(self)` returns.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Dense
|
||||
```python
|
||||
keras.layers.core.Dense(input_dim, output_dim, init='uniform', activation='linear', weights=None)
|
||||
```
|
||||
__Arguments__:
|
||||
|
||||
__Methods__:
|
||||
- Standard 1D fully-connect layer.
|
||||
|
||||
### Activation
|
||||
- __Input shape__: `(nb_samples, input_dim)`.
|
||||
|
||||
- __Arguments__:
|
||||
|
||||
- __input_dim__: int >= 0.
|
||||
- __output_dim__: int >= 0.
|
||||
- __init__: name of initialization function for the weights of the layer (see: [initializations](../initializations.md)), or alternatively, Theano function to use for weights initialization. This parameter is only relevant if you don't pass a `weights` argument.
|
||||
- __activation__: name of activation function to use (see: [activations](../activations.md)), or alternatively, elementwise Theano function. If you don't specify anything, no activation is applied (ie. "linear" activation: a(x) = x).
|
||||
- __weights__: list of numpy arrays to set as initial weights. The list should have 1 element, of shape `(input_dim, output_dim)`.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Activation
|
||||
```python
|
||||
keras.layers.core.Activation(activation)
|
||||
```
|
||||
__Arguments__:
|
||||
- Apply an activation function to the input.
|
||||
|
||||
__Methods__:
|
||||
- __Input shape__: This layer does not assume a specific input shape. As a result, it cannot be used as the first layer in a model.
|
||||
|
||||
### Dropout
|
||||
- __Arguments__:
|
||||
|
||||
- __activation__: name of activation function to use (see: [activations](../activations.md)), or alternatively, elementwise Theano function.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Dropout
|
||||
```python
|
||||
keras.layers.core.Dropout(p)
|
||||
```
|
||||
__Arguments__:
|
||||
- Apply dropout to the input. Dropout consists in randomly setting a fraction `p` of input units to 0 at each update during training time, which helps prevent overfitting. Reference: [Dropout: A Simple Way to Prevent Neural Networks from Overfitting](http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf)
|
||||
|
||||
__Methods__:
|
||||
- __Input shape__: This layer does not assume a specific input shape. As a result, it cannot be used as the first layer in a model.
|
||||
|
||||
### Reshape
|
||||
- __Arguments__:
|
||||
|
||||
- __p__: float (0 <= p < 1). Fraction of the input that gets dropped out at training time.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Reshape
|
||||
```python
|
||||
keras.layers.core.Reshape(*dims)
|
||||
```
|
||||
__Arguments__:
|
||||
|
||||
__Methods__:
|
||||
- Reshape the input to a new shape containing the same number of units.
|
||||
|
||||
### Flatten
|
||||
- __Input shape__: This layer does not assume a specific input shape. As a result, it cannot be used as the first layer in a model.
|
||||
|
||||
- __Arguments__:
|
||||
|
||||
- *dims: integers. Dimensions of the new shape.
|
||||
|
||||
- __Example__:
|
||||
```python
|
||||
keras.layers.core.Flatten(size)
|
||||
# input shape: (nb_samples, 10)
|
||||
model.add(Dense(10, 100)) # output shape: (nb_samples, 100)
|
||||
model.add(Reshape(10, 10)) # output shape: (nb_samples, 10, 10)
|
||||
```
|
||||
__Arguments__:
|
||||
|
||||
__Methods__:
|
||||
---
|
||||
|
||||
### RepeatVector
|
||||
## Flatten
|
||||
```python
|
||||
keras.layers.core.Flatten()
|
||||
```
|
||||
|
||||
- Convert a nD input to 1D.
|
||||
- __Input shape__: (nb_samples, *). This layer cannot be used as the first layer in a model.
|
||||
|
||||
---
|
||||
|
||||
## RepeatVector
|
||||
```python
|
||||
keras.layers.core.RepeatVector(n)
|
||||
```
|
||||
__Arguments__:
|
||||
|
||||
__Methods__:
|
||||
- Repeat the 1D input n times. Dimensions of input are assumed to be (nb_samples, dim). Output will have the shape (nb_samples, n, dim).
|
||||
|
||||
- __Input shape__: This layer does not assume a specific input shape. As a result, it cannot be used as the first layer in a model.
|
||||
|
||||
- __Arguments__:
|
||||
- __n__: int.
|
||||
|
||||
- __Example__:
|
||||
|
||||
```python
|
||||
# input shape: (nb_samples, 10)
|
||||
model.add(Dense(10, 100)) # output shape: (nb_samples, 100)
|
||||
model.add(Repeat(2)) # output shape: (nb_samples, 2, 10)
|
||||
```
|
||||
|
||||
|
@ -21,6 +21,8 @@ You can either instantiate an optimizer before passing it to `model.compile()` ,
|
||||
model.compile(loss='mean_squared_error', optimizer='sgd')
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Base class
|
||||
|
||||
```python
|
||||
@ -37,6 +39,8 @@ All optimizers descended from this class support the following keyword arguments
|
||||
|
||||
Note: this is base class for building optimizers, not an actual optimizer that can be used for training models.
|
||||
|
||||
---
|
||||
|
||||
## SGD
|
||||
|
||||
```python
|
||||
@ -44,11 +48,15 @@ keras.optimizers.SGD(lr=0.01, momentum=0., decay=0., nesterov=False)
|
||||
```
|
||||
[[source](https://github.com/fchollet/keras/blob/master/keras/optimizers.py)]
|
||||
|
||||
__Arguments__:
|
||||
|
||||
- __lr__: float >= 0. Learning rate.
|
||||
- __momentum__: float >= 0. Parameter updates momentum.
|
||||
- __decay__: float >= 0. Learning rate decay over each update.
|
||||
- __nesterov__: boolean. Whether to apply Nesterov momentum.
|
||||
|
||||
---
|
||||
|
||||
## Adagrad
|
||||
|
||||
```python
|
||||
@ -58,9 +66,12 @@ keras.optimizers.Adagrad(lr=0.01, epsilon=1e-6)
|
||||
|
||||
It is recommended to leave the parameters of this optimizer at their default values.
|
||||
|
||||
__Arguments__:
|
||||
|
||||
- __lr__: float >= 0. Learning rate.
|
||||
- __epsilon__: float >= 0.
|
||||
|
||||
---
|
||||
|
||||
## Adadelta
|
||||
|
||||
@ -71,12 +82,16 @@ keras.optimizers.Adadelta(lr=1.0, rho=0.95, epsilon=1e-6)
|
||||
|
||||
It is recommended to leave the parameters of this optimizer at their default values.
|
||||
|
||||
__Arguments__:
|
||||
|
||||
- __lr__: float >= 0. Learning rate. It is recommended to leave it at the default value.
|
||||
- __rho__: float >= 0.
|
||||
- __epsilon__: float >= 0. Fuzz factor.
|
||||
|
||||
For more info, see *"Adadelta: an adaptive learning rate method"* by Matthew Zeiler.
|
||||
|
||||
---
|
||||
|
||||
## RMSprop
|
||||
|
||||
```python
|
||||
@ -86,6 +101,8 @@ keras.optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=1e-6)
|
||||
|
||||
It is recommended to leave the parameters of this optimizer at their default values.
|
||||
|
||||
__Arguments__:
|
||||
|
||||
- __lr__: float >= 0. Learning rate.
|
||||
- __rho__: float >= 0.
|
||||
- __epsilon__: float >= 0. Fuzz factor.
|
Loading…
Reference in New Issue
Block a user