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

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

從張量字符串加載圖像

從張量字符串加載圖像

一只斗牛犬 2022-06-22 19:01:18
我創(chuàng)建了一個(gè)字符串的 Tensorflow 數(shù)據(jù)集(其中每個(gè)字符串都是 dicom 圖像的路徑),我想將預(yù)處理函數(shù)映射到數(shù)據(jù)集。預(yù)處理函數(shù)應(yīng)該使用pydicom包從 dicom 文件加載像素?cái)?shù)組。但是當(dāng)我嘗試映射一個(gè)函數(shù)時(shí),雖然我得到一個(gè)屬性錯(cuò)誤。如何使用如下函數(shù)從張量中讀取字符串值?我正在使用 Tensorflow 2.0.0 和 pydicom 1.3.0。AttributeError: in converted code:    <ipython-input-12-eff65198c202>:12 load_and_preprocess_image  *        dicom_data = pydicom.dcmread(img_path)    /opt/conda/lib/python3.6/site-packages/pydicom/filereader.py:849 dcmread  *        dataset = read_partial(fp, stop_when, defer_size=defer_size,    /opt/conda/lib/python3.6/site-packages/pydicom/filereader.py:651 read_partial  *        preamble = read_preamble(fileobj, force)    /opt/conda/lib/python3.6/site-packages/pydicom/filereader.py:589 read_preamble  *        preamble = fp.read(128)    AttributeError: 'Tensor' object has no attribute 'read'這是我創(chuàng)建數(shù)據(jù)集并將預(yù)處理函數(shù)映射到它的代碼。def load_and_preprocess_image(img_path):    """ Load image, resize, and normalize the image"""    dicom_data = pydicom.dcmread(img_path))    image = tf.convert_to_tensor(dicom_data.pixel_array, dtype=tf.float32)    return image# Create dataset (list of strings that lead to dicom paths)image_train_ds = tf.data.Dataset.from_tensor_slices(dicom_files_list)# Map a preprocessing function to list of dicom pathsimage_train_ds = image_train_ds.map(load_and_preprocess_image)
查看完整描述

2 回答

?
慕尼黑8549860

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

有一個(gè) Tensorflow-io 包現(xiàn)在允許這樣做。它相當(dāng)簡(jiǎn)單。


安裝包:

pip install -q tensorflow-io

import tensorflow_io as tfio


def load_and_preprocess_image(img_path):

    _bytes = tf.io.read_file(img_path)

    dicom_data = tfio.image.decode_dicom_image(_bytes, dtype=tf.float32)

    return dicom_data


dicom_files_list = ['path/to/dicom']


# Create dataset (list of strings that lead to dicom paths)

image_train_ds = tf.data.Dataset.from_tensor_slices(dicom_files_list)

image_train_ds = image_train_ds.map(load_and_preprocess_image)


查看完整回答
反對(duì) 回復(fù) 2022-06-22
?
弒天下

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

在 中pydicom.dcmread(img_path),img_path是 tf.string 張量。我不認(rèn)為pydicom支持讀取張量對(duì)象。


我找到了一種解決方法,它是在 tensorflow 中提供 DICOM 操作的 gradient_decode_dicom 。以下代碼改編自此 colab,并在 tf2.0 上進(jìn)行了測(cè)試。


def load_and_preprocess_image(img_path):

    _bytes = tf.io.read_file(img_path)

    dicom_data = decode_dicom_image(_bytes, dtype=tf.float32)

    return dicom_data


dicom_files_list = ['path/to/dicom']


# Create dataset (list of strings that lead to dicom paths)

image_train_ds = tf.data.Dataset.from_tensor_slices(dicom_files_list)

image_train_ds = image_train_ds.map(load_and_preprocess_image)


查看完整回答
反對(duì) 回復(fù) 2022-06-22
  • 2 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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