Created
September 27, 2023 20:20
-
-
Save DiogoRibeiro7/b55c7cdf01314e9c7830f4134c04cd15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout | |
def build_advanced_cnn(input_shape): | |
""" | |
Build an advanced CNN model with dropout layers. | |
Parameters: | |
input_shape (tuple): Shape of input images. | |
Returns: | |
Sequential: An advanced CNN model. | |
""" | |
model = Sequential() | |
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=input_shape)) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(64, (3, 3), activation='relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(128, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(1, activation='sigmoid')) | |
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) | |
return model | |
# Data augmentation | |
datagen = ImageDataGenerator( | |
rotation_range=40, | |
width_shift_range=0.2, | |
height_shift_range=0.2, | |
shear_range=0.2, | |
zoom_range=0.2, | |
horizontal_flip=True, | |
fill_mode='nearest') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment