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 numpy as np | |
import os | |
import cv2 | |
import torchvision | |
import torch | |
import json | |
def numpy_nms(boxes, scores, iou_threshold): |
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
file="/mnt/disk2/users/milad/videos/final_match.mp4" | |
output_dir="/mnt/disk2/users/milad/output" | |
input_file="$file" | |
filename=$(basename -- "$input_file") | |
filename_noext="${filename%.*}" | |
output_file="$output_dir/${filename_noext}.mp4" | |
# Reduce video size using ffmpeg |
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 cv2 | |
improt numpy as np | |
def draw_rotated_text(image: np.ndarray, main_text: str) -> np.ndarray: | |
main_font_face = cv2.FONT_HERSHEY_SIMPLEX | |
main_font_scale = 0.4 | |
main_thickness = 1 | |
main_text_size, _ = cv2.getTextSize(main_text, main_font_face, main_font_scale, main_thickness) | |
main_baseline = main_text_size[1] + main_thickness | |
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
# pip install pycocotools | |
from pycocotools.coco import COCO | |
import json | |
def merge_coco_json(json_files, output_file): | |
merged_annotations = { | |
"info": {}, | |
"licenses": [], | |
"images": [], | |
"annotations": [], |
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 io | |
import base64 | |
from IPython.display import HTML | |
video = io.open('21590891783.mp4', 'r+b').read() | |
encoded = base64.b64encode(video) | |
HTML(data=''' | |
<video controls> | |
<source src="data:video/mp4;base64,{0}" type="video/mp4" /> |
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
from PIL import Image | |
from PIL import ImageOps | |
import os | |
import random | |
# set the path to the directory containing the images | |
input_path = "/path/.../input" | |
output_path = "/path/.../output" | |
# loop through each image file in the directory |
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 tensorflow as tf | |
from gensim.corpora import WikiCorpus | |
import os | |
import argparse | |
# lang = 'fa' farsi | |
def store(corpus, lang): | |
base_path = os.getcwd() | |
store_path = os.path.join(base_path, '{}_corpus'.format(lang)) |
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
from simpletransformers.language_modeling import LanguageModelingModel | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
transformers_logger = logging.getLogger("transformers") | |
transformers_logger.setLevel(logging.WARNING) | |
train_args = { |
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 tensorflow | |
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
# Create training ImageDataGenerator object | |
train_data_gen = ImageDataGenerator(rotation_range=50, | |
width_shift_range=0.2, | |
height_shift_range=0.2, | |
zoom_range=0.3, | |
horizontal_flip=True, | |
vertical_flip=True, |
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 tensorflow | |
from PIL import Image | |
import glob | |
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
from tensorflow.keras.preprocessing.image import img_to_array | |
from tensorflow.keras.preprocessing.image import load_img | |
import numpy as np | |
aug = ImageDataGenerator( | |
rotation_range=30, |