Skip to content

Instantly share code, notes, and snippets.

@ayulockin
ayulockin / docScanner.py
Created December 25, 2018 08:33
Code to implemet a basic document scanner
import cv2
from scipy.spatial import distance as dist
import numpy as np
def resize(image, width=None, height=None, inter=cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
# check to see if the width is None
if width is None:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ayulockin
ayulockin / understanding_mergesort.py
Last active July 25, 2019 15:14
Understanding MergeSort :D
## DIVIDE -> mergesort
## CONQUER -> mergesort
## COMBINE -> merge
def merge(S1, S2, S):
'''
S1-> First sorted seq
S2-> Second sorted seq
S -> Original seq
'''
def quicksort(S):
if len(S)<2:
print("[RETURNED]length of list less than 2")
return
pivot = S[-1]
print("[INFO] pivot: ", pivot)
L = []
G = []
@ayulockin
ayulockin / linkedListStack.py
Created August 8, 2019 15:49
Stack Implementation Using Linked List
class LinkedStack:
def __init__(self):
self._head = None
self._size = 0
class _node:
__slots__ = '_element', '_nextP'
def __init__(self, element, nextP):
self._element = element
net = Net().to(device)
optimizer = optim.Adam(net.parameters())
wandb.init(project='pytorchw_b')
wandb.watch(net, log='all')
for epoch in range(10):
train(net, device, trainloader, optimizer, epoch)
test(net, device, testloader, classes)
if logwandb:
wandb.log({'lr': lr_schedule.get_lr()[0], 'loss': loss})
lr_finder = LRFinder(net, optimizer, device)
lr_finder.range_test(trainloader, end_lr=10, num_iter=100, logwandb=True)
class NetforExplode(nn.Module):
def __init__(self):
super(NetforExplode, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv1.weight.data.fill_(100)
self.conv1.bias.data.fill_(-100)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.conv2.weight.data.fill_(100)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 32, 3, 1)
torch.nn.init.kaiming_uniform_(self.conv1.weight, mode='fan_in', nonlinearity='relu')
self.conv2 = nn.Conv2d(32, 32, 3, 1)
torch.nn.init.kaiming_uniform_(self.conv2.weight, mode='fan_in', nonlinearity='relu')