mirror of
https://github.com/jantic/DeOldify.git
synced 2026-11-03 22:44:30 +08:00
59 KiB
59 KiB
In [ ]:
import os
os.environ['CUDA_VISIBLE_DEVICES']='3' In [ ]:
%matplotlib inline
%reload_ext autoreload
%autoreload 2In [ ]:
import fastai
from fastai import *
from fastai.vision import *
from fastai.callbacks import *
from fastai.vision.gan import *
from fasterai.dataset import *
from fasterai.visualize import *
from fasterai.tensorboard import *
from fasterai.loss import *
from fasterai.filters import *
from fasterai.generators import *
from pathlib import Path
from itertools import repeat
plt.style.use('dark_background')
torch.backends.cudnn.benchmark=TrueIn [ ]:
#Dummy data path- shouldn't pull any images.
path = Path('./')
#The higher the render_factor, the more GPU memory will be used and generally images will look better.
#11GB can take a factor of 42 max. Performance generally gracefully degrades with lower factors,
#though you may also find that certain images will actually render better at lower numbers.
#This tends to be the case with the oldest photos.
render_factor=16In [ ]:
def colorize_gen_learner_exp(data:ImageDataBunch, gen_loss=FeatureLoss(), arch=models.resnet34):
return unet_learner3(data, arch, wd=1e-3, blur=True, norm_type=NormType.Spectral,
self_attention=True, y_range=(-3.,3.), loss_func=gen_loss, nf_factor=1.5)In [ ]:
data = get_colorize_data(sz=128, bs=32, crappy_path=path, good_path=path, keep_pct=0.01)
learn = colorize_gen_learner_exp(data=data)
learn.path = Path('data/imagenet/ILSVRC/Data/CLS-LOC/bandw')
learn.load('colorize3_gen_96')
learn.model.eval()
filtr = MasterFilter([ColorizerFilter(learn=learn)], render_factor=render_factor)
vis = ModelImageVisualizer(filtr, results_dir='result_images')In [ ]:
vis.plot_transformed_image("test_images/1852GatekeepersWindsor.jpg")In [ ]:
vis.plot_transformed_image("test_images/Chief.jpg")In [ ]:
vis.plot_transformed_image("test_images/1850SchoolForGirls.jpg")In [ ]:
vis.plot_transformed_image("test_images/AtlanticCityBeach1905.jpg")In [ ]:
vis.plot_transformed_image("test_images/CottonMillWorkers1913.jpg")In [ ]:
vis.plot_transformed_image("test_images/BrooklynNavyYardHospital.jpg")In [ ]:
vis.plot_transformed_image("test_images/FinnishPeasant1867.jpg")In [ ]:
vis.plot_transformed_image("test_images/AtlanticCity1905.png")In [ ]:
vis.plot_transformed_image("test_images/PushingCart.jpg")In [ ]:
vis.plot_transformed_image("test_images/Drive1905.jpg")In [ ]:
vis.plot_transformed_image("test_images/IronLung.png")In [ ]:
vis.plot_transformed_image("test_images/FamilyWithDog.jpg")In [ ]:
vis.plot_transformed_image("test_images/DayAtSeaBelgium.jpg")In [ ]:
vis.plot_transformed_image("test_images/marilyn_woods.jpg")In [ ]:
vis.plot_transformed_image("test_images/OldWomanSweden1904.jpg")In [ ]:
vis.plot_transformed_image("test_images/WomenTapingPlanes.jpg")In [ ]:
vis.plot_transformed_image("test_images/overmiller.jpg")In [ ]:
vis.plot_transformed_image("test_images/BritishDispatchRider.jpg")In [ ]:
vis.plot_transformed_image("test_images/MuseauNacionalDosCoches.jpg")In [ ]:
vis.plot_transformed_image("test_images/abe.jpg")In [ ]:
vis.plot_transformed_image("test_images/RossCorbettHouseCork.jpg")In [ ]:
vis.plot_transformed_image("test_images/HPLabelleOfficeMontreal.jpg")In [ ]:
vis.plot_transformed_image("test_images/einstein_beach.jpg")In [ ]:
vis.plot_transformed_image("test_images/airmen1943.jpg")In [ ]:
vis.plot_transformed_image("test_images/20sWoman.jpg")In [ ]:
vis.plot_transformed_image("test_images/egypt-1.jpg")In [ ]:
vis.plot_transformed_image("test_images/Rutherford_Hayes.jpg")In [ ]:
vis.plot_transformed_image("test_images/einstein_portrait.jpg")In [ ]:
vis.plot_transformed_image("test_images/pinkerton.jpg")In [ ]:
vis.plot_transformed_image("test_images/WaltWhitman.jpg")In [ ]:
vis.plot_transformed_image("test_images/dorothea-lange.jpg")In [ ]:
vis.plot_transformed_image("test_images/Hemmingway2.jpg")In [ ]:
vis.plot_transformed_image("test_images/hemmingway.jpg")In [ ]:
vis.plot_transformed_image("test_images/smoking_kid.jpg")In [ ]:
vis.plot_transformed_image("test_images/teddy_rubble.jpg")In [ ]:
vis.plot_transformed_image("test_images/dustbowl_2.jpg")In [ ]:
vis.plot_transformed_image("test_images/camera_man.jpg")In [ ]:
vis.plot_transformed_image("test_images/migrant_mother.jpg")In [ ]:
vis.plot_transformed_image("test_images/marktwain.jpg")In [ ]:
vis.plot_transformed_image("test_images/HelenKeller.jpg")In [ ]:
vis.plot_transformed_image("test_images/Evelyn_Nesbit.jpg")In [ ]:
vis.plot_transformed_image("test_images/Eddie-Adams.jpg")In [ ]:
vis.plot_transformed_image("test_images/soldier_kids.jpg")In [ ]:
vis.plot_transformed_image("test_images/AnselAdamsYosemite.jpg")In [ ]:
vis.plot_transformed_image("test_images/unnamed.jpg")In [ ]:
vis.plot_transformed_image("test_images/workers_canyon.jpg")In [ ]:
vis.plot_transformed_image("test_images/CottonMill.jpg")In [ ]:
vis.plot_transformed_image("test_images/JudyGarland.jpeg")In [ ]:
vis.plot_transformed_image("test_images/kids_pit.jpg")In [ ]:
vis.plot_transformed_image("test_images/last_samurai.jpg")In [ ]:
vis.plot_transformed_image("test_images/AnselAdamsWhiteChurch.jpg")In [ ]:
vis.plot_transformed_image("test_images/opium.jpg")In [ ]:
vis.plot_transformed_image("test_images/dorothea_lange_2.jpg")In [ ]:
vis.plot_transformed_image("test_images/rgs.jpg")In [ ]:
vis.plot_transformed_image("test_images/wh-auden.jpg")In [ ]:
vis.plot_transformed_image("test_images/w-b-yeats.jpg")In [ ]:
vis.plot_transformed_image("test_images/marilyn_portrait.jpg")In [ ]:
vis.plot_transformed_image("test_images/wilson-slaverevivalmeeting.jpg")In [ ]:
vis.plot_transformed_image("test_images/ww1_trench.jpg")In [ ]:
vis.plot_transformed_image("test_images/women-bikers.png")In [ ]:
vis.plot_transformed_image("test_images/Unidentified1855.jpg")In [ ]:
vis.plot_transformed_image("test_images/skycrapper_lunch.jpg")In [ ]:
vis.plot_transformed_image("test_images/sioux.jpg")In [ ]:
vis.plot_transformed_image("test_images/school_kids.jpg")In [ ]:
vis.plot_transformed_image("test_images/royal_family.jpg")In [ ]:
vis.plot_transformed_image("test_images/redwood_lumberjacks.jpg")In [ ]:
vis.plot_transformed_image("test_images/poverty.jpg")In [ ]:
vis.plot_transformed_image("test_images/paperboy.jpg")In [ ]:
vis.plot_transformed_image("test_images/NativeAmericans.jpg")In [ ]:
vis.plot_transformed_image("test_images/helmut_newton-.jpg")In [ ]:
vis.plot_transformed_image("test_images/Greece1911.jpg")In [ ]:
vis.plot_transformed_image("test_images/FatMenClub.jpg")In [ ]:
vis.plot_transformed_image("test_images/EgyptColosus.jpg")In [ ]:
vis.plot_transformed_image("test_images/egypt-2.jpg")In [ ]:
vis.plot_transformed_image("test_images/dustbowl_sd.jpg")In [ ]:
vis.plot_transformed_image("test_images/dustbowl_people.jpg")In [ ]:
vis.plot_transformed_image("test_images/dustbowl_5.jpg")In [ ]:
vis.plot_transformed_image("test_images/dustbowl_1.jpg")In [ ]:
vis.plot_transformed_image("test_images/DriveThroughGiantTree.jpg")In [ ]:
vis.plot_transformed_image("test_images/covered-wagons-traveling.jpg")In [ ]:
vis.plot_transformed_image("test_images/civil-war_2.jpg")In [ ]:
vis.plot_transformed_image("test_images/civil_war_4.jpg")In [ ]:
vis.plot_transformed_image("test_images/civil_war_3.jpg")In [ ]:
vis.plot_transformed_image("test_images/civil_war.jpg")In [ ]:
vis.plot_transformed_image("test_images/BritishSlum.jpg")In [ ]:
vis.plot_transformed_image("test_images/bicycles.jpg")In [ ]:
vis.plot_transformed_image("test_images/brooklyn_girls_1940s.jpg")In [ ]:
vis.plot_transformed_image("test_images/40sCouple.jpg")In [ ]:
vis.plot_transformed_image("test_images/1946Wedding.jpg")In [ ]:
vis.plot_transformed_image("test_images/Dolores1920s.jpg")In [ ]:
vis.plot_transformed_image("test_images/TitanicGym.jpg")In [ ]:
vis.plot_transformed_image("test_images/FrenchVillage1950s.jpg")In [ ]:
vis.plot_transformed_image("test_images/ClassDivide1930sBrittain.jpg")In [ ]:
vis.plot_transformed_image("test_images/1870sSphinx.jpg")Warning:
Output truncated. This notebook contains too many cells to display efficiently.