【只需2步快速解决tensorflow-hub的调用问题】

快速解决tensorflow-hub的调用问题!!


再经历无数次试错之后,终于可以跑tensorflow-hub了,在此写出来,让大家少走弯路。

1、用pip安装库

首先一定要用pip来安装如下的包。(原因:text包需要用pip安装,conda链接找不到。同时text包安装会自动下载tensorflow)

tensorflow              2.6.2
tensorflow-addons       0.16.1
tensorflow-estimator    2.6.0
tensorflow-hub          0.8.0
tensorflow-text         2.6.0

2、用conda下载安装tensorflow-gpu

conda下载gpu的tensorflow

tensorflow              2.6.0

大功告成,可以去跑了!

错误分析

  1. no module keras ;解决:pip没下载tensorflow
  2. KeyError:'CaseFoldUTF8;解决:没有下载tensorflow-text,
    需要import tensorflow_text as text
  3. hub.KerasLayer(URL) 链接内的model无法下载
   preprocess = hub.KerasLayer(
       "https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/2",
       name="text_preprocessing",
   )
   # Load the pre-trained BERT model to be used as the base encoder.
   bert = hub.KerasLayer(
       "https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-512_A-8/1",
       "bert",
   )

解决:
(1)国外链接要下载内容,你懂的

(2)手动复制链接内容到浏览器,可以下载文件夹,然后把代码中链接更改为本地文件。

    preprocess = hub.KerasLayer(
        r"D:\bert_en_uncased_preprocess_3",
        name="text_preprocessing",
    )
    # Load the pre-trained BERT model to be used as the base encoder.
    bert = hub.KerasLayer(
        r"D:\small_bert_bert_en_uncased_L-4_H-512_A-8_2",
        "bert",
    )

(3)更改链接

#tfhub_bert="https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-128_A-2/1"
tfhub_bert="https://storage.googleapis.com/tfhub-modules/tensorflow/small_bert/bert_en_uncased_L-2_H-128_A-2/1.tar.gz"
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

押波张飞

觉得有用,是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值