Skip to content

Instantly share code, notes, and snippets.

View vaibhavcodes's full-sized avatar

Vaibhav Khandelwal vaibhavcodes

View GitHub Profile
@vaibhavcodes
vaibhavcodes / VGG16_creation_of_model.py
Created July 12, 2020 17:26
VGG16- Creation of model
model = keras.Sequential()
# Adding pre-trained model layers
model.add(model_vgg)
# Flattening the image pixels
model.add(Flatten())
# Adding 2 dense layers with 4096 neurons
model.add(Dense(4096, activation='relu'))
@vaibhavcodes
vaibhavcodes / VGG16_Preventing_16layers_to_be_trained.py
Created July 12, 2020 17:24
VGG16- Preventing the 16 convolution layers to be trained
model_vgg.trainable = False
@vaibhavcodes
vaibhavcodes / VGG16_Pretrained_model_weights.py
Created July 12, 2020 17:20
VGG16- Downloading the pre-trained model weights of VGG16 model trained on imagenet dataset
# The entire network is present under VGG16 feature extractor
from keras.applications.vgg16 import VGG16
model_vgg = VGG16(weights='imagenet', include_top=False, input_shape= (224,224,3))
# include_top: Whether to include the 3 fully-connected layers at the top of the network.
# weights: 'imagenet' (pre-training on ImageNet), or the path to the weights file to be loaded.
# input_shape: optional shape tuple, only to be specified if include_top is False
# (otherwise the input shape has to be (224, 224, 3) (with channels_last data format)
@vaibhavcodes
vaibhavcodes / VGG16_Predicting_label_of_loaded_image.py
Created July 12, 2020 17:10
VGG16- Predicting the label of the loaded image
# Predicting the loaded image
output = model.predict(test_img)
# Condition of checking the label of the loaded or tested image
if output[0][0] > output[0][1]:
print("Cat")
else:
print("Dog")
@vaibhavcodes
vaibhavcodes / VGG16_Converting_loaded_image_into_array.py
Created July 12, 2020 17:07
VGG16- Converting the loaded image into array
# Converting image to array
test_img = np.asarray(test_img)
# Expanding the dimensions
test_img = np.expand_dims(test_img, axis=0)
@vaibhavcodes
vaibhavcodes / VGG16_Loading_image_for_testing.py
Created July 12, 2020 17:04
VGG16- Loading the image for testing
# Load the testing image
test_img = image.load_img(r"/content/cat.jpg", target_size=(224,224))
test_img
@vaibhavcodes
vaibhavcodes / VGG16_Fitting_model.py
Created July 12, 2020 17:02
VGG16- Fitting of Model
# Fitting the model
result = model.fit_generator(steps_per_epoch=100, generator=training_data, verbose=1, validation_data=testing_data, epochs=50 )
@vaibhavcodes
vaibhavcodes / VGG16_Compiling_model.py
Created July 12, 2020 17:01
VGG16- Compilation of model
# Compiling the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
@vaibhavcodes
vaibhavcodes / VGG16_Summary_of_model.py
Created July 12, 2020 16:42
VGG16- Summary of the model
# Getting the summary of the model
model.summary()
@vaibhavcodes
vaibhavcodes / VGG16_Creating_model.py
Created July 12, 2020 16:40
VGG16- Creation of Model
# Initializing a Sequential model
model = Sequential()
# Creating first block- (2 Convolution + 1 Max pool)
model.add(Conv2D(filters= 64, kernel_size= (3,3), strides= (1,1), padding='same', input_shape= (224, 224, 3), activation= 'relu'))
model.add(Conv2D(filters= 64, kernel_size= (3,3), strides= (1,1), padding='same', activation= 'relu'))
model.add(MaxPool2D(pool_size= (2,2), strides=(2,2)))
# Creating second block- (2 Convolution + 1 Max pool)
model.add(Conv2D(filters= 128, kernel_size= (3,3), strides= (1,1), padding='same', activation= 'relu'))