mirror of
https://github.com/jantic/DeOldify.git
synced 2026-11-04 23:25:58 +08:00
They were used just to get a ds object which has the denorm function. I just made my own denorm instead. Git 'r done.
44 KiB
44 KiB
In [ ]:
%matplotlib inline
%reload_ext autoreload
%autoreload 2In [ ]:
import multiprocessing
import os
from torch import autograd
from fastai.transforms import TfmType
from fasterai.transforms import *
from fastai.conv_learner import *
from fasterai.images import *
from fasterai.dataset import *
from fasterai.visualize import *
from fasterai.callbacks import *
from fasterai.loss import *
from fasterai.modules import *
from fasterai.training import *
from fasterai.generators import *
from fastai.torch_imports import *
from pathlib import Path
from itertools import repeat
import tensorboardX
plt.style.use('dark_background')
torch.backends.cudnn.benchmark=True
colorizer_device = torch.device('cuda:0')
defader_device = torch.device('cuda:1')
In [ ]:
IMAGENET = Path('data/imagenet/ILSVRC/Data/CLS-LOC/train')
colorizer_path = IMAGENET.parent/('colorize_gen_192.h5')
defader_path = IMAGENET.parent/('defade_rc_gen_256.h5')
default_sz=400
torch.backends.cudnn.benchmark=TrueIn [ ]:
class Generator(nn.Module):
def __init__(self, colorizer, defader):
super().__init__()
self.colorizer = colorizer
self.defader = defader
def forward(self, x):
x = self.colorizer(x).detach().to(device=defader_device)
return self.defader(x)In [ ]:
colorizer = Unet34(nf_factor=2).cuda(device=colorizer_device)
load_model(colorizer, colorizer_path)
colorizer = colorizer.eval()
defader = Unet34(nf_factor=2).cuda(device=defader_device)
load_model(defader, defader_path)
defader = defader.eval()
netG = Generator(colorizer, defader)
netG = netG.eval()In [ ]:
x_tfms = [BlackAndWhiteTransform()]In [ ]:
vis = ModelImageVisualizer(default_sz=default_sz)In [ ]:
vis.plot_transformed_image("test_images/overmiller.jpg", netG, tfms=x_tfms, sz=420)In [ ]:
vis.plot_transformed_image("test_images/einstein_beach.jpg", netG, tfms=x_tfms,sz=600)In [ ]:
vis.plot_transformed_image("test_images/abe.jpg", netG, tfms=x_tfms, sz=480)In [ ]:
vis.plot_transformed_image("test_images/airmen1943.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/20sWoman.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/egypt-1.jpg", netG,sz=480)In [ ]:
vis.plot_transformed_image("test_images/Rutherford_Hayes.jpg", netG, tfms=x_tfms, sz=400)In [ ]:
vis.plot_transformed_image("test_images/einstein_portrait.jpg", netG, tfms=x_tfms, sz=400)In [ ]:
vis.plot_transformed_image("test_images/pinkerton.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/marilyn_woods.jpg", netG, tfms=x_tfms, sz=440)In [ ]:
vis.plot_transformed_image("test_images/WaltWhitman.jpg", netG, tfms=x_tfms, sz=280)In [ ]:
vis.plot_transformed_image("test_images/dorothea-lange.jpg", netG, tfms=x_tfms,sz=460)In [ ]:
vis.plot_transformed_image("test_images/Hemmingway2.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/Chief.jpg", netG, tfms=x_tfms,sz=520)In [ ]:
vis.plot_transformed_image("test_images/hemmingway.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/smoking_kid.jpg", netG, tfms=x_tfms,sz=550)In [ ]:
vis.plot_transformed_image("test_images/teddy_rubble.jpg", netG, tfms=x_tfms, sz=360)In [ ]:
vis.plot_transformed_image("test_images/dustbowl_2.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/camera_man.jpg", netG, tfms=x_tfms,sz=520)In [ ]:
vis.plot_transformed_image("test_images/migrant_mother.jpg", netG, tfms=x_tfms,sz=590)In [ ]:
vis.plot_transformed_image("test_images/marktwain.jpg", netG, tfms=x_tfms, sz=530)In [ ]:
vis.plot_transformed_image("test_images/HelenKeller.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/Evelyn_Nesbit.jpg", netG, tfms=x_tfms, sz=580)In [ ]:
vis.plot_transformed_image("test_images/Eddie-Adams.jpg", netG, tfms=x_tfms, sz=460)In [ ]:
vis.plot_transformed_image("test_images/soldier_kids.jpg", netG, tfms=x_tfms, sz=400)In [ ]:
vis.plot_transformed_image("test_images/AnselAdamsYosemite.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/unnamed.jpg", netG, tfms=x_tfms, sz=550)In [ ]:
vis.plot_transformed_image("test_images/workers_canyon.jpg", netG, tfms=x_tfms,sz=570)In [ ]:
vis.plot_transformed_image("test_images/CottonMill.jpg", netG, tfms=x_tfms,sz=500)In [ ]:
vis.plot_transformed_image("test_images/JudyGarland.jpeg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/kids_pit.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/last_samurai.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/AnselAdamsWhiteChurch.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/opium.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/dorothea_lange_2.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/rgs.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/wh-auden.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/w-b-yeats.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/marilyn_portrait.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/wilson-slaverevivalmeeting.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/ww1_trench.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/women-bikers.png", netG, tfms=x_tfms, sz=450)In [ ]:
vis.plot_transformed_image("test_images/Unidentified1855.jpg", netG, tfms=x_tfms, sz=400)In [ ]:
vis.plot_transformed_image("test_images/skycrapper_lunch.jpg", netG, tfms=x_tfms, sz=550)In [ ]:
vis.plot_transformed_image("test_images/sioux.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/school_kids.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/royal_family.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/redwood_lumberjacks.jpg", netG, tfms=x_tfms, sz=550)In [ ]:
vis.plot_transformed_image("test_images/poverty.jpg", netG, tfms=x_tfms,sz=550)In [ ]:
vis.plot_transformed_image("test_images/paperboy.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/NativeAmericans.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/helmut_newton-.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/Greece1911.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/FatMenClub.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/EgyptColosus.jpg", netG, tfms=x_tfms, sz=400)In [ ]:
vis.plot_transformed_image("test_images/egypt-2.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/dustbowl_sd.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/dustbowl_people.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/dustbowl_5.jpg", netG, tfms=x_tfms, sz=450)In [ ]:
vis.plot_transformed_image("test_images/dustbowl_1.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/DriveThroughGiantTree.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/covered-wagons-traveling.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/civil-war_2.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/civil_war_4.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/civil_war_3.jpg", netG, tfms=x_tfms, sz=550)In [ ]:
vis.plot_transformed_image("test_images/civil_war.jpg", netG, tfms=x_tfms, sz=540)In [ ]:
vis.plot_transformed_image("test_images/BritishSlum.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/bicycles.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/brooklyn_girls_1940s.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/40sCouple.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/1946Wedding.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/Dolores1920s.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/TitanicGym.jpg", netG, tfms=x_tfms, sz=550)In [ ]:
vis.plot_transformed_image("test_images/FrenchVillage1950s.jpg", netG, tfms=x_tfms, sz=440)In [ ]:
vis.plot_transformed_image("test_images/ClassDivide1930sBrittain.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/1870sSphinx.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/1890Surfer.png", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/TV1930s.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/1864UnionSoldier.jpg", netG, tfms=x_tfms, sz=510)In [ ]:
vis.plot_transformed_image("test_images/1890sMedStudents.png", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/BellyLaughWWI.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/PiggyBackRide.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/HealingTree.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/ManPile.jpg", netG, tfms=x_tfms, sz=450)In [ ]:
vis.plot_transformed_image("test_images/1910Bike.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/FreeportIL.jpg", netG, tfms=x_tfms, sz=402)In [ ]:
vis.plot_transformed_image("test_images/DutchBabyCoupleEllis.jpg", netG, tfms=x_tfms, sz=500)In [ ]:
vis.plot_transformed_image("test_images/InuitWoman1903.png", netG, tfms=x_tfms, sz=460)In [ ]:
vis.plot_transformed_image("test_images/1920sDancing.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/AirmanDad.jpg", netG, tfms=x_tfms)In [ ]:
vis.plot_transformed_image("test_images/1910Racket.png", netG, tfms=x_tfms, sz=540)In [ ]:
vis.plot_transformed_image("test_images/1880Paris.jpg", netG, tfms=x_tfms, sz=520)In [ ]:
vis.plot_transformed_image("test_images/Deadwood1860s.png", netG, tfms=x_tfms)Warning:
Output truncated. This notebook contains too many cells to display efficiently.