【深度學習】人物圖片標籤生成
簡介
圖片處理的時候,經常會給圖片標籤處理,Illustration2Vec是網上一個比較好的任務標籤開源庫,用於生成人物特徵的標籤。
Illustration2Vec
下載地址:
https://github.com/rezoo/illustration2vec
並且在https://github.com/rezoo/illustration2vec/releases下載模板檔案和標籤檔案。
Illustration2Vec用到chainer這個深度學習框架,以及一些其他庫,如果沒有則安裝
pip install chainer Pillow scikit-image
Illustration2Vec有豐富的標籤庫,可以設定一個閾值,比如0.5,提取高於閾值的標籤,或者給出指定的標籤,獲取對應的概率。
比如,百度圖片下個萌妹子:
程式碼:
# -*- coding: utf-8 -*- import i2v from imageio import imread illust2vec = i2v.make_i2v_with_chainer('illust2vec_tag_ver200.caffemodel', 'tag_list.json') tags = ['blonde hair', 'brown hair', 'black hair', 'blue hair', 'pink hair', 'purple hair', 'green hair', 'red hair', 'silver hair', 'white hair', 'orange hair', 'aqua hair', 'grey hair', 'long hair', 'short hair', 'twintails', 'drill hair', 'ponytail', 'blue eyes', 'red eyes', 'brown eyes', 'green eyes', 'purple eyes', 'yellow eyes', 'pink eyes', 'aqua eyes', 'black eyes', 'orange eyes', 'blush', 'smile', 'open mouth', 'hat', 'ribbon', 'glasses','photo'] def checkimage(filename, threshold=[]): img = imread(filename) if (threshold==[]): tags = illust2vec.estimate_plausible_tags([img], threshold=0.5) else: tags = illust2vec.estimate_specific_tags([img], threshold) return tags if __name__ == '__main__': result = checkimage("E:/data/Jupyter/project21Code/ACGan/faces1/852.jpg") print(result)
獲取標籤:
[{‘general’: [(‘1girl’, 0.9891161918640137), (‘food’, 0.8902480602264404), (‘brown hair’, 0.8745222091674805), (‘solo’, 0.7861981391906738), (‘long hair’, 0.7356202602386475), (‘blush’, 0.7042754888534546), (‘fruit’, 0.6705906391143799), (‘eating’, 0.5464189052581787)], ‘copyright’: [], ‘character’: [], ‘rating’: <zip object at 0x0000000018A90B08>}]
標籤反饋圖片1個女孩,食物,棕色頭髮,長頭髮,吃飯等資訊
也可以指定標籤獲取概率:
[{‘purple eyes’: 0.4817981719970703, ‘smile’: 0.06011262536048889, ‘orange hair’: 0.04947340488433838, ‘short hair’: 0.0349823534488678, ‘green hair’: 0.00037857890129089355, ‘brown eyes’: 0.02036881446838379, ‘aqua eyes’: 3.936886787414551e-05}]