Skip to content

Instantly share code, notes, and snippets.

@PulkitS01
PulkitS01 / app.py
Last active Feb 21, 2021
ML_model_deployment_streamlit.py
View app.py
%%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()
@PulkitS01
PulkitS01 / data_hamming.py
Last active Feb 18, 2020
Distance Functions in Machine Learning
View data_hamming.py
# defining two strings
string_1 = 'euclidean'
string_2 = 'manhattan'
View adding_noise.py
#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')
@PulkitS01
PulkitS01 / augmentation.py
Last active Jun 5, 2020
Image augmentation
View augmentation.py
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])
@PulkitS01
PulkitS01 / batch_norm.py
Created Nov 4, 2019
Model Improvement: PyTorch
View batch_norm.py
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),
@PulkitS01
PulkitS01 / adding_classifier.py
Created Oct 15, 2019
Transfer Learning using PyTorch
View adding_classifier.py
# Add on classifier
model.classifier[6] = Sequential(
Linear(4096, 2))
for param in model.classifier[6].parameters():
param.requires_grad = True
View cnn_architecture.py
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),
@PulkitS01
PulkitS01 / array.py
Last active May 7, 2020
Introduction to PyTorch
View array.py
# initializing two arrays
a = np.array(2)
b = np.array(1)
print(a,b)
@PulkitS01
PulkitS01 / accuracy.py
Last active Mar 15, 2021
Video Classification
View accuracy.py
# checking the accuracy of the predicted tags
from sklearn.metrics import accuracy_score
accuracy_score(predict, actual)*100
View create_density_map.py
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)