This file contains hidden or 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
| %%writefile app.py | |
| import pickle | |
| import streamlit as st | |
| # loading the trained model | |
| pickle_in = open('classifier.pkl', 'rb') | |
| classifier = pickle.load(pickle_in) | |
| @st.cache() |
This file contains hidden or 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
| # defining two strings | |
| string_1 = 'euclidean' | |
| string_2 = 'manhattan' |
This file contains hidden or 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
| #standard deviation for noise to be added in the image | |
| sigma=0.155 | |
| #add random noise to the image | |
| noisyRandom = random_noise(image,var=sigma**2) | |
| plt.imshow(noisyRandom) | |
| plt.title('Random Noise') |
This file contains hidden or 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
| final_train_data = [] | |
| final_target_train = [] | |
| for i in tqdm(range(train_x.shape[0])): | |
| final_train_data.append(train_x[i]) | |
| final_train_data.append(rotate(train_x[i], angle=45, mode = 'wrap')) | |
| final_train_data.append(np.fliplr(train_x[i])) | |
| final_train_data.append(np.flipud(train_x[i])) | |
| final_train_data.append(random_noise(train_x[i],var=0.2**2)) | |
| for j in range(5): | |
| final_target_train.append(train_y[i]) |
This file contains hidden or 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
| torch.manual_seed(0) | |
| class Net(Module): | |
| def __init__(self): | |
| super(Net, self).__init__() | |
| self.cnn_layers = Sequential( | |
| # Defining a 2D convolution layer | |
| Conv2d(3, 16, kernel_size=3, stride=1, padding=1), | |
| ReLU(inplace=True), |
This file contains hidden or 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
| # Add on classifier | |
| model.classifier[6] = Sequential( | |
| Linear(4096, 2)) | |
| for param in model.classifier[6].parameters(): | |
| param.requires_grad = True |
This file contains hidden or 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
| class Net(Module): | |
| def __init__(self): | |
| super(Net, self).__init__() | |
| self.cnn_layers = Sequential( | |
| # Defining a 2D convolution layer | |
| Conv2d(1, 4, kernel_size=3, stride=1, padding=1), | |
| BatchNorm2d(4), | |
| ReLU(inplace=True), | |
| MaxPool2d(kernel_size=2, stride=2), |
This file contains hidden or 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
| # initializing two arrays | |
| a = np.array(2) | |
| b = np.array(1) | |
| print(a,b) |
This file contains hidden or 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
| # checking the accuracy of the predicted tags | |
| from sklearn.metrics import accuracy_score | |
| accuracy_score(predict, actual)*100 |
This file contains hidden or 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
| for img_path in img_paths: | |
| print (img_path) | |
| mat = io.loadmat(img_path.replace('.jpg','.mat').replace('images','ground-truth').replace('IMG_','GT_IMG_')) | |
| img= plt.imread(img_path) | |
| k = np.zeros((img.shape[0],img.shape[1])) | |
| gt = mat["image_info"][0,0][0,0][0] | |
| for i in range(0,len(gt)): | |
| if int(gt[i][1])<img.shape[0] and int(gt[i][0])<img.shape[1]: | |
| k[int(gt[i][1]),int(gt[i][0])]=1 | |
| k = gaussian_filter_density(k) |