【问题标题】:Azure Machine Learning profiling model errorsAzure 机器学习分析模型错误
【发布时间】:2022-08-18 17:18:04
【问题描述】:

成功完成 Azure 机器学习示例中的 image-classification-mnist-data 教程后

Samples/1.43.0/tutorials/image-classification-mnist-data/img-classification-part1-training.ipynb

我想分析生成的模型,如本文https://docs.microsoft.com/en-us/azure/machine-learning/v1/how-to-deploy-profile-model?pivots=py-sdk 所示

但是我不断收到错误消息

Running.....................................
Failed
/tmp/ipykernel_56534/2365332213.py:15: UserWarning: Model Profiling operation failed with the following error: Model service has failed with status: CrashLoopBackOff: Back-off restarting failed. This may be caused by errors in your scoring file\'s init() function. Error logs URL: Log upload failed. Request ID: b5384f0f-8a3a-4f53-908e-0a028374b924. Inspect ModelProfile.error property for more information.
  profile.wait_for_completion(True)
{\'name\': \'sklearn-08172022-143854\',
 \'createdTime\': \'2022-08-17T14:38:56.706085+00:00\',
 \'state\': \'Failed\',
 \'requestedCpu\': 3.5,
 \'requestedMemoryInGB\': 15.0,
 \'requestedQueriesPerSecond\': 0,
 \'error\': {\'code\': \'ModelTestBackendCrashLoopBackoff\',
  \'statusCode\': 400,
  \'message\': \"Model service has failed with status: CrashLoopBackOff: Back-off restarting failed. This may be caused by errors in your scoring file\'s init() function. Error logs URL: Log upload failed.\",
  \'details\': []}}

我的工作区模型列表中只有 1 个模型。那么为什么我会收到一个错误,我如何才能看到评分文件中抛出的错误?

评分.py

def init():
    global model
    # AZUREML_MODEL_DIR is an environment variable created during deployment.
    # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)
    # For multiple models, it points to the folder containing all deployed models (./azureml-models)
    model_path = os.path.join(os.getenv(\'AZUREML_MODEL_DIR\'), \'sklearn_mnist_model.pkl\')
    model = joblib.load(model_path)
        
def run(raw_data):
    data = np.array(json.loads(raw_data)[\'data\'])
    # make prediction
    y_hat = model.predict(data)
    # you can return any data type as long as it is JSON-serializable
    return y_hat.tolist()

分析.py

import os
from azureml.core import Dataset
from azureml.opendatasets import MNIST
from utils import load_data
import os
import glob


data_folder = os.path.join(os.getcwd(), \'data\')
os.makedirs(data_folder, exist_ok=True)

mnist_file_dataset = MNIST.get_file_dataset()
mnist_file_dataset.download(data_folder, overwrite=True)

data_folder = os.path.join(os.getcwd(), \'data\')
# note we also shrink the intensity values (X) from 0-255 to 0-1. This helps the neural network converge faster
X_test = load_data(glob.glob(os.path.join(data_folder,\"**/t10k-images-idx3-ubyte.gz\"), recursive=True)[0], False) / 255.0
y_test = load_data(glob.glob(os.path.join(data_folder,\"**/t10k-labels-idx1-ubyte.gz\"), recursive=True)[0], True).reshape(-1)




import json
from azureml.core import Datastore
from azureml.core.dataset import Dataset
from azureml.data import dataset_type_definitions

random_index = np.random.randint(0, len(X_test)-1)
input_json = \"{\\\"data\\\": [\" + str(list(X_test[random_index])) + \"]}\"
# create a string that can be utf-8 encoded and
# put in the body of the request
serialized_input_json = json.dumps(input_json)
dataset_content = []
for i in range(100):
    dataset_content.append(serialized_input_json)
dataset_content = \'\\n\'.join(dataset_content)
file_name = \'sample_request_data.txt\'
f = open(file_name, \'w\')
f.write(dataset_content)
f.close()

# upload the txt file created above to the Datastore and create a dataset from it
data_store = Datastore.get_default(ws)
data_store.upload_files([\'./\' + file_name], target_path=\'sample_request_data\')
datastore_path = [(data_store, \'sample_request_data\' +\'/\' + file_name)]
sample_request_data = Dataset.Tabular.from_delimited_files(
    datastore_path, separator=\'\\n\',
    infer_column_types=True,
    header=dataset_type_definitions.PromoteHeadersBehavior.NO_HEADERS)
sample_request_data = sample_request_data.register(workspace=ws,
                                                    name=\'sample_request_data\',
                                                    create_new_version=True)



from azureml.core.model import InferenceConfig, Model
from azureml.core.dataset import Dataset
from datetime import datetime


model = Model(ws, id=\'sklearn_mnist:1\')
inference_config = InferenceConfig(entry_script=\'score.py\', environment=env)
input_dataset = Dataset.get_by_name(workspace=ws, name=\'sample_request_data\')
profile = Model.profile(ws,
            \'sklearn-%s\' % datetime.now().strftime(\'%m%d%Y-%H%M%S\'),
            [model],
            inference_config,
            input_dataset=input_dataset)

profile.wait_for_completion(True)

# see the result
details = profile.get_details()
            
    

    标签: profiling azure-machine-learning-studio


    【解决方案1】:

    CrashLoopBackOff错误将发生在在里面()由于 score.py 文件中缺少所需的库而导致的方法。根据提到的代码,函数中缺少 pickle 库。

    from PIL import Image 
    import json
    import pickle
    import joblib
    

    在 score.py 文件中使用上述库以避免CrashLoopBackOff错误。

    【讨论】:

      猜你喜欢
      • 2020-02-09
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      相关资源
      最近更新 更多