Python3 - Docker部署caffe open_nsfw 图片鉴黄

Posted 韩俊强

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3 - Docker部署caffe open_nsfw 图片鉴黄相关的知识,希望对你有一定的参考价值。

文章目录

本篇博文重点介绍 Centos:6.9 Docker部署Caffe, 测试open_nsfw实例, 意在学习caffe的快速安装, 这里以cpu版本的caffe安装为例, 简单应用 open_nsfw 鉴黄库, 当前使用图片和视频的项目越来越多, 在此基础上, 进一步封装可以商用, 节省成本。

1. Docker部署caffe

[harry@k8s-master01 open_nsfw]$ docker pull elezar/caffe:cpu
cpu: Pulling from elezar/caffe
6c953ac5d795: Pull complete 
3eed5ff20a90: Pull complete 
f8419ea7c1b5: Pull complete 
51900bc9e720: Pull complete 
a3ed95caeb02: Pull complete 
b968c02ba977: Pull complete 
291f35fdb68c: Pull complete 
6c428669041b: Pull complete 
ee9f5a7f3403: Pull complete 
380df6ccf740: Pull complete 
Digest: sha256:d2fc0a3e942290fdf275cc072f329557b1ba1b0210436c42cd11481d7b4b318c
Status: Downloaded newer image for elezar/caffe:cpu
docker.io/elezar/caffe:cpu

检测caffe是否安装成功

# 查看caffe版本号
[harry@k8s-master01 open_nsfw]$ docker run -ti elezar/caffe:cpu caffe --version
libdc1394 error: Failed to initialize libdc1394
caffe version 1.0.0-rc3
# 查看caffe镜像
[harry@k8s-master01 open_nsfw]$ docker images
REPOSITORY            TAG               IMAGE ID       CREATED             SIZE
elezar/caffe          cpu               aadc51f74429   5 years ago         1.31GB

2. 下载open_nsfw

wget https://github.com/yahoo/open_nsfw.git

3. 运行caffe

# 切换到刚才下载的open_nsfw文件夹
[harry@k8s-master01 ]$ cd open_nsfw

# 放几张待测试的图片
[harry@k8s-master01 open_nsfw]$ tree
.
├── 111.jpg
├── 222.jpg
├── 333.jpg
├── classify_nsfw.py
├── LICENSE.md
├── nsfw_model
│   ├── deploy.prototxt
│   └── resnet_50_1by2_nsfw.caffemodel
└── README.md

# 运行caffe
# --volume=$(pwd):/workspace 工作目录映射
# $(pwd)为当前文件路径
# /workspace 为caffe工作路径
[harry@k8s-master01 open_nsfw]$ docker run -ti --volume=$(pwd):/workspace elezar/caffe:cpu /bin/bash
root@c74059855431:/workspace# 

4. 运行鉴黄图片

# 使用open_nsfw识别库 检测图片
root@27a3cf6c655f:/workspace# python ./classify_nsfw.py --model_def nsfw_model/deploy.prototxt --pretrained_model nsfw_model/resnet_50_1by2_nsfw.caffemodel   333.jpg 
libdc1394 error: Failed to initialize libdc1394
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0417 12:29:12.823567    21 net.cpp:49] Initializing net from parameters: 
name: "ResNet_50_1by2_nsfw"
state 
  phase: TEST

layer 
  name: "data"
  type: "Input"
  top: "data"
  input_param 
    shape 
      dim: 1
      dim: 3
      dim: 224
      dim: 224
    
  

...............
...............
I0417 12:28:58.549093    20 net.cpp:219] scale_1 does not need backward computation.
I0417 12:28:58.549103    20 net.cpp:219] bn_1 does not need backward computation.
I0417 12:28:58.549154    20 net.cpp:219] conv_1 does not need backward computation.
I0417 12:28:58.549166    20 net.cpp:219] data does not need backward computation.
I0417 12:28:58.549175    20 net.cpp:261] This network produces output prob
I0417 12:28:58.549315    20 net.cpp:274] Network initialization done.
I0417 12:28:58.809204    20 net.cpp:752] Ignoring source layer loss
('NSFW score:  ', 0.81271326541900635)
# 很明显0.8值高了, 你懂得~ 自己手动试试吧~

好啦🌶🌶, 关于caffe-open_nsfw鉴黄就介绍到这里, 喜欢点个赞吧~ ❤☕️

以上是关于Python3 - Docker部署caffe open_nsfw 图片鉴黄的主要内容,如果未能解决你的问题,请参考以下文章

Python3 - Docker部署caffe open_nsfw 图片鉴黄

docker[caffe&&pycaffe]

模型推理谈谈 caffe 的 bn 和 scale 算子

Python3 - Docker 安装部署Gitlab代码托管教程

Python3 - Docker 安装部署Gitlab代码托管教程

Python3 - Docker 安装部署Gitlab代码托管教程