百度AI攻略:Paddlehub實(shí)現(xiàn)圖像生成

PaddleHub可以便捷地獲取PaddlePaddle生態(tài)下的預(yù)訓(xùn)練模型,完成模型的管理和一鍵預(yù)測。配合使用Fine-tune API,可以基于大規(guī)模預(yù)訓(xùn)練模型快速完成遷移學(xué)習(xí),讓預(yù)訓(xùn)練模型能更好地服務(wù)于用戶特定場景的應(yīng)用。

模型概述

CycleGAN是生成對(duì)抗網(wǎng)絡(luò)(Generative Adversarial Networks )的一種,與傳統(tǒng)的GAN只能單向生成圖片不同,CycleGAN可以同時(shí)完成兩個(gè)domain的圖片進(jìn)行相互轉(zhuǎn)換。該P(yáng)addleHub Module使用Cityscapes數(shù)據(jù)集訓(xùn)練完成,支持圖片從實(shí)景圖轉(zhuǎn)換為語義分割結(jié)果,也支持從語義分割結(jié)果轉(zhuǎn)換為實(shí)景圖。

代碼及效果示例:

import paddlehub as hub

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

cyclegan = hub.Module(name="cyclegan_cityscapes")

test_img_path = "./body2.jpg"

# 預(yù)測結(jié)果展示

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

# set input dict

input_dict = {"image": [test_img_path]}

# execute predict and print the result

results = cyclegan.generate(data=input_dict)

for result in results:

? ? print(result)

test_img_path = "./cyclegan_output/body2.jpg"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-06 08:47:55,320] [? ? INFO] - Installing cyclegan_cityscapes module

2020-01-06 08:47:55,320-INFO: Installing cyclegan_cityscapes module

[2020-01-06 08:47:55,353] [? ? INFO] - Module cyclegan_cityscapes already installed in /home/aistudio/.paddlehub/modules/cyclegan_cityscapes

2020-01-06 08:47:55,353-INFO: Module cyclegan_cityscapes already installed in /home/aistudio/.paddlehub/modules/cyclegan_cityscapes

?

[2020-01-06 08:47:55,728] [? ? INFO] - 234 pretrained paramaters loaded by PaddleHub

2020-01-06 08:47:55,728-INFO: 234 pretrained paramaters loaded by PaddleHub

File ./body2.jpg is processed successfully and the result is saved to the cyclegan_output/body2.jpg

?

In[8]

cyclegan = hub.Module(name="cyclegan_cityscapes")

test_img_path = "./cbd1.jpg"

# 預(yù)測結(jié)果展示

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

# set input dict

input_dict = {"image": [test_img_path]}

# execute predict and print the result

results = cyclegan.generate(data=input_dict)

for result in results:

? ? print(result)

test_img_path = "./cyclegan_output/cbd1.jpg"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-06 08:49:16,726] [? ? INFO] - Installing cyclegan_cityscapes module

2020-01-06 08:49:16,726-INFO: Installing cyclegan_cityscapes module

[2020-01-06 08:49:16,746] [? ? INFO] - Module cyclegan_cityscapes already installed in /home/aistudio/.paddlehub/modules/cyclegan_cityscapes

2020-01-06 08:49:16,746-INFO: Module cyclegan_cityscapes already installed in /home/aistudio/.paddlehub/modules/cyclegan_cityscapes

?

[2020-01-06 08:49:17,164] [? ? INFO] - 234 pretrained paramaters loaded by PaddleHub

2020-01-06 08:49:17,164-INFO: 234 pretrained paramaters loaded by PaddleHub

File ./cbd1.jpg is processed successfully and the result is saved to the cyclegan_output/cbd1.jpg

?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 她又開始做噩夢(mèng)了! 夢(mèng)里的她穿著紅色的衣服,在找一間屋子,很費(fèi)力地在找一間屋子。她不知道為什么一定要找到它,但是她...
    青青奈我何閱讀 170評(píng)論 0 3
  • 驚蟄之后。風(fēng)放下屠刀,立地成佛 佛手柔軟,象無骨的嬰兒 從臉上撫過,人面轉(zhuǎn)身就是桃花 河水變聲,覆冰下的低吟蛻變激...
    隱麥客閱讀 1,153評(píng)論 23 31
  • 文‖靜若 〔一〕 剛讀完伍琦詩的小說《無聲告白》,故事里沉悶、壓抑、陰郁、煩躁的情感基調(diào)像一股股污濁...
    靜若517閱讀 2,582評(píng)論 2 5
  • 秦淮鳳鳴閱讀 68評(píng)論 0 3
  • 1. 認(rèn)識(shí)這個(gè)詞(基礎(chǔ)篇) 詞:embark on 英英釋義:to start a new project or ...
    楓林悅讀_Diana閱讀 484評(píng)論 0 1

友情鏈接更多精彩內(nèi)容