【深度学习】人物图片标签生成

简介
图片处理的时候,经常会给图片标签处理,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}]

猜你喜欢

转载自blog.csdn.net/mozf881/article/details/84929443