Skip to content

Instantly share code, notes, and snippets.

@Deepayan137
Deepayan137 / cost_new.py
Created October 29, 2017 08:56
compute costs for differnt methods
import sys
import os
from ocr import GravesOCR
from postproc.dictionary import Dictionary
from parser import read_book
import json
from cost_model import CostModel
from timekeep import Timer
from parser.convert import page_to_unit
import parser.webtotrain as webtotrain
@Deepayan137
Deepayan137 / cost_est.py
Created November 9, 2017 15:43
Pseudo code for cost estimation
def cost_model(**kwargs):
tc, sc = 15, 5
#method = kwargs['method']
in_dictionary = kwargs['included']
not_in_dictionary = kwargs['excluded']
if in_dictionary:
return tc*not_in_dictionary + sc*in_dictionary
else:
return tc*not_in_dictionary
@Deepayan137
Deepayan137 / image_deblurring.py
Created November 10, 2017 10:11
image deblurring
import cv2
import argparse
import numpy as np
import cmath
import pdb
import numpy.matlib
from math import e
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image1", required=True, help="Path to the image")
args = vars(ap.parse_args())
@Deepayan137
Deepayan137 / Praveen_k-nearest.py
Created November 13, 2017 11:16
Implementation of K nearest neighbours on image features
from doctools.cluster.mst import cluster
from doctools.cluster.distance import jaccard, lev, euc
from doctools.parser.convert import page_to_unit
from doctools.parser import webtotrain
from argparse import ArgumentParser
from pprint import pprint
from .dot import as_dot
import json
from functools import partial
import pdb
@Deepayan137
Deepayan137 / cbow_model.py
Last active February 2, 2018 17:27
naive CBOW architecture
class MyCbow():
def __init__(self, vocab_size, embedding_size):
super(MyCbow, self).__init__()
self.w1 = self.initialize(vocab_size, embedding_size)
self.w2 = self.initialize(embedding_size, vocab_size)
self.w1_grad= 0
self.w2_grad = 0
self.embedding = None
self.x = None
def set_params(self, w):
@Deepayan137
Deepayan137 / gravesOCR.py
Created February 3, 2018 14:28
This code returns the text output for a given document image/images
import os
import subprocess
import glob
import numpy as np
import cv2
import sys
import shutil
import pdb
def segmentation(path):
for root, dirs, files in os.walk(path):
@Deepayan137
Deepayan137 / model.py
Created April 13, 2018 09:11
SeqGan model
import torch
import torch.nn as nn
import torch.nn.utils.rnn as rnn_utils
class DiscNet():
def __init__(self, vocab_size, hidden_size, embedding_size, rnn_type, dropout=0.2):
super(DiscNet, self).__init__()
self.hidden_size = hidden_size
self.embedding = nn.Embedding(vocab_size, embedding_size)
self.rnn_type = rnn_type
@Deepayan137
Deepayan137 / vggFace_downloader.py
Created May 27, 2018 09:30
VGG face dataset downloader
import os
import requests
from PIL import Image
import pdb
from tqdm import *
data_path = '/home/saurabh/Facex/data/files'
class NotFound(BaseException):
pass
@Deepayan137
Deepayan137 / lec03.md
Last active August 9, 2018 14:32
RMSE vs. MAE

Root Mean Square error vs Mean Absolute Error

  • RMSE can be defined as a square root of summation over all i { [Yi -(W^T.Xi)]^2 }. We take square of the difference between predicted value and the real value before summing over in order to get rid of negative values, so that the positives and negatives don’t cancel each other out and we are left with an error which is much lesser than the actual error. We then proceed to find W by differentiating the above loss function w.r.t W and equate it to zero.

  • However, it is interesting to note that we don’t have to necessarily take the square of the difference to get rid of the negative values. The same could be achieved by taking the absolute value of the difference between predicted and real values. This is know as Mean Absolute Error or MAE. Summation over all i {abs [ Yi - (W^T.Xi)] }

  • One could argue that why do we take RMSE when MAE less computationally expensive.

The below link beautifully explains why we do that. Do give it a read.

import numpy as np
import random
import pdb
import os
import sys
def update(W, X_vec, n):
W_new = W + n*X_vec
return W_new