This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import the required libraries | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#read the image | |
image = cv2.imread('coins.jpg') | |
#calculate the edges using Canny edge algorithm | |
edges = cv2.Canny(image,100,200) | |
#plot the edges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing the required libraries | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
image = cv2.imread('index.png') | |
#using the averaging kernel for image smoothening | |
averaging_kernel = np.ones((3,3),np.float32)/9 | |
filtered_image = cv2.filter2D(image,-1,kernel) | |
plt.imshow(dst) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import required libraries | |
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#show OpenCV version | |
print(cv2.__version__) | |
#read the iamge and convert to grayscale | |
image = cv2.imread('index.png') | |
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import required libraries | |
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#show OpenCV version | |
print(cv2.__version__) | |
#read image and convert to grayscale | |
image = cv2.imread('index.png') | |
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#reading images in grayscale format | |
image1 = cv2.imread('messi.jpg',0) | |
image2 = cv2.imread('team.jpg',0) | |
#finding out the keypoints and their descriptors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import required libraries | |
import numpy as np | |
import cv2 as cv | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#load the classifiers downloaded | |
face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') | |
eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml') | |
#read the image and convert to grayscale format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing required modules | |
from keras.applications import VGG16 | |
#loading the saved model | |
#we are using the complete architecture thus include_top=True | |
model = VGG16(weights='imagenet',include_top=True) | |
#show the summary of model | |
model.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creating a mapping of layer name ot layer details | |
#we will create a dictionary layers_info which maps a layer name to its charcteristics | |
layers_info = {} | |
for i in model.layers: | |
layers_info[i.name] = i.get_config() | |
#here the layer_weights dictionary will map every layer_name to its corresponding weights | |
layer_weights = {} | |
for i in model.layers: | |
layer_weights[i.name] = i.get_weights() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing the required modules | |
from vis.visualization import visualize_activation | |
from vis.utils import utils | |
from keras import activations | |
from keras import applications | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
plt.rcParams['figure.figsize'] = (18,6) | |
#creating a VGG16 model using fully connected layers also because then we can | |
#visualize the patterns for individual category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing required libraries and functions | |
from keras.models import Model | |
#defining names of layers from which we will take the output | |
layer_names = ['block1_conv1','block2_conv1','block3_conv1','block4_conv2'] | |
outputs = [] | |
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2])) | |
#extracting the output and appending to outputs | |
for layer_name in layer_names: | |
intermediate_layer_model = Model(inputs=model.input,outputs=model.get_layer(layer_name).output) | |
intermediate_output = intermediate_layer_model.predict(image) |