[英]A problem when deploying timeseries model using auto-ts
我想使用 docker 部署时间序列 model,所有模型都可以正常工作。 但是当我输入时间序列的端点 model 时,它给了我以下消息。
_unpickle_timestamp() takes exactly 3 positional arguments (4 given)]
当我尝试加载 pickle 文件时会发生这种情况。
return pickle.load(file_obj)
我使用 Windows 操作系统,docker 文件是这样的。
# try to use alpine image
FROM python:3.8-slim-buster
WORKDIR /app
COPY . /app
RUN python -m pip install --upgrade pip
RUN pip install --upgrade setuptools
# fbprophet
RUN apk add --no-cache --virtual .build-deps gcc musl-dev python3-dev libffi-dev openssl-dev cargo
RUN pip3 install convertdate==2.1.2 lunarcalendar==0.0.9 holidays==0.10.3 cython==0.29.21 pystan==2.19.1.1 pandas
RUN pip3 install fbprophet==0.6
RUN pip install -r requirements.txt
RUN pip install --upgrade watchdog
CMD ["python3", "app.py"]
端点看起来像。
@app.route('/noofcases',methods=['GET'])
def predict_noofcases_datapoint():
predict_pipeline=PredictPipline()
results=predict_pipeline.GDNC_no_of_cases_predict(12)
data = results.to_json(orient='records') # Convert DataFrame to JSON format
parsed_data = json.loads(data) # Parse the JSON string
return jsonify(parsed_data)
和GDNC_no_of_cases_predict
function 看起来像。
def GDNC_no_of_cases_predict(self, periods=12):
try:
model_path = os.path.join("artifacts", "nofcases.pkl")
best_model = load_object(file_path=model_path)
logging.info("file loaded successfully")
# best_model = model.get_best_model()
future_dates = best_model.make_future_dataframe(periods, freq='M')
forecast = best_model.predict(future_dates)
preds = forecast[['ds', 'yhat']].tail(periods)
return preds
except Exception as e:
raise CustomException(e,sys)
经过大量研究后,我将 dockerfile 更改如下
# Dockerfile
# Use Python 3.8 slim buster as the base image
FROM python:3.8-slim-buster
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Switch to root user
USER root
RUN apt-get -o Acquire::Max-FutureTime=86400 update
RUN apt-get update && apt-get install -y gnupg
RUN apt-get update && apt-get install -y
RUN apt-get install curl -y
RUN apt-get install apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | tee /etc/apt/sources.list.d/msprod.list
RUN apt-get update
ENV ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive
RUN apt-get install mssql-tools unixodbc-dev -y
# Upgrade pip and setuptools
RUN python -m pip install --upgrade pip setuptools
# Install the Microsoft ODBC driver for SQL Server (Linux)
# Install necessary build dependencies
RUN apt-get install -y --no-install-recommends \
build-essential \
gcc \
musl-dev \
python3-dev \
libffi-dev
# Install pyodbc
RUN pip install pyodbc
# Install the required Python packages
RUN pip install -r requirements.txt
# Upgrade watchdog
RUN pip install --upgrade watchdog
# Set the command to run the application
CMD ["python3", "app.py"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.