当前位置:网站首页>Picture coloring project - deoldify

Picture coloring project - deoldify

2022-07-06 11:06:00 zkkkkkkkkkkkkk

Catalog

One 、 Pull Deoldify Project code

Two 、 Download pre training model

        2.1、 step

3、 ... and 、 Color the picture

Four 、 Video coloring


One 、 Pull Deoldify Project code

        git Address :https://github.com/jantic/DeOldify

Two 、 Download pre training model

        2.1、 step

                1) Create in project root models Folder

                             

                2) Download the pre training model file , Upload three files to models Catalog

3、 ... and 、 Color the picture

from deoldify import device
from deoldify.device_id import DeviceId
from deoldify.visualize import *
from pathlib import Path
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = "TRUE"

import warnings
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")



#choices:  CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)
plt.style.use('dark_background')
torch.backends.cudnn.benchmark=True




render_factor=35
result_path = None


p = Path('D:\\Gitlab\\DeOldify\\test_images')
all_file_path = []
count = 0
for file_name in p.rglob('*.jpg'):
    all_file_path.append(file_name)
    count+=1
for file_name in p.rglob('*.png'):
    all_file_path.append(file_name)
    count+=1
for file_name in p.rglob('*.jppeg'):
    all_file_path.append(file_name)
    count+=1

print(f" End of traversing the folder to be colored , share {count} A picture file \n")



#  Traverse images , Color 
for img_file_path in all_file_path:
    # arctan
    colorizer = get_image_colorizer(artistic=True)
    img_file_name = str(img_file_path).split('\\')[-1]
    print(f" Start to deal with {img_file_name}")
    colorizer.plot_transformed_image(path=img_file_path, render_factor=render_factor, compare=True)
    print(f"{img_file_name} End of processing ")
    print("\n")

#  end 
print(" The picture coloring process is over ")

                

Four 、 Video coloring

from deoldify import device
from deoldify.device_id import DeviceId

from deoldify.visualize import *
plt.style.use('dark_background')

import warnings
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")



#choices:  CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)
colorizer = get_video_colorizer()

#NOTE:  Max is 44 with 11GB video cards.  21 is a good default
render_factor=21
result_path = None

file_name_ext =  'D:\\Gitlab\\DeOldify\\test_video\\test1.mp4'


colorizer.colorize_from_file_name(file_name_ext, render_factor=render_factor)

原网站

版权声明
本文为[zkkkkkkkkkkkkk]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060912332006.html