CNN_Model_Code
CNN_Model_Code
import os
import numpy as np
import tensorflow as tf
crack_dir = '/content/crack'
without_crack_dir = '/content/without_crack'
data = []
labels = []
"""Load images from the given folder path and assign the specified label."""
if img_name.lower().endswith(valid_extensions):
try:
# Resize image
data.append(img)
labels.append(label)
except Exception as e:
load_images(crack_dir, label=1)
load_images(without_crack_dir, label=0)
CNN MODEL
data = np.array(data)
labels = np.array(labels)
model = Sequential([
MaxPooling2D((2, 2)),
# Max pooling
MaxPooling2D((2, 2)),
CNN MODEL
# Max pooling
MaxPooling2D((2, 2)),
# Max pooling
Flatten(),
Dense(128, activation='relu'),
Dropout(0.5),
])
model.save('/content/crack_detection_model.h5')
files.download('/content/crack_detection_model.h5')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.show()