Skip to content Skip to sidebar Skip to footer

Importing Images Azure Machine Learning Studio

Is it possible to import images from your Azure storage account from within a Python script module as opposed to using the Import Images module that Azure ML Studio provides. Ideal

Solution 1:

yes, you should be able to do that using Python. At the very least, straight REST calls should work.

Solution 2:

Based on my understanding, I think you want to get the grayscale data of a image which comes from Azure Blob Storage via the method cv2.imread of python-opencv2.

I tried to write a python script using azure-storage==0.20.3 package to do it. Here is my sample code as below.

from azure.storage.blob import BlobService
import numpy
import cv2

service = BlobService(account_name='<your storage account name>', account_key='<your storage account key>')
blob = service.get_blob_to_bytes('mycontainer', 'test.jpg')
printtype(blob)
np_array = numpy.fromstring(blob, numpy.uint8)
print np_array
img = cv2.imdecode(np_array, cv2.CV_LOAD_IMAGE_COLOR)

If using the latest azure-storage package, make sure that using the code as below.

from azure.storage.blob importBlockBlobServiceservice= BlockBlobService(account_name='<your storage account name>', account_key='<your storage account key>')

The code above works fine on local environment, but it doesn't work as a Execute Python Script module on the Experiments of Azure ML Studio, because of missing the required Python packages azure-storage & cv2. Then I tried to follow the document Adding Python Script as a Custom Resource to add these packages, but failed that I realized the python-opencv2 package is depended on the C native library opencv2.

So per my experience, I think the simple & workaround way is that computing the grayscale data with the RGB data in dataframe from Import Images module of OpenCV Library Modules.

Hope it helps.

Post a Comment for "Importing Images Azure Machine Learning Studio"