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
# adapted from: https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson7-superres.ipynb | |
t = data.valid_ds[0][1].data | |
t = torch.stack([t,t]) | |
def gram_matrix(x): | |
n,c,h,w = x.size() | |
x = x.view(n, c, -1) | |
return (x @ x.transpose(1,2))/(c*h*w) |
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
bs,size=64,128 | |
# bs,size=8,480 | |
arch = models.resnet34 | |
src = ImageImageList.from_folder(path_lr).split_by_rand_pct(0.1, seed=42) | |
tfms = get_transforms(do_flip=True, flip_vert=True, max_zoom = 1.1, max_lighting=0.2, max_rotate = 10) | |
def get_data(bs,size=None): |
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
data = get_data(bs=64,size=128) | |
learn = None | |
gc.collect() | |
wd = 1e-3 | |
learn = unet_learner(data, arch, wd=wd, loss_func=feat_loss, callback_fns=LossMetrics,blur=True, norm_type=NormType.Weight) |
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
lr = 1e-2 | |
def do_fit(save_name, lrs=slice(lr), pct_start=0.9, cycles = 10): | |
learn.fit_one_cycle(cycles, lrs, pct_start=pct_start) | |
learn.save(save_name) | |
learn.show_results(rows=2, imgsize=7) | |
do_fit('1a', slice(lr)) |
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
data = get_data(bs=1) | |
learn.data = data | |
learn.freeze() | |
gc.collect() | |
learn.load('2b') | |
lr = 1e-6 |
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
learn = load_learner("/content/drive/My Drive/video_restorer4/") | |
def run_inference_images(file, dest): | |
img = open_image(file) | |
p,img_hr,b = learn.predict(img) | |
# Image(img_hr).save(dest) | |
# plt.figure(figsize=(25,25)) | |
Image(img_hr).show(figsize=(25,25)) |
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
mport PIL | |
import glob | |
import os | |
from tqdm.notebook import tqdm | |
render_factor = 40 | |
if os.path.exists('imagepaths.txt'): | |
os.remove('imagepaths.txt') |
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 | |
import numpy as np | |
import os | |
clean = 'seinfeld_inference.mp4' | |
cap = cv2.VideoCapture(clean) | |
clean_fps = cap.get(cv2.CAP_PROP_FPS) | |
print(clean_fps) | |
pathOut = '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
# download grain video | |
rm -Rf build | |
YT_GRAIN_OVERLAY="https://www.youtube.com/watch?v=J_MZb7qTenE" | |
mkdir -p build | |
youtube-dl "$YT_GRAIN_OVERLAY" -f mp4 --output "build/grain.mp4" | |
# invert colors | |
ffmpeg -loglevel quiet -y -i "build/grain.mp4" -vf negate 'color_inverted.mp4' | |
# overlay video | |
ffmpeg \ | |
-y \ |
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 EmbeddingDot(nn.Module): | |
def __init__(self): | |
super().__init__() | |
self.u.weight.data.uniform_(0,0.05) | |
self.m.weight.data.uniform_(0,0.05) |
OlderNewer