Deepdanbooru(以下简称dd)是一个由TensorFlow实现,基于AI的多标签动漫图片分类系统。详细介绍参见量子位的文章

项目地址:https://github.com/KichangKim/DeepDanbooru

1.准备文件:项目本体;模型文件

2.准备环境(注意,以下版本号请完全匹配,防止出现各种兼容性问题;建议使用miniconda):

  • Python 3.6.
  • tensorflow==2.3.1
  • Click==7.0
  • numpy==1.16.2
  • requests==2.22.0
  • scikit-image==0.15.0
  • six==1.13.0
  • scipy==1.5.4

3.安装dd

进入dd根目录,(使用conda请切换至刚装好的环境)运行以下命令

python setup.py build
->running build
->running build_py
python setup.py install
#运行前请先装好上述module
->running install
->running bdist_egg
->running egg_info
->writing deepdanbooru.egg-info/PKG-INFO
...省略...
->Finished processing dependencies for deepdanbooru==1.0.0

至此dd安装完毕

4.使用

deepdanbooru
->2021-02-24 11:41:25.989366: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
->2021-02-24 11:41:25.989409: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
#以上两行是使用tensorflow-cpu的警告,忽略即可
->Usage: deepdanbooru [OPTIONS] COMMAND [ARGS]...

->AI based multi-label girl image classification system, implemented by
->using TensorFlow.

->Options:
->--version Show the version and exit.
->--help Show this message and exit.

->Commands:
->create-project
->download-tags
->evaluate Evaluate model by estimating image tag.
->evaluate-project Evaluate the project.
->grad-cam Experimental feature.
->make-training-database
->train-project

笔者在2021.2.21使用的版本中evaluate-project命令报错,改用evaluate

Usage: deepdanbooru evaluate [OPTIONS] [TARGET_PATHS]...

Evaluate model by estimating image tag.

Options:

--model-path FILE

--tags-path FILE

--threshold FLOAT

提供以下参数即可

model-path.h5模型绝对路径

tags-pathtags文件绝对路径

threshold阈值,即置信度大于此值的tag才会被统计(可选,默认0.5)

[TARGET_PATHS]图片文件绝对路径

5.结果

使用以下图片

deepdanbooru evaluate --model-path /root/model/model-resnet_custom_v4.h5 --tags-path /root/model/tags.txt /root/1.jpg
2021-02-24 12:08:17.463558: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-02-24 12:08:17.463634: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-02-24 12:08:19.303020: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-02-24 12:08:19.303063: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2021-02-24 12:08:19.303084: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (VM-8-17-centos): /proc/driver/nvidia/version does not exist
2021-02-24 12:08:19.303295: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-02-24 12:08:19.310116: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 2595120000 Hz
2021-02-24 12:08:19.310312: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x560c8244eb90 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-02-24 12:08:19.310331: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
Tags of /root/1.jpg:
(0.972) 1girl
(0.998) animal_ears
(0.528) bangs
(0.897) blush
(0.658) cat_ears
(0.546) closed_mouth
(0.610) eyebrows_visible_through_hair
(0.875) gradient
(0.879) gradient_background
(0.933) long_hair
(0.771) looking_at_viewer
(0.517) portrait
(0.965) solo
(0.510) white_background
(0.958) yellow_eyes

其他用法可以手动更改源码

Tags:

No responses yet

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

近期评论
归档
分类