gpt4 book ai didi

python - 如何从本地系统加载 TF hub 模型

转载 作者:行者123 更新时间:2023-12-04 04:31:18 33 4
gpt4 key购买 nike

一种方法是每次从 tensorflow_hub 下载模型喜欢以下

import tensorflow as tf
import tensorflow_hub as hub

hub_url = "https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1"
embed = hub.KerasLayer(hub_url)
embeddings = embed(["A long sentence.", "single-word", "http://example.com"])
print(embeddings.shape, embeddings.dtype)

我想下载一次文件并一次又一次地使用,而不是每次都下载

最佳答案

  • 从 url + "?tf-hub-format=compressed"下载你的模型
    例如“https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1?tf-hub-format=compressed”
  • 解压
  • 在代码中加载未解压的文件夹
  • import tensorflow as tf
    import tensorflow_hub as hub

    embed = hub.KerasLayer('path/to/untarred/folder')
    embeddings = embed(["A long sentence.", "single-word", "http://example.com"])
    print(embeddings.shape, embeddings.dtype)

    关于python - 如何从本地系统加载 TF hub 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60578801/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com