python - 无法使用安装了 ubuntu、numpy、opencv 的方式编写 dockerfile
问题描述
该计划是部署预训练的人脸识别模型。但在我需要安装一些库之前。
docker 背后的想法是它带来了所有需要的库并构建整个“环境”而没有太多开销。只需启动 dockerfile,它就会依次运行所有其他脚本。
要安装的库:
- Ubuntu 16.04.6 LTS
- Python 3.6.10(3.5.x 也应该没问题)
- 开放CV 3.3。
- 数字货币
- imutils https://github.com/jrosebr1/imutils
- dlib http://dlib.net/
- 人脸识别https://github.com/ageitgey/face_recognition
我试图使用 curl 从 URL 下载 pkgs,但它不起作用。
我的码头文件:
FROM ubuntu:16.04.6
RUN apt-get update && apt-get install -y curl bzip2
curl -o numpy
&& sudo apt-get install numpy
&& curl install imutils https://github.com/jrosebr1/imutils
&& curl install dlib https://dlib.net
&& sudo git clone https://github.com/ageitgey/face_recognition.git
&& curl python-opencv https://opencv.org/
&& echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc \
&& ~/anaconda3/bin/conda update -n base conda \
&& rm miniconda_install.sh \
&& rm -rf /var/lib/apt/lists/* \
&& /bin/bash -c "source ~/.bashrc"
ENV PATH="~/anaconda3/bin:${PATH}"
##################################################
# Setup env for current project:
##################################################
EXPOSE 8000
RUN /bin/bash -c "conda create -y -n PYMODEL3.6"
ADD requirements.txt /tmp/setup/requirements.txt
RUN /bin/bash -c "source activate PYMODEL3.6 && pip install -r /tmp/setup/requirements.txt"
WORKDIR /Service
ADD Service /Service
ENTRYPOINT ["/bin/bash", "-c", "source activate PYMODEL3.6 && ./run.sh"]
人脸模型是预训练的。有2个python文件进行实际检测、128d编码和识别。用法是这样的:
#detect face, if there is face - encode it, return pickle
python3 encode.py --dataset dataset_id --encodings encodings.pickle
--confidence 0.9
#recognize using pickle
python3 face_recognizer.py --encodings encodings.pickle --image
dataset_webcam/3_1.jpg --confidence 0.9 --tolerance 0.5
我应该将它们包含在 dockerfile 中吗?
解决方案
我建议您使用如下所示的 Dockerfile,假设您的 requirements.txt 文件中有所有要求(numpy、imutils 等),并且您的文件夹中有encode.py
和文件:face_recognizer.py
Service
FROM python:3.6.10
RUN mkdir /tmp/setup
ADD requirements.txt /tmp/setup/requirements.txt
RUN pip install --no-cache-dir --upgrade setuptools && \
pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r /tmp/setup/requirements.txt
WORKDIR /Service
ADD Service /Service/
CMD ["./run.sh"]
EXPOSE 8000
推荐阅读
- r - 将大数据框转换为 3 列
- sql - 更新后的排名
- flutter-layout - 有什么方法可以为颤振中的警报对话创建一个通用类?
- angular - Angular 7:虚拟滚动和延迟加载
- gitlab - 在 CI/CD 管道中使用 if-then else
- javascript - Styling react native picker - specifically text alignment (iOS)
- mysql - MySql 条件更新 TRIGGER 给出奇怪的语法错误
- node.js - 具有服务器功能的 WebPack 项目
- javascript - 如何在JavaScript中检测变量是否连续超过2秒
- javascript - 道具更改时反应子组件不会重新渲染