-
Notifications
You must be signed in to change notification settings - Fork 0
/
incep.py
91 lines (67 loc) · 2.73 KB
/
incep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
"""incep.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1BuiorjP68IjFpbWA76JTzkZPYcqq0sgM
"""
from google.colab import drive
drive.mount('/content/drive')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 26 12:56:41 2020
@author: harshit
"""
from tensorflow.keras.models import Model
import tensorflow as tf
from tensorflow.keras.layers import Dense, Dropout, BatchNormalization, GlobalAveragePooling2D
# Initialising the CNN
classifier_base = tf.keras.applications.InceptionV3(input_shape = (75,75,3),
include_top=False
)
x = classifier_base.output
x = GlobalAveragePooling2D()(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
predictions = Dense(1, activation = 'sigmoid')(x)
classifier = Model(classifier_base.input,predictions)
# Compiling the CNN
classifier_base.summary()
classifier_base.trainable = False
classifier.summary()
# Convolutional Neural Network
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
# Installing Theano
# pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
# Installing Tensorflow
# pip install tensorflow
# Part 2 - Fitting the CNN to the images
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('/content/drive/My Drive/covid-dataset/training_set',
target_size = (75, 75),
batch_size = 32,
class_mode = 'binary')
test_set = test_datagen.flow_from_directory('/content/drive/My Drive/covid-dataset/test_set',
target_size = (75, 75),
batch_size = 32,
class_mode = 'binary')
from keras.callbacks import EarlyStopping
classifier.fit(training_set,
epochs = 15,
validation_data = test_set)
# classifier.save("vgg166.h5")
import matplotlib.pyplot as plt
plt.plot(classifier.history.history['accuracy'])
plt.plot(classifier.history.history['val_accuracy'])
plt.plot(classifier.history.history['loss'])
plt.plot(classifier.history.history['val_loss'])
plt.title("model accuracy")
plt.ylabel("Accuracy")
plt.xlabel("Epoch")
plt.legend(["Accuracy","Validation Accuracy","loss","Validation Loss"])
plt.show()