亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Tensorflow Hub 形狀未定義

Tensorflow Hub 形狀未定義

揚帆大魚 2023-07-11 18:55:08
我正在嘗試加載預先訓練的嵌入模型,但無論我給出什么形狀,我都找不到輸入形狀。這似乎是一個非常受歡迎的選擇,但我在張量流中心頁面上找不到任何關于要使用什么輸入形狀的指示符。輸入序列應該具有可變長度,因此我使用無輸入形狀。Keras 自動提供批量大小embedding_url = 'https://tfhub.dev/google/universal-sentence-encoder-large/5'embedding_layer = hub.KerasLayer(embedding_url)premises = tf.keras.Input(shape=(None,))conclusion = tf.keras.Input(shape=(None,))x1 = embedding_layer(premises)x2 = embedding_layer(conclusion) model = tf.keras.Model(inputs=[premises, conclusion], outputs=[x1, x2])這是我得到的錯誤ValueError: Python inputs incompatible with input_signature:      inputs: (        Tensor("input_5:0", shape=(None, None), dtype=float32))      input_signature: (        TensorSpec(shape=<unknown>, dtype=tf.string, name=None))
查看完整描述

1 回答

?
HUH函數

TA貢獻1836條經驗 獲得超4個贊

您可以通過將輸入形狀參數保留為空元組來將功能 API 與 KerasLayer 結合使用。


代碼:


import tensorflow_hub as hub

import tensorflow as tf

embedding_url = 'https://tfhub.dev/google/universal-sentence-encoder-large/5'


premises = tf.keras.layers.Input(shape=(), name="Input1", dtype=tf.string)

conclusion = tf.keras.layers.Input(shape=(), name="Input2", dtype=tf.string)

embedding_layer = hub.KerasLayer(embedding_url)

x1 = embedding_layer(premises)

x2 = embedding_layer(conclusion)


model = tf.keras.Model(inputs=[premises, conclusion], outputs=[x1, x2])

tf.keras.utils.plot_model(model, 'my_first_model.png', show_shapes=True)

你的模型看起來像這樣:

http://img1.sycdn.imooc.com//64ad353a00015cfb06410182.jpg

查看完整回答
反對 回復 2023-07-11
  • 1 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號