This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
OlderNewer