Skip to content

Instantly share code, notes, and snippets.

@jchacks
jchacks / predict.py
Last active September 28, 2021 12:07
MLflow mlflow.tensorflow.load_model bug.
# Model code
import tensorflow as tf
from tensorflow.keras import layers
class Model(tf.Module):
def __init__(self, output_size, name="iris_model"):
super().__init__(name=name)
self.d1 = layers.Dense(64, activation='relu')
self.d2 = layers.Dense(64, activation='relu')
@jchacks
jchacks / batch_creation_benchmark.py
Created May 28, 2021 09:54
Machine Learning flat batch creation benchmark script.
import numpy as np
import time
import timeit
batch_size = 5000
datasets = 4
data = [np.ones(100)] * datasets
def opt1():
batches = []
@elbruno
elbruno / moviepyconcatenateandblur.py
Created May 26, 2021 13:23
moviepyconcatenateandblur.py
from moviepy.video.compositing.concatenate import concatenate_videoclips
from skimage.filters import gaussian
from moviepy.editor import VideoFileClip, clips_array, concatenate_videoclips
def blur(image):
""" Returns a blurred (radius=4 pixels) version of the image """
return gaussian(image.astype(float), sigma=4)
# open video and resize to 460
clip1 = VideoFileClip("cat1.mp4").subclip(1,2).resize(width=200)
@ranelpadon
ranelpadon / .zshrc
Last active September 30, 2021 21:14
YouTube Downloader and Trimmer
# Add this to your `~/.bash_profile` or `~/.zshrc` file,
# so that running the Python script in the terminal is more convenient.
# Command: yvt URL START_TIME END_TIME
# Sample: yvt 'https://www.youtube.com/watch?v=RjxKVAOZCQY' 9:41 10:58
yt_video_trimmer() {
python <PATH TO>/yt-video-trimmer.py $1 $2 $3
}
alias yvt=yt_video_trimmer
import moviepy
from moviepy.editor import VideoFileClip, concatenate_videoclips
import glob
files = glob.glob("*." + suffix)
files = [VideoFileClip(file) for file in files]
final_video = concatenate_videoclips(files)
final_video.write_videofile(outputPath.split(".")[0] + ".mp4")
if __name__ == "__main__":
import scipy
import moviepy.editor
grid_size = [3,3]
duration_sec = 5
smoothing_sec = 1.0
image_zoom = 1
fps = 15
random_seed = np.random.randint(0, 999)
@Davi0k
Davi0k / display-text-on-video.py
Last active June 12, 2021 00:03
A small utility function to quickly display text on a video using `moviepy` library
from moviepy.editor import * # pip install moviepy
import argparse # pip install argparse
def display_text_on_video(video: str, text: str, path: str) -> None:
"""
Show text at the center of a video and save the new video version in a specific location.
Parameters:
video (str): The path of the video to edit
text (str): The text to be overlaid on the video
# git clone https://github.com/NVlabs/stylegan2
import os
import numpy as np
from scipy.interpolate import interp1d
from scipy.io import wavfile
import matplotlib.pyplot as plt
import PIL.Image
import moviepy.editor
import dnnlib
import math
from moviepy.editor import concatenate, ImageClip
import os
import platform
import subprocess
import random
import torch
# pip install pytorch-pretrained-biggan
from pytorch_pretrained_biggan import (BigGAN, truncated_noise_sample, convert_to_images)
import numpy as np
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.