text: # -*- coding: utf-8 -*-
  """pneumonia_pred.ipynb
  
  Automatically generated by Colaboratory.
  
  Original file is located at
      https://colab.research.google.com/drive/1gjGGD32pLGLqBHA9amApVj8solFZwor0
  """
  
  from google.colab import drive
   
  drive.mount('/content/gdrive/')
  
  import zipfile
  from google.colab import drive
  
  drive.mount('/content/drive/')
  
  zip_ref = zipfile.ZipFile('/content/real_fake.zip', 'r')
  zip_ref.extractall()
  zip_ref.close()
  
  from keras.layers import Conv2D, Activation, GlobalAvgPool2D, MaxPooling2D, Dropout, Dense, Flatten
  
  from keras.models import Sequential
  
  file1 = ('/content/drive/MyDrive/pneumonia/chest_xray/train')
  
  file2= ('/content/drive/MyDrive/pneumonia/chest_xray/val')
  
  import tensorflow as tf
  from keras import layers
  from tensorflow.keras.preprocessing import image_dataset_from_directory
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
  
  from keras.preprocessing.image import ImageDataGenerator
  
  train_datagen = ImageDataGenerator(rescale = 1./255,
                                     shear_range = 0.05,
                                     zoom_range = 0.05,
                                     horizontal_flip = True)
  
  train_set = train_datagen.flow_from_directory(file1,
                                                   target_size = (384, 384),
                                                   batch_size = 16,
                                                   subset='training',
                                                   class_mode = 'binary')
  
  import matplotlib.pyplot as plt
  
  
  
  test_datagen = ImageDataGenerator(rescale = 1./255)
  
  test_set = test_datagen.flow_from_directory(file2,
                                              target_size = (384, 384),
                                              batch_size = 16,
                                              subset='validation',
                                              class_mode = 'binary')
  
  model = tf.keras.models.Sequential()
  model.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu', input_shape=[384, 384, 3]))
  model.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
  model.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu'))
  model.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
  model.add(tf.keras.layers.Flatten())
  model.add(tf.keras.layers.Dense(units=128, activation='relu'))
  model.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))
  model.compile(optimizer = 'adam', loss='binary_crossentropy', metrics=['accuracy'])
  model.summary()
  
  model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
  
  history = model.fit(train_set, validation_data =test_set, epochs=8, verbose=2)
  
  plt.figure(figsize =(6,4))
  plt.plot(history.history['accuracy'])
  plt.title("Accuracy")
  plt.show()
  
  plt.figure(figsize =(6,4))
  plt.plot(history.history['loss'])
  plt.title("Loss")
  plt.show()
  
  
  
  import cv2
  
  import numpy as np
  
  
  x = plt.imread('/content/pnuem.jpg')
  plt.imshow(x)
  
  x = x/255
  
  x = np.resize(x,(1,384,384,3))
  
  x.shape
  
  classes = list(train_set.class_indices)
  
  print(classes[np.argmax(model.predict(x))])
  
  
  
  