簡體   English   中英

使用 auto-ts 部署時間序列 model 時出現問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM