python 连接被拒绝错误:[Errno 111]连接被拒绝- Mlrun

zqdjd7g9  于 2022-12-17  发布在  Python
关注(0)|答案(2)|浏览(230)

我试图调用mlrun中的函数,但出现上述错误。任何人都可以帮助我在that.im上附加代码...

from cloudpickle import load
import numpy as np
from typing import List
import mlrun

class ClassifierModel(mlrun.serving.V2ModelServer):
    def load(self):
        """load and initialize the model and/or other elements"""
        model_file, extra_data = self.get_model('.pkl')
        self.model = load(open(model_file, 'rb'))

    def predict(self, body: dict) -> List:
        """Generate model predictions from sample."""
        feats = np.asarray(body['inputs'])
        result: np.ndarray = self.model.predict(feats)
        return result.tolist()

以下代码将您在上一步中定义的ClassifierModel类转换为服务函数。服务函数使用的类名在spec.default_class中设置。

serving_fn = mlrun.code_to_function('serving', kind='serving',image='mlrun/mlrun')
serving_fn.spec.default_class = 'ClassifierModel'

model_file = project.get_artifact_uri('my_model') 
serving_fn.add_model('my_model',model_path=model_file)

在本地测试函数

my_data = '''{"inputs":[[5.1, 3.5, 1.4, 0.2],[7.7, 3.8, 6.7, 2.2]]}'''

server = serving_fn.to_mock_server()
server.test("/v2/models/my_model/infer", body=my_data)

# Building and Deploying the Serving Function¶

function_address = serving_fn.deploy()

print (f'The address for the function is {function_address} \n')

!curl $function_address

# Now we will try to invoke our serving function

serving_fn.invoke('/v2/models/my_model/infer', my_data)

OSError: error: cannot get build status, HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /api/v1/build/status?name=serving&project=getting-started-jovyan&tag=&logs=yes&offset=0&last_log_timestamp=1664873747518.8518&verbose=no (Caused by ReadTimeoutError("HTTPConnectionPool(host='localhost', port=8080): Read timed out. (read timeout=45)"))
zhte4eai

zhte4eai1#

从外观上看,localhost:8080上没有任何侦听,即使应该有。
根据入门指南,应该有一个“MLRun Backend Service”,默认情况下应该在这个地址上。我怀疑你还没有启动这个服务。

xwbd5t1u

xwbd5t1u2#

地址localhost:8080在无法从docker-composer访问,这意味着你必须做MLRun安装到不同的IP地址。我看到两个步骤,如何解决这个问题:

相关安装

桌面Docker中的MLRun Community Edition必须安装在相关的HOST_IP下(不使用localhost或127.0.0.1,而是使用稳定的IP地址,请参见ipconfig),并使用相关的SHARED_DIR。请参见相关命令行(从操作系统窗口):

set HOST_IP=192.168.0.150
set SHARED_DIR=c:\Apps\mlrun-data
set TAG=1.2.0

mkdir %SHARED_DIR%

docker-compose -f "c:\Apps\mlrun\compose.with-jupyter.yaml" up

顺便说一句:YAML文件参见https://docs.mlrun.org/en/latest/install/local-docker.html

2.进出港口

在调用serving_fn.invoke的情况下,您必须打开IP地址上的相关端口(从deploy_function)(基于HOST_IP的设置,参见第一点)。
通常,可以根据防火墙策略或本地防病毒程序阻止此端口。这意味着,您必须在调用调用之前打开对此端口的访问。
顺便说一句:

相关问题