Skip to content

Instantly share code, notes, and snippets.

View prateekjoshi565's full-sized avatar
🎯
Focusing

Prateek Joshi prateekjoshi565

🎯
Focusing
View GitHub Profile
from PIL import Image, ImageDraw, ImageFont
import matplotlib.pyplot as plt
import io
# generate video
create_video_from_images("/images", "out.mp4")
def create_video_from_images(images_folder, output_video, fps=10, duration=6):
images = sorted(os.listdir(images_folder))
# create path to the input images
img_path = os.path.join(images_folder, images[0])
# load image
frame = cv2.imread(img_path)
# extract dimensions of the image
height, width, channels = frame.shape
import cv2 # (OpenCV) version - 4.7.0
import os
cnt = 0
for img in tqdm_notebook(col_images):
# apply frame mask
masked = cv2.bitwise_and(img[:,:,0], img[:,:,0], mask=stencil)
# apply image thresholding
ret, thresh = cv2.threshold(masked, 130, 145, cv2.THRESH_BINARY)
# specify frame index
idx = 457
# plot frame
plt.figure(figsize=(10,10))
plt.imshow(col_images[idx][:,:,0], cmap= "gray")
plt.show()
def get_relation(sent):
doc = nlp(sent)
# Matcher class object
matcher = Matcher(nlp.vocab)
#define the pattern
pattern = [{'DEP':'ROOT'},
{'DEP':'prep','OP':"?"},
@prateekjoshi565
prateekjoshi565 / text_preprocessing_elmo.py
Created March 6, 2019 18:33
text preprocessing elmo
# remove punctuation marks
punctuation = '!"#$%&()*+-/:;<=>?@[\\]^_`{|}~'
train['clean_tweet'] = train['clean_tweet'].apply(lambda x: ''.join(ch for ch in x if ch not in set(punctuation)))
test['clean_tweet'] = test['clean_tweet'].apply(lambda x: ''.join(ch for ch in x if ch not in set(punctuation)))
# convert text to lowercase
train['clean_tweet'] = train['clean_tweet'].str.lower()
test['clean_tweet'] = test['clean_tweet'].str.lower()
# extract subject
source = [i[0] for i in entity_pairs]
# extract object
target = [i[1] for i in entity_pairs]
kg_df = pd.DataFrame({'source':source, 'target':target, 'edge':relations})
# predict next token
def predict(net, tkn, h=None):
# tensor inputs
x = np.array([[token2int[tkn]]])
inputs = torch.from_numpy(x)
# push to GPU
inputs = inputs.cuda()