首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从存储桶中打开FastText进行加载

无法从存储桶中打开FastText进行加载
EN

Stack Overflow用户
提问于 2021-07-10 17:38:35
回答 1查看 194关注 0票数 1

我下载了fasttext model li.176.bin。如果我在文件夹中使用model在本地运行我的代码,一切都很好。但我需要在GC中运行它,所以,我将模型上传到存储桶中,并将路径从本地更改为gs存储桶,得到一个错误:ValueError: gs://models/fasttext-model/lid.176.bin cannot be opened for loading!我如何使用存储桶中的模型?

代码语言:javascript
运行
复制
path_to_pretrained_model = 'gs://models/fasttext-model/lid.176.bin'
fasttext_model = fasttext.load_model(path_to_pretrained_model)
EN

回答 1

Stack Overflow用户

发布于 2021-07-13 18:24:50

Google Documentation的这个函数可以帮助我解决这个问题

代码语言:javascript
运行
复制
from google.cloud import storage


def download_blob(bucket_name, source_blob_name, destination_file_name):
    """Downloads a blob from the bucket."""
    # bucket_name = "your-bucket-name"
    # source_blob_name = "storage-object-name"
    # destination_file_name = "local/path/to/file"

    storage_client = storage.Client()

    bucket = storage_client.bucket(bucket_name)

    # Construct a client side representation of a blob.
    # Note `Bucket.blob` differs from `Bucket.get_blob` as it doesn't retrieve
    # any content from Google Cloud Storage. As we don't need additional data,
    # using `Bucket.blob` is preferred here.
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name)

    print(
        "Blob {} downloaded to {}.".format(
            source_blob_name, destination_file_name
        )
    )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68326536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档