MachineLearningNotebooks icon indicating copy to clipboard operation
MachineLearningNotebooks copied to clipboard

How to access azure blob storage in score.py for scoring of deployed model

Open amardeepjaiman opened this issue 7 years ago • 11 comments

Hi,

I have found ways to access (mount,download) datastore (blob store) while training on AML and in pipelines. but i have nowhere seen any example to access the blob store datastore as mount in scoring script of deployed model. Could someone guide me to this ?

Thanks, Amardeep

amardeepjaiman avatar May 08 '19 05:05 amardeepjaiman

Not sure, but this article might help: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-access-data

j-martens avatar May 10 '19 13:05 j-martens

Thanks @j-martens , But this articles tells about accessing datastores while training and training pipelines. but not about accessing them in scoring script while predicting using deployed web service

amardeepjaiman avatar May 15 '19 08:05 amardeepjaiman

what exactly do you want to do with data from a datastore in your scoring script?

j-martens avatar May 20 '19 18:05 j-martens

I want to access my data , which is stored on the blob storage as mounting the storage on compute for inferencing/scoring the model ?

amardeepjaiman avatar May 23 '19 08:05 amardeepjaiman

This is a web service that runs a script in a loop every time it receives data. We don't fetch data from the datastore every time a request comes in since that would negatively impact model performance. To load it during init, you can use the extra dockerfile parameter to copy the data into the web service image as it’s being built so you don’t have to mess around with fetching data over the network at run time.

@jpe316 - Can you provide any additional guidance here?

CC: @Blackmist @j-martens

j-martens avatar May 23 '19 13:05 j-martens

I cant copy all the data in the docker image while building as the data on which this scoring scripts will work and do inferencing, will be the user input who is using the deployed model. For example, User wants to input the name of the image which is stored on some blob storage and want to generate inferencing on this image and return the results. Or please let me know what should be the preferred way ?

amardeepjaiman avatar May 27 '19 12:05 amardeepjaiman

@nibaccam @rongduan-zhu

nibaccam avatar Jun 13 '19 22:06 nibaccam

@amardeepjaiman Sorry for the time it's taken to get back to you on this, and thanks for the interesting scenario.

The functionality that you are looking for is not something covered by the Azure Machine Learning service or SDK. This will require custom code, probably using the Azure Storage Python SDK.

Assuming that the images are updated outside of the model (users can upload images at any time and then ask the model to do inference on them), the pattern to solve this would look something like this:

  1. user passes the name of the image.
  2. in the score.py, the run function would parse the incoming request data (JSON) and extract the field containing the name.
  3. custom code would use the name to construct the path to the image in the blob, and use the Azure Storage SDK to read in the image data.
  4. The image data would then be sent to the model for inference. Depending on what the model expects (size, data format) you might need custom code to do transformations.

Since loading the image and applying transforms would take time, and given enough time the web request might time out, I would recommend putting whatever transforms are needed to get the image in the format that the model expects into the portion of this solution that uploads the image.

That's really about all I can recommend on this, as we are the documentation team and don't provide custom code solutions. If you need to go further on this and get working code, I would recommend Microsoft Consulting Services.

I'll also recommend that the engineering team consider doing a sample based on this scenario, though I cannot provide any guarantees that one will be created.

Blackmist avatar Jun 14 '19 14:06 Blackmist

Closed per Blackmist

kenkadota avatar Jul 08 '19 16:07 kenkadota

@amardeepjaiman Thanks again for bringing this up. Since this isn't currently provided by the SDK, can you post it as a feature suggestion/request at https://feedback.azure.com/forums/257792-machine-learning ? The engineering team uses the suggestions posted here to improve the product.

Blackmist avatar Jul 08 '19 19:07 Blackmist

Thanks @Blackmist

amardeepjaiman avatar Jul 12 '19 15:07 amardeepjaiman