Program
Program
drive.mount('/content/drive')
# Directories
train_dir = '/content/drive/MyDrive/DATASET/TRAIN'
val_dir = '/content/drive/MyDrive/DATASET/TEST'
val_datagen = ImageDataGenerator(rescale=1./255)
# CNN Model
model = Sequential([
MaxPooling2D(2, 2),
MaxPooling2D(2, 2),
MaxPooling2D(2, 2),
Flatten(),
Dense(512, activation='relu'),
Dropout(0.5),
Dense(len(train_generator.class_indices), activation='softmax')
])
OUTPUT:
DCNN:
PROGRAM:
import tensorflow as tf
drive.mount('/content/drive')
# Directories
train_dir = '/content/drive/MyDrive/New folder (2)/train'
val_datagen = ImageDataGenerator(rescale=1./255)
model = Sequential([
BatchNormalization(),
MaxPooling2D(2, 2),
BatchNormalization(),
MaxPooling2D(2, 2),
BatchNormalization(),
MaxPooling2D(2, 2),
BatchNormalization(),
MaxPooling2D(2, 2),
BatchNormalization(),
MaxPooling2D(2, 2),
Flatten(),
Dense(512, activation='relu'),
Dropout(0.5),
Dense(len(train_generator.class_indices), activation='softmax')
])
# Compile the model
model.summary()
plt.ylabel('Accuracy')
plt.legend(loc='best')
plt.grid(True)
plt.show()
OUTPUT:
2.MACHINE LEARNING MODEL:
RANDOM FOREST:
PROGRAM:
import numpy as np
import os
drive.mount('/content/drive')
images = []
labels = []
images.append(img_array)
labels.append(label)
X, y = load_images_from_folder(folder_path)
rf_model.fit(X_train, y_train)
y_pred = rf_model.predict(X_test)
print(f"Accuracy: {accuracy:.2f}")
print("Classification Report:")
print(classification_report(y_test, y_pred))
plt.ylabel('Accuracy')
plt.legend(loc='best')
plt.grid(True)
plt.show()
OUTPUT:
SVM:
PROGRAM:
import numpy as np
import os
drive.mount('/content/drive')
images = []
labels = []
if os.path.isdir(label_folder):
images.append(img_array)
labels.append(label)
X, y = load_images_from_folder(folder_path)
rf_model.fit(X_train, y_train)
y_pred = rf_model.predict(X_test)
print(f"Accuracy: {accuracy:.2f}")
print("Classification Report:")
print(classification_report(y_test, y_pred))
scoring='accuracy', n_jobs=-1)
# Compute mean and standard deviation for training and validation scores
plt.figure(figsize=(10, 6))
plt.title('Learning SVM')
plt.ylabel('Accuracy')
plt.legend(loc='best')
plt.grid(True)
plt.show()
OUTPUT: