Importing images Azure Machine Learning Studio

删除回忆录丶 提交于 2019-12-12 03:57:30

问题


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. Ideally I would like to use cv2.imread(). I only want to read in grayscale data but the Import Images module reads in RGB. Can I use the BlockBlobService library as if I were calling it from an external Python script?


回答1:


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




回答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')
print type(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 import BlockBlobService

service = 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.



来源:https://stackoverflow.com/questions/42081202/importing-images-azure-machine-learning-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!