简体   繁体   English

关于卷积神经网络

[英]Regarding Convolutional Neural Network

Hi wish to enquire some help regarding neural networks, i am doing a school project whereby i am required to build deep fake detection neural network.嗨,想咨询一些有关神经网络的帮助,我正在做一个学校项目,要求我构建深度假检测神经网络。 I am unsure on why by adding more layers into the neural.我不确定为什么要在神经中添加更多层。 My Accuracy during training goes from 0.7 in the first epoch and jumps to 1.0 in the second to fifth epoch which is overfittin and the loss value goes to a weird number, Wish to seek advice on how i could adjust the neural network to suit deepfake detections.我在训练期间的准确度从第一个时期的 0.7 到第二到第五个时期的 1.0,这是过度拟合并且损失值达到一个奇怪的数字,希望就如何调整神经网络以适应 deepfake 检测寻求建议.

Thank you all for the time in reading感谢大家的阅读时间

import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D, Dropout

model = Sequential()
model.add(Conv2D(32, (3,3), input_shape = (256,256,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(64, (3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(64, (3,3)))
model.add(Activation("relu"))
model.add(Dropout(0.20))

model.add(Conv2D(64, (3,3)))
model.add(Activation("relu"))
model.add(Dropout(0.20))

model.add(Conv2D(64, (3,3)))
model.add(Activation("relu"))
model.add(Dropout(0.20))

model.add(Conv2D(64, (3,3)))
model.add(Activation("relu"))


#flatten the layer conv 2d dense is 1d data set
model.add(Flatten()) #convets 3d feature maps to 1D feature Vectors

model.add(Dense(64))
model.add(Activation('relu'))

model.add(Dense(1))
model.add(Activation('sigmoid'))

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

model.fit(X, y, batch_size=32, epochs=5)

Model Summary Model 总结

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d (Conv2D)              (None, 254, 254, 32)      896       
_________________________________________________________________
activation (Activation)      (None, 254, 254, 32)      0         
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 127, 127, 32)      0         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 125, 125, 64)      18496     
_________________________________________________________________
activation_1 (Activation)    (None, 125, 125, 64)      0         
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 62, 62, 64)        0         
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 60, 60, 64)        36928     
_________________________________________________________________
activation_2 (Activation)    (None, 60, 60, 64)        0         
_________________________________________________________________
dropout (Dropout)            (None, 60, 60, 64)        0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 58, 58, 64)        36928     
_________________________________________________________________
activation_3 (Activation)    (None, 58, 58, 64)        0         
_________________________________________________________________
dropout_1 (Dropout)          (None, 58, 58, 64)        0         
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 56, 56, 64)        36928     
_________________________________________________________________
activation_4 (Activation)    (None, 56, 56, 64)        0         
_________________________________________________________________
dropout_2 (Dropout)          (None, 56, 56, 64)        0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 54, 54, 64)        36928     
_________________________________________________________________
activation_5 (Activation)    (None, 54, 54, 64)        0         
_________________________________________________________________
flatten (Flatten)            (None, 186624)            0         
_________________________________________________________________
dense (Dense)                (None, 64)                11944000  
_________________________________________________________________
activation_6 (Activation)    (None, 64)                0         
_________________________________________________________________
dense_1 (Dense)              (None, 1)                 65        
_________________________________________________________________
activation_7 (Activation)    (None, 1)                 0         
=================================================================
Total params: 12,111,169
Trainable params: 12,111,169
Non-trainable params: 0
_________________________________________________________________

You have to specify more stuff inside each layer, not only the size and number of filters.您必须在每一层内指定更多的东西,而不仅仅是过滤器的大小和数量。 This will help you to increase the model performance.这将帮助您提高 model 性能。
For example, you could use adam from keras_optimizers, which will help to increase the accuracy during training the model.例如,您可以使用 keras_optimizers 中的 adam,这将有助于提高训练 model 期间的准确性。 Also, l2 from keras.regularizers will help you to reduce overfitting.此外,来自 keras.regularizers 的 l2 将帮助您减少过度拟合。 Which means you can't increase the accuracy just by increasing the epochs, you must first build a good model before starting the training这意味着你不能仅仅通过增加epochs来提高准确率,你必须在开始训练之前先建立一个好的model

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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