PaddleHub可以便捷地獲取PaddlePaddle生態(tài)下的預(yù)訓(xùn)練模型真屯,完成模型的管理和一鍵預(yù)測。配合使用Fine-tune API倍试,可以基于大規(guī)模預(yù)訓(xùn)練模型快速完成遷移學(xué)習(xí)讯屈,讓預(yù)訓(xùn)練模型能更好地服務(wù)于用戶特定場景的應(yīng)用。
模型概述
CycleGAN是生成對抗網(wǎng)絡(luò)(Generative Adversarial Networks )的一種县习,與傳統(tǒng)的GAN只能單向生成圖片不同涮母,CycleGAN可以同時完成兩個domain的圖片進行相互轉(zhuǎn)換。該PaddleHub Module使用Cityscapes數(shù)據(jù)集訓(xùn)練完成躁愿,支持圖片從實景圖轉(zhuǎn)換為語義分割結(jié)果叛本,也支持從語義分割結(jié)果轉(zhuǎn)換為實景圖。
代碼及效果示例:
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
?