keras_input_explanation
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
keras_input_explanation [2020/10/03 11:58] – [Defining your image in Keras] serge | keras_input_explanation [2020/12/27 15:14] (Version actuelle) – serge | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Keras input explanation: | ====== Keras input explanation: | ||
+ | <WRAP center round box 60% centeralign> | ||
+ | **{{tagpage> | ||
+ | </ | ||
+ | <WRAP center round box 60% centeralign> | ||
+ | **[[les_pages_intelligence_artificielle_en_details|Les Pages Intelligence Artificielle en détails]]** | ||
+ | </ | ||
+ | |||
Mise en forme d'un post de **stackoverflow.com** non traduit en français, car très technique ce qui ne se comprend qu'en anglais. | Mise en forme d'un post de **stackoverflow.com** non traduit en français, car très technique ce qui ne se comprend qu'en anglais. | ||
**[[https:// | **[[https:// | ||
+ | |||
+ | =====Ressources===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
=====Question===== | =====Question===== | ||
Ligne 28: | Ligne 40: | ||
====The input shape==== | ====The input shape==== | ||
What flows between layers are tensors. Tensors can be seen as matrices, with shapes. \\ | What flows between layers are tensors. Tensors can be seen as matrices, with shapes. \\ | ||
- | In Keras, the input layer itself is not a layer, but a tensor. It's the starting tensor you send to the first hidden layer. This tensor must have the same shape as your training data. \\ | + | In Keras, the input layer itself is not a layer, but a tensor. It's the starting tensor you send to the first hidden layer. |
- | Example: if you have 30 images of 50x50 pixels in RGB (3 channels), the shape of your input data is (30, | + | Example: if you have 30 images of 50x50 pixels in RGB (3 channels), the shape of your input data is (30, |
Each type of layer requires the input with a certain number of dimensions: | Each type of layer requires the input with a certain number of dimensions: | ||
* Dense layers require inputs as (batch_size, | * Dense layers require inputs as (batch_size, | ||
Ligne 37: | Ligne 49: | ||
*if using channels_first: | *if using channels_first: | ||
* 1D convolutions and recurrent layers use (batch_size, | * 1D convolutions and recurrent layers use (batch_size, | ||
- | *Details on how to prepare data for recurrent layers | + | *Details on [[https:// |
Now, the input shape is the only one you must define, because your model cannot know it. Only you know that, based on your training data. \\ | Now, the input shape is the only one you must define, because your model cannot know it. Only you know that, based on your training data. \\ | ||
All the other shapes are calculated automatically based on the units and particularities of each layer. | All the other shapes are calculated automatically based on the units and particularities of each layer. | ||
Ligne 90: | Ligne 103: | ||
model = Sequential() | model = Sequential() | ||
- | #start from the first hidden layer, since the input is not actually a layer | + | # Start from the first hidden layer, since the input is not actually a layer |
- | #but inform the shape of the input, with 3 elements. | + | # but inform the shape of the input, with 3 elements. |
- | model.add(Dense(units=4, | + | model.add(Dense(units=4, |
- | #further | + | # Further |
- | model.add(Dense(units=4)) #hidden layer 2 | + | model.add(Dense(units=4)) # hidden layer 2 |
- | model.add(Dense(units=1)) #output layer | + | model.add(Dense(units=1)) # output layer |
</ | </ | ||
| | ||
**With the functional API Model:** | **With the functional API Model:** | ||
+ | |||
<code python> | <code python> | ||
from keras.models import Model | from keras.models import Model | ||
from keras.layers import * | from keras.layers import * | ||
- | #Start defining the input tensor: | + | # Start defining the input tensor: |
inpTensor = Input((3, | inpTensor = Input((3, | ||
- | #create | + | # Create |
hidden1Out = Dense(units=4)(inpTensor) | hidden1Out = Dense(units=4)(inpTensor) | ||
hidden2Out = Dense(units=4)(hidden1Out) | hidden2Out = Dense(units=4)(hidden1Out) | ||
finalOut = Dense(units=1)(hidden2Out) | finalOut = Dense(units=1)(hidden2Out) | ||
- | #define | + | # Define |
- | model = Model(inpTensor, | + | model = Model(inpTensor, |
</ | </ | ||
Ligne 148: | Ligne 162: | ||
It (the word dimension alone) can refer to: | It (the word dimension alone) can refer to: | ||
- **The dimension of Input Data (or stream)** such as # N of sensor axes to beam the time series signal, or RGB color channel (3): suggested word=> " | - **The dimension of Input Data (or stream)** such as # N of sensor axes to beam the time series signal, or RGB color channel (3): suggested word=> " | ||
- | - **The total number /length of Input Features** (or Input layer) (28 x 28 = 784 for the MINST color image) or 3000 in the FFT transformed Spectrum Values, or | + | - **The total number /length of Input Features** (or Input layer) (28 x 28 = 784 for the MINST color image) or 3000 in the FFT transformed Spectrum Values, or "Input Layer / Input Feature Dimension" |
- | "Input Layer / Input Feature Dimension" | + | |
- **The dimensionality** (# of dimension) of the input (typically 3D as expected in Keras LSTM) or (# | - **The dimensionality** (# of dimension) of the input (typically 3D as expected in Keras LSTM) or (# | ||
- | "N Dimensionality of Input" | + | - "N Dimensionality of Input" **The SPECIFIC Input Shape** (eg. (30, |
- | - **The SPECIFIC Input Shape** (eg. (30, | + | |
- | | + | |
Keras has its input_dim refers to the Dimension of Input Layer / Number of Input Feature | Keras has its input_dim refers to the Dimension of Input Layer / Number of Input Feature | ||
+ | |||
<code python> | <code python> | ||
model = Sequential() | model = Sequential() | ||
Ligne 168: | Ligne 181: | ||
- | {{tag>sb ia}} | + | {{tag>sb ia keras}} |
keras_input_explanation.1601726328.txt.gz · Dernière modification : 2020/10/03 11:58 de serge