程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python+ai coloring old photos

編輯:Python

hello , Hello everyone , Today, I will continue to share interesting AI project .

Today we share NoGAN New image enhancement technology to color old photos . Like to remember to collect 、 Focus on 、 give the thumbs-up .

notes : Data 、 At the end of the article, a technical exchange group is provided

The effect is as follows :

Original picture

After coloring

NoGAN It's a new kind of GAN, It can take the least amount of time to do GAN Training .

The project shared today has been in GitHub Open source project , Let's run it .

1. preparation

First , use git clone Command download source code

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

Go to the project root directory , install Python Dependency package

pip3 install -r requirements.txt

Before writing code to run the project , You need to download the pre trained model . The project provides three models

Model

The difference between the following :

  • ColorizeArtistic_gen.pth: Achieve the highest quality of image shading in terms of interesting details and vitality , The model is in UNet Upper use resnet34 For the backbone , adopt NoGAN the 5 Second critic pre training /GAN Cycle and repeat

  • ColorizeStable_gen.pth: Achieved the best results in landscape and portrait , The model is in UNet Upper use resnet101 For the backbone , adopt NoGAN the 3 Second critic pre training /GAN Cycle and repeat

  • ColorizeVideo_gen.pth: Optimized for smooth video , It uses only the initial generator / Critic pre training /GAN NoGAN Training . Due to the pursuit of smooth speed , It has less color than the first two .

Put the downloaded model file in the project root directory models Under the directory .

2. Write code

Create... Under the same level of the project root directory Python file , Write code to load the model file just downloaded .

from DeOldify.deoldify.generators import gen_inference_wide
from DeOldify.deoldify.filters import MasterFilter, ColorizerFilter
# Specify model file 
learn = gen_inference_wide(root_folder=Path('./DeOldify'), weights_name='ColorizeVideo_gen')
# Load model 
deoldfly_model = MasterFilter([ColorizerFilter(learn=learn)], render_factor=10)

root_folder Specify the project root directory ,weights_name Specify which model to use next to color the photo .

Read old photos , Color it

import cv2
import numpy as np
from PIL import Image
img = cv2.imread('./images/origin.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
pil_img = Image.fromarray(img)
filtered_image = deoldfly_model.filter(
pil_img, pil_img, render_factor=35, post_process=True
)
result_img = np.asarray(filtered_image)
result_img = cv2.cvtColor(result_img, cv2.COLOR_RGB2BGR)
cv2.imwrite('deoldify.jpg', result_img)

use cv2 Read old photos , And use PIL.Image The module converts the picture into the format required for model input , Send it to the model for coloring , Save when done .

The above code is extracted from the project source code , You can see , Running the code is still very simple .

Interested friends can run it by themselves , You can also try other models .

Technical communication

At present, a technical exchange group has been opened , Group friends have exceeded 2000 people , The best way to add notes is : source + Interest direction , Easy to find like-minded friends

  • The way ①、 Send the following picture to wechat , Long press recognition , The background to reply : Add group ;
  • The way ②、 WeChat search official account : Machine learning community , The background to reply : Add group ;
  • The way ③、 You can add micro signals directly :mlc2060. Make a remark when adding : Research direction + School / company +CSDN, that will do . Then we can pull you into the group .

Research directions include : machine learning 、 data mining 、 object detection 、 Image segmentation 、 Target tracking 、 Face detection & distinguish 、OCR、 Attitude estimation 、 Super resolution 、SLAM、 Medical imaging 、Re-ID、GAN、NAS、 Depth estimation 、 Autopilot 、 Reinforcement learning 、 Lane line detection 、 Model pruning & Compress 、 Denoise 、 Defogging 、 Go to the rain 、 Style transfer 、 Remote sensing image 、 Behavior recognition 、 Video understanding 、 Image fusion 、 image retrieval 、 Paper Submission & communication 、PyTorch、TensorFlow and Transformer etc. .

Be sure to note : Research direction + School / company + nickname ( Such as Transformer Or target detection + Hand in + kaka ), Note according to the format , Can be passed and invited into the group faster .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved