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

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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值