mirror of
https://github.com/jantic/DeOldify.git
synced 2026-11-03 22:44:30 +08:00
8.4 KiB
8.4 KiB
In [ ]:
!git clone -b FastAIv1 --single-branch https://github.com/jantic/DeOldify.git DeOldifyIn [ ]:
from os import path
import torch
print(torch.__version__)
print(torch.cuda.is_available())In [ ]:
cd DeOldifyIn [ ]:
!pip install PyDriveIn [ ]:
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
from google.colab import drive
from IPython.display import Image
import fastai
from fastai import *
from fasterai.visualize import *
from pathlib import Path
from itertools import repeat
from google.colab import drive
torch.backends.cudnn.benchmark=TrueIn [ ]:
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)In [ ]:
results_dir=Path('/content/drive/My Drive/deOldifyImages/results')
#Adjust this if image doesn't look quite right (max 64 on 11GB GPU). The default here works for most photos.
#It literally just is a number multiplied by 16 to get the square render resolution.
#Note that this doesn't affect the resolution of the final output- the output is the same resolution as the input.
#Example: render_factor=21 => color is rendered at 16x21 = 336x336 px.
render_factor=36In [ ]:
artistic = False #@param {type:"boolean"}In [ ]:
!mkdir 'models'
if artistic:
!wget https://www.dropbox.com/s/9ne9su2mc5t0m38/ColorizeImagesArtistic_gen.pth?dl=0 -O ./models/ColorizeImagesArtistic_gen.pth
else:
!wget https://www.dropbox.com/s/ztgygpaz1z3jkjg/ColorizeImagesStable_gen.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pthIn [ ]:
from google.colab import drive
drive.mount('/content/drive')In [ ]:
!mkdir "/content/drive/My Drive/deOldifyImages"
!mkdir "/content/drive/My Drive/deOldifyImages/results"In [ ]:
vis = get_image_colorizer(render_factor=render_factor, artistic=artistic)In [ ]:
!wget "https://media.githubusercontent.com/media/jantic/DeOldify/master/test_images/TV1930s.jpg" -O "family_TV.jpg"In [ ]:
vis.plot_transformed_image('family_TV.jpg')In [ ]:
for img in os.listdir("/content/drive/My Drive/deOldifyImages/"):
img_path = str("/content/drive/My Drive/deOldifyImages/") + img
if os.path.isfile(img_path):
vis.plot_transformed_image(img_path)