<jupyter_start><jupyter_text>Image Data Agumentation<jupyter_code>#setting parameter for Image Data agumentation to the traing data
train_datagen=ImageDataGenerator(rescale=1./255,shear_range=0.2,zoom_range=0.2,horizontal_flip=True)
#Image Data agumentation to the testing data
test_datagen=ImageDataGenerator(rescale=1./255)<jupyter_output><empty_output><jupyter_text>Loading our data and performing data agumentation<jupyter_code>#performing data agumentation to train data
x_train=train_datagen.flow_from_directory(directory=r'D:\personal\ECG\ECG-main\data\train'
                                          ,target_size=(64,64),batch_size=32,class_mode='categorical')
#performing data agumentation to test data
x_test=test_datagen.flow_from_directory(directory=r'D:\personal\ECG\ECG-main\data\test'
                                        ,target_size=(64,64),batch_size=32,class_mode='categorical')
print(x_train.class_indices)#checking the number of classes
from collections import Counter as c
c(x_train.labels)<jupyter_output><empty_output><jupyter_text>Creating the model<jupyter_code># create model
model=Sequential()
# adding model layer
model.add(Conv2D(32,(3,3),input_shape=(64,64,3),activation='relu'))#convolutional layer
model.add(MaxPooling2D(pool_size=(2,2))) #MaxPooling2D-for downsampling the input

model.add(Conv2D(32,(3,3),activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())#flatten the dimension of the image
model.add(Dense(32))#deeply connected neural network layers.
model.add(Dense(6,activation='softmax'))#output layer with 6 neurons

model.summary()#summary of our model
# Compile model
model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
model.fit_generator(generator=x_train,steps_per_epoch = len(x_train),
                    epochs=10, validation_data=x_test,validation_steps = len(x_test))
# Save the model
model.save('ECG.h5')
from tensorflow.keras.models import load_model
from keras.preprocessing import image
model = load_model("ECG.h5") #loading the model for testing
img = image.load_img(r"D:\personal\ECG\ECG-main\Flask\uploads\PAC.png",target_size= (64,64))#loading of the image
x = image.img_to_array(img)#image to array
x = np.expand_dims(x,axis = 0)#changing the shape
pred = model.predict_classes(x)#predicting the classes
pred
index=['Left Bundle Branch Block','Normal','Premature Atrial Contraction',
       'Premature Ventricular Contractions', 'Right Bundle Branch Block','Ventricular Fibrillation']
result=str(index[pred[0]])
result<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11917701863354037, 'fraction_numerical': 0.023291925465838508, 'mean_word_length': 6.832826747720365, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '557804', 'license': 'MIT', 'n_tokens_mistral': 883, 'n_tokens_neox': 844, 'n_words': 154, 'path': 'Training/arrhythmia Classification.ipynb', 'repo_name': 'sushmamareddy/Arrhythmia-classification-using-Deep-Learning', 'size': '2576'}