本篇博文重点介绍 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 6cb: Pull complete ee9f5a7f3403: Pull complete 380df6ccf740: Pull complete Digest: sha256:d2fc0a3efdf275cc072fb1ba1b0c42cd11481d7b4b318c 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@c:/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. 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. 20 net.cpp:219] scale_1 does not need backward computation. I0417 12:28:58. 20 net.cpp:219] bn_1 does not need backward computation. I0417 12:28:58. 20 net.cpp:219] conv_1 does not need backward computation. I0417 12:28:58. 20 net.cpp:219] data does not need backward computation. I0417 12:28:58. 20 net.cpp:261] This network produces output prob I0417 12:28:58. 20 net.cpp:274] Network initialization done. I0417 12:28:58. 20 net.cpp:752] Ignoring source layer loss ('NSFW score: ', 0.) # 很明显0.8值高了, 你懂得~ 自己手动试试吧~
好啦??, 关于caffe-open_nsfw鉴黄就介绍到这里, 喜欢点个赞吧~ ❤☕️
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/219406.html原文链接:https://javaforall.net
