A
A
Andrey_Epifantsev2021-02-23 10:35:05
Python
Andrey_Epifantsev, 2021-02-23 10:35:05

What is the structure of this neural network?

I read an article on machine learning, I write the code as in the article.

The article describes an application that recognizes cats and dogs in images. I realized that the images are reduced to a size of 128X128, then a neural network is trained on a huge dataset and after that it can recognize cats and dogs in the images.

There is such a code describing the neural network model:

model = Sequential()
    model.add(Conv2D(32, (3, 3), input_shape=(128, 128, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(32, (3, 3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Flatten())
    model.add(Dense(units=128, activation='relu'))
    model.add(Dense(units=1, activation='sigmoid'))
    model.compile(optimizer=Adam(),
                  loss='binary_crossentropy',
                  metrics=['accuracy'])

I can’t understand: how many layers are there in this neural network? 2 or 6? Or another number? Does each of the add calls add a new layer, or do some of them change the previous ones?

Unfortunately, the article is very apical and there is no such information in it. And the documentation for these functions is written very indistinctly, using a large number of incomprehensible terms without reference to their definition.

Maybe there is some article that would explain the work of neural networks, without using obscure terms like 2D convolution layer, Max pooling operation, Flattens the input? Well, or to explain these terms.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2021-02-23
@Andrey_Epifantsev

Conv2D is a convolutional layer that runs through a stack of convolutions over the entire image, calculating a new value at each of its points. MaxPooling2D splits the entire image into a grid with a 2x2 pixel cell and selects the maximum value from each cell (the lightest pixel), their totality becomes a new image 2 times smaller in size. Flatten simply "flattens" a multi-dimensional tensor into a one-dimensional vector. Dense is a classic (as in all the pictures) fully connected layer of neurons, where each of the neurons is connected to all the neurons of the previous layer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question