Neural Networks Beginnings. Jade Carter

Чтение книги онлайн.

Читать онлайн книгу Neural Networks Beginnings - Jade Carter страница 5

Автор:
Жанр:
Серия:
Издательство:
Neural Networks Beginnings - Jade Carter

Скачать книгу

style="font-size:15px;">       layers.Flatten(),

       layers.Dense(256, activation='relu'),

       layers.BatchNormalization(),

       layers.Dropout(0.5),

       layers.Dense(7, activation='softmax')

      ])

      # Compiling the model.

      model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

      # Training the model

      history = model.fit(train_data, train_labels, epochs=50, validation_data=(val_data, val_labels))

      # Evaluation of the model

      test_loss, test_acc = model.evaluate(test_data, test_labels)

      print('Test accuracy:', test_acc)

      # Using the model

      predictions = model.predict(new_data)

      This code creates a convolutional neural network for recognizing emotions on 48x48 pixel images.

      The first layer uses a 3x3 convolution with 32 filters and a ReLU activation function that takes 48x48x1 input images. Then follow layers of batch normalization, max pooling with a 2x2 filter size, and dropout to help prevent overfitting.

      Two additional convolutional layers with increased filter numbers and similar normalization and dropout layers are then added. A flattening layer follows, which converts the multidimensional input to a one-dimensional vector.

      Next are two fully connected layers with ReLU activation and batch normalization, as well as dropout layers. The final layer contains 7 neurons and uses the softmax activation function to determine the probability of each of the 7 emotions.

      The optimizer Adam, the categorical_crossentropy loss function, and the accuracy metric are used to compile the model. The model is trained on the training data for 50 epochs with validation on the validation data.

      After training, the model is evaluated on the test data, and the accuracy of predictions is displayed. Then the model is used to predict emotions on new data.

      Conclusion on Chapter 1:

      In this chapter, we have covered the fundamental concepts underlying neural networks. We learned what a neuron is, how it works in a neural network, what weights and biases are, how a neuron makes decisions, and how a neural network is constructed. We also discussed the process of training a neural network and how it adjusts its weights and biases to improve prediction accuracy.

      Конец ознакомительного фрагмента.

      Текст предоставлен ООО «ЛитРес».

      Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.

      Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.

/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wgARCAhhBdwDASIAAhEBAxEB/8QAGwABAQACAwEAAAAAAAAAAAAAAAECBAMFBgf/xAAWAQEBAQAA

Скачать книгу