微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用泡菜或莳萝从天蓝色Blob存储中读取文件而不保存到磁盘

如何解决使用泡菜或莳萝从天蓝色Blob存储中读取文件而不保存到磁盘

我正在尝试从Python中的Azure存储Blob读取机器学习模型的权重。它应该正在运行i Azure Functions,所以我认为我无法使用将Blob保存到磁盘的方法

我正在使用azure-storage-blob 12.5.0,而不是旧版本。

我尝试使用Dill.loads加载.pkl文件,如下所示:

<Button Content="{Binding}"
        CommandParameter="{Binding RelativeSource={RelativeSource Self}}"
        Command="{Binding DataContext.testCommand,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
        Width="20"
        Margin="10,0"/>

哪个返回:

connection_string = 'my_connection_string'
blob_client = BlobClient.from_connection_string(connection_string,container_name,blob_name)
downloader = blob_client.download_blob(0)

with BytesIO() as f:
    downloader.readinto(f)
    weights = dill.loads(f)

我不确定使用Pickle的方法会如何。有人对如何解决这个问题有建议吗?非常感谢您的帮助!

解决方法

对于任何潜在的未来读者,这是解决此问题的方法:

def get_weights_blob(BLOB_NAME = None):
    connection_string = 'my_connection_string'
    blob_client = BlobClient.from_connection_string(connection_string,container_name,blob_name)
    downloader = blob_client.download_blob(0)

    # Load to pickle
    b = downloader.readall()
    weights = pickle.loads(b)

    return weights

然后使用以下功能检索权重:

weights = get_weights_blob(blob_name = 'myPickleFile')
,

这是我的工作样本

100px

和requirements.txt文件

def main(req: func.HttpRequest) -> func.HttpResponse:

 connection_string = ''
    blob_client = BlobClient.from_connection_string(connection_string,'blog-storage-containe','blobfile')
    downloader = blob_client.download_blob(0)

b = downloader.readall()
loaded_model = pickle.loads(b)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。