Skip to content

Can you please provide the exact .xlsx file used to train the CT2Rep model initially. #18

Open

Description

@hari3100

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 .

Activity

  1. Mike-ihr commented on Nov 17, 2024

    @Mike-ihr

    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.

  2. ZZUwxr commented on Nov 27, 2024

    @ZZUwxr

    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

  3. Coldermyy commented on Mar 9, 2025

    @Coldermyy

    @ZZUwxr Hello. Can you share how you did it? Thank you.

  4. ZZUwxr commented on Mar 10, 2025

    @ZZUwxr

    你好。 您能分享一下您是如何做到的吗? 谢谢。

    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)
    
  5. Coldermyy commented on Mar 10, 2025

    @Coldermyy

    你好。 您能分享一下您是如何做到的吗? 谢谢。

    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?

  6. ZZUwxr commented on Mar 10, 2025

    @ZZUwxr
  7. Coldermyy commented on Mar 10, 2025

    @Coldermyy

    Thank you for your answer and have a nice life!

    由于我每个数据项只有两张图片,所以我选择给两张图片加零,以达到将 2d 图片转换为 3d 数据集的效果,如果你已经有 3D 图片,则无需加零,只需将 dcm 格式转换为 npz 数据格式即可
    …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions