搭建docker-caffe-anaconda-open_nsfw雅虎鉴黄环境

  sre

拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/master_caffe_in_21days/caffe:cpu_only
创建实例
docker run -ti registry.cn-hangzhou.aliyuncs.com/master_caffe_in_21days/caffe:cpu_only
#docker ps 获取id,id e0b30118467d

进入容器
docker attach e0b30118467d
apt-get update
安装io
export PYTHONPATH=/root/caffe/python
pip install scikit-image
pip install protobuf

安装Anaconda2
apt-get install wget curl -y
cd ~
wget https://repo.continuum.io/archive/Anaconda2-2.4.0-Linux-x86_64.sh
chmod +x Anaconda2-2.4.0-Linux-x86_64.sh
./Anaconda2-2.4.0-Linux-x86_64.sh #选默认即可
source ~/.bashrc

安装nginx与uwsgi
pip install uwsgi
apt-get install -y nginx

Ctrl+D退出容器,重新提交镜像
docker commit e0b30118467d caffe/anaconda

启动端口映射和目录挂载
mkdir -p /data/caffe
cd /data/caffe
git clone https://github.com/yahoo/open_nsfw.git
docker run -itd -p 9000:80 -it -v /data/caffe:/dockerData caffe/anaconda /bin/bash #hostPort:containerPort
docker ps #id f104d2bcfc91
docker attach f104d2bcfc91

cd /dockerData/open_nsfw
export PYTHONPATH=/root/caffe/python
python ./classify_nsfw.py \
–model_def nsfw_model/deploy.prototxt \
–pretrained_model nsfw_model/resnet_50_1by2_nsfw.caffemodel \
test.JPG #获得分数

Ctrl+P+Q后台继续运行容器

附:api封装后,即可通过http调用图片地址就行分数判断
/usr/bin/pip install flask requests
修改Nginx配置:
vim /etc/nginx/conf.d/uwsgi.conf
server {
listen 80;
server_name 0.0.0.0 127.0.0.1 192.168.195.41;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
include uwsgi_params;
uwsgi_send_timeout 600; # 指定向uWSGI传送请求的超时时间,完成握手后向uWSGI传送请求的超时时间。
uwsgi_connect_timeout 600; # 指定连接到后端uWSGI的超时时间。
uwsgi_read_timeout 600; # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间。
uwsgi_pass 127.0.0.1:5000;
uwsgi_param UWSGI_PYHOME /root/caffe/python;
uwsgi_param UWSGI_CHDIR /dockerData/open_nsfw;
uwsgi_param UWSGI_SCRIPT check:app;
}
}
service nginx restart

修改uwsgi配置:
vim /dockerData/open_nsfw/uwsgi.ini
[uwsgi]
socket = 127.0.0.1:5000 #注: 指定某个固定端口
processes = 4 #注:跑几个进程,这里用4个进程
threads = 2
master = true
pythonpath = /root/caffe/python
module = check
callable = app
memory-report = true
py-autoreload = 1 #python文件修改,无需重启

cd /dockerData/open_nsfw
uwsgi -d /dockerData/uwsgi.log –ini /dockerData/open_nsfw/uwsgi.ini #启动
kill -9 (ps -ef |grep uwsgi |awk ‘{print2}’ |xargs) #关闭

4 thoughts on - 搭建docker-caffe-anaconda-open_nsfw雅虎鉴黄环境

  • Open nsfw model是雅虎开源项目,全名是Open Not suitable for work model,专门鉴别不适合工作时间浏览的图片(言而言之就是小黄图)。它是基于Caffe框架训练的模型,用于音视频后处理。不过,它还不能鉴别恐怖、血腥图片。

    • ~$ docker ps
      CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
      06f00553e137 registry.cn-hangzhou.aliyuncs.com/master_caffe_in_21days/caffe:cpu_only “/bin/bash” 3 minutes ago Up 2 minutes sleepy_turing
      6992c5c86abc registry.cn-hangzhou.aliyuncs.com/master_caffe_in_21days/caffe:cpu_only “/bin/bash” 3 minutes ago Up 3 minutes compassionate_fermi

      docker attach 06f00553e137
      Killed

      有能够使用的么

      麻烦确认。

  • docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    06f00553e137 registry.cn-hangzhou.aliyuncs.com/master_caffe_in_21days/caffe:cpu_only “/bin/bash” 3 minutes ago Up 2 minutes sleepy_turing
    6992c5c86abc registry.cn-hangzhou.aliyuncs.com/master_caffe_in_21days/caffe:cpu_only “/bin/bash” 3 minutes ago Up 3 minutes compassionate_fermi

    docker attach 06f00553e137
    Killed

    你好,按照你的方法,出现了上面的信息。
    有能够使用的么。

    麻烦您了。

    • 1 看看系统日志,docker与环境还是有一些关系的;
      2 试试exec进容器看看
      3 attach后有没有其他操作呢,有时候会卡一下的
      4 退出时候打入后台

LEAVE A COMMENT

Captcha Code