Skip to content

Instantly share code, notes, and snippets.

View priya-dwivedi's full-sized avatar

Priyanka Dwivedi priya-dwivedi

  • Deep Learning Consultant
  • Toronto, Canada
View GitHub Profile
class CustomDataset(utils.Dataset):
def load_custom(self, dataset_dir, subset):
"""Load a subset of the Balloon dataset.
dataset_dir: Root directory of the dataset.
subset: Subset to load: train or val
"""
# Add classes. We have only one class to add.
self.add_class("damage", 1, "damage")
def distance_boxes (boxA, boxB):
import math
center_boxA = [(boxA[0] + boxA[2])/ 2.0, (boxA[1] + boxA[3])/2.0]
center_boxB = [(boxB[0] + boxB[2])/ 2.0, (boxB[1] + boxB[3])/2.0]
pixel_distance = math.sqrt( ((center_boxA[0]-center_boxB[0])**2)+((center_boxA[1]-center_boxB[1])**2) )
return pixel_distance
@priya-dwivedi
priya-dwivedi / social_distancing.py
Created May 6, 2020 11:10
modeling social distance
def model_distancing(df, proximity):
print("Simulation Started")
time1 = time.time()
max_frame = df['frame_num'].max()
for frame_num in range(3, max_frame):
pairs_done = []
if frame_num % 50 == 0:
print("Completed: ", frame_num)
## Look at all tracks in this frame
@priya-dwivedi
priya-dwivedi / extract_programming_languages.py
Created May 28, 2020 14:41
Extract Programming Languages from a resume
import docx2txt
def extract_programming_languages(file_name):
# read in word file
result = docx2txt.process(file_name)
programming_languages_pattern = re.search(r'Programming Languages:[A-Za-z,\s0-9]*\.',result)
print(programming_languages_pattern)
programming_languages_line = programming_languages_pattern.group(0)
languages = re.sub("Programming Languages: ","", programming_languages_line)
@priya-dwivedi
priya-dwivedi / kg_matthew.py
Created May 28, 2020 14:51
Knowledge Graph for a single candidate
import networkx as nx
edge_dict = {}
edge_dict['Mathew'] = languages_mathew
# create a directed-graph from a dataframe
G=nx.from_dict_of_lists(edge_dict,create_using=nx.MultiDiGraph())
plt.figure(figsize=(12,12))
pos = nx.spring_layout(G)
nx.draw(G, with_labels=True, node_color='skyblue', edge_cmap=plt.cm.Blues, pos = pos, node_size = 4500)
plt.show()
@priya-dwivedi
priya-dwivedi / kg_all_candidates.py
Created May 28, 2020 14:58
Knowldge Graph for all the candidates
edge_dict = {}
edge_dict[names[0]] = languages1
edge_dict[names[1]] = languages2
edge_dict[names[2]] = languages2
G=nx.from_dict_of_lists(edge_dict,create_using=nx.MultiDiGraph())
plt.figure(figsize=(12,12))
pos = nx.circular_layout(G)
@priya-dwivedi
priya-dwivedi / traverse_kg.py
Created May 28, 2020 15:37
Traverse a Knowledge Graph
def get_max_degree_node(list_of_nodes_to_eliminate, G):
max_degree=0
all_remaining_nodes = [x for x in G.nodes() if x not in list_of_nodes_to_eliminate]
max_node=all_remaining_nodes[0]
for node in all_remaining_nodes:
degree = G.degree(node)
if degree>max_degree:
max_degree = degree
max_node = node
return max_degree, max_node
@priya-dwivedi
priya-dwivedi / detr_class.py
Created June 8, 2020 17:06
DETR inference block
class DETRdemo(nn.Module):
"""
Demo DETR implementation.
Demo implementation of DETR in minimal number of lines, with the
following differences wrt DETR in the paper:
* learned positional encoding (instead of sine)
* positional encoding is passed at input (instead of attention)
* fc bbox predictor (instead of MLP)
The model achieves ~40 AP on COCO val5k and runs at ~28 FPS on Tesla V100.
@priya-dwivedi
priya-dwivedi / load_wikihow.py
Created September 2, 2020 15:58
T5 Load WikiHow Data
## Load Data from NLP Library
from nlp import load_dataset
dataset = load_dataset('wikihow', 'all', data_dir='data/')
print(dataset.keys())
print("Size of train dataset: ", dataset['train'].shape)
print("Size of Validation dataset: ", dataset['validation'].shape)
## Look at Sample Examples
print(dataset['train'][0].keys())
print(" Example of text: ", dataset['train'][0]['text'])
print(" Example of Summary: ", dataset['train'][0]['headline'])
@priya-dwivedi
priya-dwivedi / wikihow-dataset.py
Created September 2, 2020 18:52
Pytorch Dataset for Wikihow
class wikihow(Dataset):
def __init__(self, tokenizer, type_path, num_samples, input_length, output_length, print_text=False):
self.dataset = load_dataset('wikihow', 'all', data_dir='data/', split=type_path)
if num_samples:
self.dataset = self.dataset.select(list(range(0, num_samples)))
self.input_length = input_length
self.tokenizer = tokenizer
self.output_length = output_length
self.print_text = print_text