简体   繁体   中英

how can we generate a CNN model?

I saw a post about Dog and Cat classification, link to that blog

https://medium.com/@mrgarg.rajat/kaggle-dogs-vs-cats-challenge-complete-step-by-step-guide-part-2-e9ee4967b9

but in the code, author show architecture of CNN network like this

model = Sequential()

model.add(Conv2D(32, (3,3), input_shape=(ROWS, COLS, CHANNELS), activation='relu'))
model.add(MaxPooling2D(pool_size = (2,2)))

model.add(Conv2D(64, (3,3), activation='relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.4))

model.add(Conv2D(128, (3,3), activation='relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.4))

model.add(Conv2D(256, (3,3), activation='relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.4))

model.add(Conv2D(512, (1,1), activation='relu'))
#model.add(MaxPooling2D(pool_size = (2,2)))

model.add(Flatten())
model.add(Dropout(0.4))

model.add(Dense(units=120, activation='relu'))
model.add(Dense(units=2, activation='sigmoid'))

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

I really don't know how author use this, like, how he think a network like this but none other, why need 4 con2d and 2 dense, and how he use dropout, please help me explain this network, thank a lot

in this CNN:

ROW and COL is 64

CHANNELS is 3

Your question is about the architecture of the model. The real answer is that, there is actually no straight-froward to find the good one which does the job in the very first place. That is actually the main task in R&D, with numerous cross-validation to estimate a good architecture for a specific problem. And that is one of the reasons why pre-trained models are so precious.

There is a branch of ML called AutoML , which tries to navigate through space and approximately find the good architecture. Feel free to have a look.

If you want to learn about why people use certain CNN models, you'll need to read research papers about how CNN models were developed. A couple of models you might want to read up on are VGG, ResNet, AlexNet, and Inception. Most of these bloggers making articles are basing their work off these models since they've been shown to be highly effective.

These models are developed through a combination of theory (coming up with ideas about what might work) and testing (actually trying and adding in all of the layers).

Understand, much of this is built on matrix algebra, probability, and calculus so if you don't know these subjects, you need to start there if you really want to understand what's going on under the hood.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM