我有視頻字幕專案的資料集。用于訓練的資料集管道構建為:
dataset = tf.data.Dataset.from_tensor_slices((videos , tf.ragged.constant(captions)))
我想讀取所有進入訓練步驟的batch_data ,如下所示:
class VideoCaptioningModel(keras.Model):
.
.
.
def train_step(self, batch_data):
batch_img, batch_seq = batch_data
batch_loss = 0
batch_acc = 0
print('batch_data=', batch_data)
.
.
輸出是:
batch_data= (<tf.Tensor 'IteratorGetNext:0' shape=(None, 28, 1536) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None, 8) dtype=int64>)
我嘗試使用print('batch_data=', batch_data.numpy())
,但我得到了:
AttributeError: 'tuple' object has no attribute 'numpy'
uj5u.com熱心網友回復:
您的資料集由videos和組成,并且資料集中的captions每個條目都是一個tuple. 看:
for x in dataset:
tf.print(x[0]) # videos
tf.print(x[1]) # captions
現在,請注意您可以呼叫.numpy()intf.Tensor模式Eager Execution,但元組沒有此屬性。所以試試:
tf.print('batch_data=', batch_data[0].numpy())
tf.print('batch_data=', batch_data[1].numpy())
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524098.html
標籤:Python张量流数据集
上一篇:資料集形狀不正確的張量流
下一篇:InvalidArgumentError:輸入檔案名張量必須是標量,但具有形狀:[1][Op:ReadFile]
