Skip to content

Instantly share code, notes, and snippets.

@PulkitS01
PulkitS01 / app.py
Last active May 25, 2023 11:20
ML_model_deployment_streamlit.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 April 9, 2022 13:07
Distance Functions in Machine Learning
# defining two strings
string_1 = 'euclidean'
string_2 = 'manhattan'
@PulkitS01
PulkitS01 / adding_noise.py
Created November 27, 2019 10:16
Augmentation
#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 June 5, 2020 14:27
Image augmentation
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 November 4, 2019 08:10
Model Improvement: PyTorch
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 October 15, 2019 09:28
Transfer Learning using PyTorch
# Add on classifier
model.classifier[6] = Sequential(
Linear(4096, 2))
for param in model.classifier[6].parameters():
param.requires_grad = True
@PulkitS01
PulkitS01 / cnn_architecture.py
Created September 20, 2019 06:06
CNNs using PyTorch
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 03:19
Introduction to PyTorch
# initializing two arrays
a = np.array(2)
b = np.array(1)
print(a,b)
@PulkitS01
PulkitS01 / accuracy.py
Last active September 28, 2022 21:35
Video Classification
# checking the accuracy of the predicted tags
from sklearn.metrics import accuracy_score
accuracy_score(predict, actual)*100
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)