Workspace
Felipe Gomez/

Course Notes: Advanced Deep Learning with Keras

0
Beta
Spinner

add text here

# Write and run code here

Input layers The first step in creating a neural network model is to define the Input layer. This layer takes in raw data, usually in the form of numpy arrays. The shape of the Input layer defines how many variables your neural network will use. For example, if the input data has 10 columns, you define an Input layer with a shape of (10,).

In this case, you are only using one input in your network.

Import the Input layer function from keras.layers. Create an input layer of shape 1.

Import Input from tensorflow.keras.layers

from tensorflow.keras.layers import Input

Create an input layer of shape 1

input_tensor = Input(shape=(1,))

Dense layers Once you have an Input layer, the next step is to add a Dense layer.

Dense layers learn a weight matrix, where the first dimension of the matrix is the dimension of the input data, and the second dimension is the dimension of the output data. Recall that your Input layer has a shape of 1. In this case, your output layer will also have a shape of 1. This means that the Dense layer will learn a 1x1 weight matrix.

In this exercise, you will add a dense layer to your model, after the input layer.

Import the Dense layer function from keras.layers. Create a Dense layer with 1 unit. Pass input_tensor to output_layer().

Load layers

from tensorflow.keras.layers import Input, Dense

Input layer

input_tensor = Input(shape=(1,))

Dense layer

output_layer = Dense(1)

Connect the dense layer to the input_tensor

output_tensor = output_layer(input_tensor)

Output layers Output layers are simply Dense layers! Output layers are used to reduce the dimension of the inputs to the dimension of the outputs. You'll learn more about output dimensions in chapter 4, but for now, you'll always use a single output in your neural networks, which is equivalent to Dense(1) or a dense layer with a single unit.

Import the Input and Dense functions from keras.layers. Create an input layer of shape 1. Again, create a dense layer with 1 unit and pass input_tensor directly to it.

Load layers

from tensorflow.keras.layers import Input, Dense

Input layer

input_tensor = Input(shape=(1,))

Create a dense layer and connect the dense layer to the input_tensor in one step

Note that we did this in 2 steps in the previous exercise, but are doing it in one step now

output_tensor = Dense(1)(input_tensor)

  • AI Chat
  • Code