You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can you please provide the exact .xlsx file used to train the CT2Rep model initially. #18
I'm trying to infer the CT2Rep model, I have the ct2rep model file with me, Im currently not able to infer it , as the model while converting it's results to human readable words, is expecting a vocabulary that consist of around 2627 words. But I don't have that .xlsx file , It would be really helpful to me , if you could please provide that file.
As I tried using a different train_reports.csv (which I did convert to .xlsx) from 'dataset/radiology_text_reports' , but when using that it showed that the vocabs I had were over 5000 in length and the model only expected 2627.
I did try working around it but I only endup getting a '.' as my tokenized report.
I really appreciate the work you have put into creating this model. I would greatly appreciate any help from your end.
Thank you to both @ibrahimethemhamamci, @sezginerr .
Have you resolved the problem yet? And there are few image samples in the example dataset, and they are all in the format of .npz while files in the CT-RATE are in the format of .nii.gz. I don't know how to convert the .gii.gz format to the correct .npz format.
Have you resolved the problem yet? And there are few image samples in the example dataset, and they are all in the format of .npz while files in the CT-RATE are in the format of .nii.gz. I don't know how to convert the .gii.gz format to the correct .npz format.
Hello, I have solved this problem, if you need to contact, may I ask you to solve the problem of how to use the trained model for inference
import os
import pydicom
import numpy as np
from natsort import natsorted
def convert_dcm_to_npz(input_folder, output_folder_base, target_depth=4):
"""
将指定文件夹中的所有 .dcm 文件转换为 .npz 格式,并按顺序存储在新的子文件夹中。
:param input_folder: 包含 .dcm 文件的源文件夹路径
:param output_folder_base: 转换后文件夹的存储根路径
:param target_depth: 目标3D体积的深度
"""
# 确保输出文件夹存在
if not os.path.exists(output_folder_base):
os.makedirs(output_folder_base)
# 遍历输入文件夹中所有 .dcm 文件
dcm_files = natsorted([f for f in os.listdir(input_folder) if f.endswith('.dcm')])
if not dcm_files:
print("输入文件夹中没有 .dcm 文件!")
return
folder_index = 1 # 子文件夹编号
for dcm_file in dcm_files:
dcm_path = os.path.join(input_folder, dcm_file)
output_folder = os.path.join(output_folder_base, str(folder_index))
# 创建子文件夹
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# 读取 DICOM 文件
dcm_data = pydicom.dcmread(dcm_path)
image_data = dcm_data.pixel_array
# 检查图像是否包含两个切片
if image_data.shape[0] != 2:
print(f"文件 {dcm_file} 不符合包含两个切片的要求,跳过。")
continue
# 获取图像尺寸
height, width = image_data.shape[1], image_data.shape[2]
# 创建目标 3D 体积
volume_data = np.zeros((target_depth, height, width), dtype=image_data.dtype)
# 填充前扫和后扫图像
volume_data[1, :, :] = image_data[0, :, :]
volume_data[3, :, :] = image_data[1, :, :]
# 保存为 .npz 文件
output_npz_path = os.path.join(output_folder, f"volume_{folder_index}.npz")
np.savez_compressed(output_npz_path, arr_0=volume_data)
print(f"{dcm_file} 已转换并保存到 {output_npz_path}")
folder_index += 1
# 示例调用
input_folder = "[20241104]Data" # 替换为实际文件夹路径
output_folder_base = "output_npz_3" # 替换为输出文件夹根路径
convert_dcm_to_npz(input_folder, output_folder_base)
Thanks for your reply, this is very useful for me, but I would like to know why it is necessary to check if the image contains two slices. Doesn't the report in dicom format contain many images?
Since I only have two images for each data item, I chose to add zeros to the two images to achieve the effect of converting 2d images to 3d data sets, if you already have 3d images, you don't need to add zeros, just convert dcm format to npz data format
---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 2025年03月10日 18:59 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.***>***@***.***> |
| 主题 | Re: [ibrahimethemhamamci/CT2Rep] Can you please provide the exact .xlsx file used to train the CT2Rep model initially. (Issue #18) |
你好。 您能分享一下您是如何做到的吗? 谢谢。
import os
import pydicom
import numpy as np
from natsort import natsorted
def convert_dcm_to_npz(input_folder, output_folder_base, target_depth=4):
"""
将指定文件夹中的所有 .dcm 文件转换为 .npz 格式,并按顺序存储在新的子文件夹中。
:param input_folder: 包含 .dcm 文件的源文件夹路径
:param output_folder_base: 转换后文件夹的存储根路径
:param target_depth: 目标3D体积的深度
"""
# 确保输出文件夹存在
if not os.path.exists(output_folder_base):
os.makedirs(output_folder_base)
# 遍历输入文件夹中所有 .dcm 文件
dcm_files = natsorted([f for f in os.listdir(input_folder) if f.endswith('.dcm')])
if not dcm_files:
print("输入文件夹中没有 .dcm 文件!")
return
folder_index = 1 # 子文件夹编号
for dcm_file in dcm_files:
dcm_path = os.path.join(input_folder, dcm_file)
output_folder = os.path.join(output_folder_base, str(folder_index))
# 创建子文件夹
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# 读取 DICOM 文件
dcm_data = pydicom.dcmread(dcm_path)
image_data = dcm_data.pixel_array
# 检查图像是否包含两个切片
if image_data.shape[0] != 2:
print(f"文件 {dcm_file} 不符合包含两个切片的要求,跳过。")
continue
# 获取图像尺寸
height, width = image_data.shape[1], image_data.shape[2]
# 创建目标 3D 体积
volume_data = np.zeros((target_depth, height, width), dtype=image_data.dtype)
# 填充前扫和后扫图像
volume_data[1, :, :] = image_data[0, :, :]
volume_data[3, :, :] = image_data[1, :, :]
# 保存为 .npz 文件
output_npz_path = os.path.join(output_folder, f"volume_{folder_index}.npz")
np.savez_compressed(output_npz_path, arr_0=volume_data)
print(f"{dcm_file} 已转换并保存到 {output_npz_path}")
folder_index += 1
# 示例调用
input_folder = "[20241104]Data" # 替换为实际文件夹路径
output_folder_base = "output_npz_3" # 替换为输出文件夹根路径
convert_dcm_to_npz(input_folder, output_folder_base)
Thanks for your reply, this is very useful for me, but I would like to know why it is necessary to check if the image contains two slices. Doesn't the report in dicom format contain many images?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
Coldermyy left a comment (ibrahimethemhamamci/CT2Rep#18)
你好。 您能分享一下您是如何做到的吗? 谢谢。
import os
import pydicom
import numpy as np
from natsort import natsorted
def convert_dcm_to_npz(input_folder, output_folder_base, target_depth=4):
"""
将指定文件夹中的所有 .dcm 文件转换为 .npz 格式,并按顺序存储在新的子文件夹中。
:param input_folder: 包含 .dcm 文件的源文件夹路径
:param output_folder_base: 转换后文件夹的存储根路径
:param target_depth: 目标3D体积的深度
"""
# 确保输出文件夹存在
if not os.path.exists(output_folder_base):
os.makedirs(output_folder_base)
# 遍历输入文件夹中所有 .dcm 文件
dcm_files = natsorted([f for f in os.listdir(input_folder) if f.endswith('.dcm')])
if not dcm_files:
print("输入文件夹中没有 .dcm 文件!")
return
folder_index = 1 # 子文件夹编号
for dcm_file in dcm_files:
dcm_path = os.path.join(input_folder, dcm_file)
output_folder = os.path.join(output_folder_base, str(folder_index))
# 创建子文件夹
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# 读取 DICOM 文件
dcm_data = pydicom.dcmread(dcm_path)
image_data = dcm_data.pixel_array
# 检查图像是否包含两个切片
if image_data.shape[0] != 2:
print(f"文件 {dcm_file} 不符合包含两个切片的要求,跳过。")
continue
# 获取图像尺寸
height, width = image_data.shape[1], image_data.shape[2]
# 创建目标 3D 体积
volume_data = np.zeros((target_depth, height, width), dtype=image_data.dtype)
# 填充前扫和后扫图像
volume_data[1, :, :] = image_data[0, :, :]
volume_data[3, :, :] = image_data[1, :, :]
# 保存为 .npz 文件
output_npz_path = os.path.join(output_folder, f"volume_{folder_index}.npz")
np.savez_compressed(output_npz_path, arr_0=volume_data)
print(f"{dcm_file} 已转换并保存到 {output_npz_path}")
folder_index += 1
# 示例调用
input_folder = "[20241104]Data" # 替换为实际文件夹路径
output_folder_base = "output_npz_3" # 替换为输出文件夹根路径
convert_dcm_to_npz(input_folder, output_folder_base)
Thanks for your reply, this is very useful for me, but I would like to know why it is necessary to check if the image contains two slices. Doesn't the report in dicom format contain many images?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
Activity
Mike-ihr commentedon Nov 17, 2024
Have you resolved the problem yet? And there are few image samples in the example dataset, and they are all in the format of .npz while files in the CT-RATE are in the format of .nii.gz. I don't know how to convert the .gii.gz format to the correct .npz format.
ZZUwxr commentedon Nov 27, 2024
Hello, I have solved this problem, if you need to contact, may I ask you to solve the problem of how to use the trained model for inference
Coldermyy commentedon Mar 9, 2025
@ZZUwxr Hello. Can you share how you did it? Thank you.
ZZUwxr commentedon Mar 10, 2025
Coldermyy commentedon Mar 10, 2025
Thanks for your reply, this is very useful for me, but I would like to know why it is necessary to check if the image contains two slices. Doesn't the report in dicom format contain many images?
ZZUwxr commentedon Mar 10, 2025
Coldermyy commentedon Mar 10, 2025
Thank you for your answer and have a nice life!