为什么出错FileNotFoundError:[错误2]没有这样的文件或目录:'./ML/model.pth'?

时间:2020-07-19 13:15:03

标签: docker dockerfile pytorch

错误

l_1 |从Ml导入demo_model
ml_1 |文件“ /app/Ml/demo.py”,第84行 ml_1 |模型= torch.load('./ ML / model.pth',map_location ='cpu')
ml_1 |载入中的文件“ /usr/local/lib/python3.7/site-packages/torch/serialization.py”,行584
ml_1 |使用_open_file_like(f,'rb')作为open_file:
ml_1 | _open_file_like文件
中的“ /usr/local/lib/python3.7/site-packages/torch/serialization.py”文件,第234行 ml_1 |返回_open_file(名称或缓冲区,模式)
ml_1 | init
中的文件“ /usr/local/lib/python3.7/site-packages/torch/serialization.py”,第215行 ml_1 |超级(_open_file,self)。初始化(打开(名称,模式))

FileNotFoundError:[错误2]没有这样的文件或目录:'./ML/model.pth'

在启动Docker容器时发生。 Dockerfile:

FROM python:3.7

WORKDIR /app

COPY ./server/requirements.txt /app

COPY ./server/Ml/model.pth /app/Ml/

COPY ./server/Ml/demo.py /app/Ml/

RUN python -m pip install --no-cache-dir -r requirements.txt

CMD gunicorn -b=0.0.0.0:8443 -w=4 project.app:app --timeout 2000

发生错误的代码行:

best_model = torch.load('./ML/model.pth',  map_location='cpu')

1 个答案:

答案 0 :(得分:1)

您似乎有错字:文件夹为Ml(小写“ l”),而在代码中为ML(大写“ L”)。