Definirea rețelelor neuronale cu Keras

Introducere în TensorFlow în Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Clasificarea literelor din limbajul semnelor

Această imagine arată litera A în limbajul semnelor.

Această imagine arată litera B în limbajul semnelor.

Această imagine arată litera C în limbajul semnelor.

Această imagine arată litera D în limbajul semnelor.

Introducere în TensorFlow în Python

API-ul secvențial

Această imagine prezintă o rețea neuronală cu 16 noduri în primul strat ascuns, 8 în al doilea și 4 în stratul de ieșire.

Introducere în TensorFlow în Python

API-ul secvențial

  • Strat de intrare
  • Straturi ascunse
  • Strat de ieșire
  • Ordonate secvențial
Introducere în TensorFlow în Python

Construirea unui model secvențial

# Import tensorflow
from tensorflow import keras

# Define a sequential model
model = keras.Sequential()
# Define first hidden layer
model.add(keras.layers.Dense(16, activation='relu', input_shape=(28*28,)))
Introducere în TensorFlow în Python

Construirea unui model secvențial

# Define second hidden layer
model.add(keras.layers.Dense(8, activation='relu'))
# Define output layer
model.add(keras.layers.Dense(4, activation='softmax'))
# Compile the model
model.compile('adam', loss='categorical_crossentropy')
# Summarize the model
print(model.summary())
Introducere în TensorFlow în Python

API-ul funcțional

Figura prezintă o rețea neuronală cu două seturi de intrări.

Introducere în TensorFlow în Python

Utilizarea API-ului funcțional

# Import tensorflow
import tensorflow as tf

# Define model 1 input layer shape
model1_inputs = tf.keras.Input(shape=(28*28,))

# Define model 2 input layer shape
model2_inputs = tf.keras.Input(shape=(10,))
# Define layer 1 for model 1
model1_layer1 = tf.keras.layers.Dense(12, activation='relu')(model1_inputs)

# Define layer 2 for model 1
model1_layer2 = tf.keras.layers.Dense(4, activation='softmax')(model1_layer1)
Introducere în TensorFlow în Python

Utilizarea API-ului funcțional

# Define layer 1 for model 2
model2_layer1 = tf.keras.layers.Dense(8, activation='relu')(model2_inputs)

# Define layer 2 for model 2
model2_layer2 = tf.keras.layers.Dense(4, activation='softmax')(model2_layer1)
# Merge model 1 and model 2
merged = tf.keras.layers.add([model1_layer2, model2_layer2])
# Define a functional model
model = tf.keras.Model(inputs=[model1_inputs, model2_inputs], outputs=merged)

# Compile the model
model.compile('adam', loss='categorical_crossentropy')
Introducere în TensorFlow în Python

Să exersăm!

Introducere în TensorFlow în Python

Preparing Video For Download...