2 回答

TA貢獻1818條經驗 獲得超11個贊
有一個 Tensorflow-io 包現在允許這樣做。它相當簡單。
安裝包:
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)

TA貢獻1818條經驗 獲得超8個贊
在 中pydicom.dcmread(img_path),img_path是 tf.string 張量。我不認為pydicom支持讀取張量對象。
我找到了一種解決方法,它是在 tensorflow 中提供 DICOM 操作的 gradient_decode_dicom 。以下代碼改編自此 colab,并在 tf2.0 上進行了測試。
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)
添加回答
舉報