第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

在 Tensorflow 數(shù)據(jù)集管道中返回不同長度的數(shù)組

在 Tensorflow 數(shù)據(jù)集管道中返回不同長度的數(shù)組

慕虎7371278 2023-08-22 10:42:35
我正在 python 中使用 Tensorflow 進(jìn)行對象檢測。我想使用張量流輸入管道來加載批量輸入數(shù)據(jù)。問題是圖像中的對象數(shù)量是可變的。想象一下我想做以下事情。注釋是圖像文件名及其包含的邊界框的數(shù)組。標(biāo)簽被排除在外。每個(gè)邊界框由四個(gè)數(shù)字表示。import tensorflow as tf@tf.function()def prepare_sample(annotation):    annotation_parts = tf.strings.split(annotation, sep=' ')    image_file_name = annotation_parts[0]    image_file_path = tf.strings.join(["/images/", image_file_name])    depth_image = tf.io.read_file(image_file_path)    bboxes = tf.reshape(annotation_parts[1:], shape=[-1,4])    return depth_image, bboxesannotations = ['image1.png 1 2 3 4', 'image2.png 1 2 3 4 5 6 7 8']dataset = tf.data.Dataset.from_tensor_slices(annotations)dataset = dataset.shuffle(len(annotations))dataset = dataset.map(prepare_sample)dataset = dataset.batch(16)for image, bboxes in dataset:  pass在上面的示例中,image1 包含單個(gè)對象,而 image2 包含兩個(gè)對象。我收到以下錯(cuò)誤:InvalidArgumentError:無法將張量添加到批次:元素?cái)?shù)量不匹配。形狀為:[張量]:[1,4],[批次]:[2,4]這就說得通了。我正在尋找從映射函數(shù)返回不同長度數(shù)組的方法。我能做些什么?謝謝你!編輯:我想我找到了解決方案;我不再收到錯(cuò)誤。我dataset.batch(16)改為dataset.padded_batch(16).
查看完整描述

1 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊


dataset.batch(16)更改為 后該錯(cuò)誤將得到解決dataset.padded_batch(16)。


下面是相同的修改后的代碼。


import tensorflow as tf


@tf.function()

def prepare_sample(annotation):

? ? annotation_parts = tf.strings.split(annotation, sep=' ')

? ? image_file_name = annotation_parts[0]

? ? image_file_path = tf.strings.join(["/images/", image_file_name])

? ? depth_image = tf.io.read_file(image_file_path)

? ? bboxes = tf.reshape(annotation_parts[1:], shape=[-1,4])

? ? return depth_image, bboxes


annotations = ['image1.png 1 2 3 4', 'image2.png 1 2 3 4 5 6 7 8']

dataset = tf.data.Dataset.from_tensor_slices(annotations)

dataset = dataset.shuffle(len(annotations))

dataset = dataset.map(prepare_sample)

dataset = dataset.padded_batch(16)


for image, bboxes in dataset:

? pass



查看完整回答
反對 回復(fù) 2023-08-22
  • 1 回答
  • 0 關(guān)注
  • 4450 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號