Skip to content

Commit 8ae6701

Browse files
authored
No pkl extension requirement for model name (#164)
1 parent 962778c commit 8ae6701

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

diabetes_regression/scoring/score.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import numpy
2727
import joblib
2828
import os
29+
from azureml.core.model import Model
2930
from inference_schema.schema_decorators \
3031
import input_schema, output_schema
3132
from inference_schema.parameter_types.numpy_parameter_type \
@@ -36,16 +37,13 @@ def init():
3637
# load the model from file into a global object
3738
global model
3839

39-
# AZUREML_MODEL_DIR is an environment variable created during service
40-
# deployment. It contains the path to the folder containing the model.
41-
path = os.environ['AZUREML_MODEL_DIR']
42-
model_path = None
43-
for root, dirs, files in os.walk(path):
44-
for file in files:
45-
if '.pkl' in file:
46-
model_path = os.path.join(path, file)
47-
if model_path is None:
48-
raise ValueError(".pkl model not found")
40+
# we assume that we have just one model
41+
# AZUREML_MODEL_DIR is an environment variable created during deployment.
42+
# It is the path to the model folder
43+
# (./azureml-models/$MODEL_NAME/$VERSION)
44+
model_path = Model.get_model_path(
45+
os.getenv("AZUREML_MODEL_DIR").split('/')[-2])
46+
4947
model = joblib.load(model_path)
5048

5149

0 commit comments

Comments
 (0)