20201223: Call the paddlepaddle cutout model to change the background color of the photo

1. Environmental installation

  • pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple
    (Note: it cannot be installed in the cpu environment, it needs to be installed in the gpu environment)
  • pip install paddlehub

2. The script is as follows


import matplotlib.pyplot as plt 
import matplotlib.image as mpimg

photo_path = ['mines.jpg']

#显示原图
img = mpimg.imread(photo_path[0])
plt.figure(figsize=(10,10))
plt.imshow(img) 
plt.axis('off') 
plt.show()


#改变底色
import paddlehub as hub

output_path = 'output'
module = hub.Module(name="deeplabv3p_xception65_humanseg")
input_dict = {"image": photo_path}
results = module.segmentation(data=input_dict,visualization=True,
                 output_dir=output_path)



#显示处理好的图片
import glob
import os
img_path = glob.glob(os.path.join(output_path, '*.png'))
img_path.sort()

for path in img_path:
    img= mpimg.imread(path)

plt.figure(figsize=(10,10))
plt.imshow(img) 
plt.axis('off') 
plt.show()

Guess you like

Origin blog.csdn.net/weixin_38192254/article/details/111595283