<jupyter_start><jupyter_text><jupyter_code>!pip install tensorflow-gpu
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import imread
data_dir = '/content/drive/MyDrive/Data'
test_path = data_dir + '/test/'
train_path = data_dir + '/train/'
test_path
image_shape = (130,130,3)
from tensorflow.keras.preprocessing.image import ImageDataGenerator
image_gen = ImageDataGenerator(rotation_range = 20,
                              width_shift_range = 0.1,
                              height_shift_range=0.1,
                              shear_range = 0.1,
                              zoom_range=0.1,
                              horizontal_flip = True,
                              fill_mode='nearest')
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, MaxPool2D, Dropout,Flatten
model = Sequential()
model.add(Conv2D(filters=32,kernel_size=(3,3),input_shape= image_shape, activation='relu'))
model.add(MaxPool2D(pool_size=(2,2)))

model.add(Conv2D(filters=64,kernel_size=(3,3),input_shape= image_shape, activation='relu'))
model.add(MaxPool2D(pool_size=(2,2)))

model.add(Conv2D(filters=64,kernel_size=(3,3),input_shape= image_shape, activation='relu'))
model.add(MaxPool2D(pool_size=(2,2)))

model.add(Flatten())

model.add(Dense(128,activation='relu'))

model.add(Dropout(0.5))

model.add(Dense(1,activation='sigmoid'))

model.compile(loss = 'binary_crossentropy', optimizer= 'adam',
             metrics=['accuracy'])
from tensorflow.keras.callbacks import EarlyStopping
#early_stop = EarlyStopping(monitor='val_loss',patience=2 )
batch_size = 16
train_image_gen = image_gen.flow_from_directory(train_path,
                                               target_size= image_shape[:2],
                                               color_mode='rgb',
                                               batch_size = batch_size,
                                               class_mode= 'binary')
test_image_gen = image_gen.flow_from_directory(test_path,
                                               target_size= image_shape[:2],
                                               color_mode='rgb',
                                               batch_size = batch_size,
                                               class_mode= 'binary',
                                              shuffle= False)
results = model.fit_generator(train_image_gen, epochs=50,
                              validation_data= test_image_gen)
pred = model.predict_generator(test_image_gen)
predictions = pred > 0.5
from sklearn.metrics import classification_report, confusion_matrix
print(classification_report(test_image_gen.classes,predictions))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09937888198757763, 'fraction_numerical': 0.021191085129704055, 'mean_word_length': 2.2556480380499404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '664963', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 785, 'n_tokens_neox': 757, 'n_words': 122, 'path': 'ImageClassification_CNN.ipynb', 'repo_name': 'akshansh11/Differentiating-the-heat-zones-of-microstructure-by-using-CNN-algorithm', 'size': '2737'}