Biooptics2021 / PathFinder

GNU General Public License v3.0
45 stars 4 forks source link

question for Micro_networks transfrom #7

Closed hqh1997 closed 11 months ago

hqh1997 commented 11 months ago

hello, author in Macro_networks train, I can use train_transform. how could I defined the right transform in Micro_networks for PatchesImageDatasetLoader. [https://github.com/Biooptics2021/PathFinder/blob/43da3deaabadd00f0338ef2de6d56dc4855da100/Prognosis/train_test.py#L42C16-L42C16]

LiangJunhao-THU commented 11 months ago

Hi @hqh1997 , In PatchesImageDatasetLoader, we give the model a [16*3, 512, 512] tensor

Imgs = Imgs.reshape((16*3,512,512))

Change the transform as below will work

train_transform = A.Compose( [
A.Resize(512, 512),

A.RandomRotate90(p = 0.75),

        A.Normalize(mean=(0.5,)*48, std=(0.5,)*48),
        ToTensorV2(),
    ]
)
hqh1997 commented 11 months ago

Hi @hqh1997 , In PatchesImageDatasetLoader, we give the model a [16*3, 512, 512] tensor

Imgs = Imgs.reshape((16*3,512,512))

Change the transform as below will work

train_transform = A.Compose( [ A.Resize(512, 512),

A.RandomRotate90(p = 0.75),

A.Normalize(mean=(0.5,)48, std=(0.5,)48), ToTensorV2(), ] )

thank you for your quick response, but it still not working, I try to print the img shape before the transform. get (512, 512, 3) the code below is data_loaders.py Tumour patches Loader part. class PatchesImageDatasetLoader(Dataset): def init(self, patches_filepaths, transform=None): super(PatchesImageDatasetLoader, self).init() self.images_filepaths = patches_filepaths self.transform = transform

def get_files(self, path, rule=".png"):
    all = []
    for fpathe,dirs,fs in os.walk(path):
        for f in fs:
            filename = os.path.join(fpathe,f)
            if filename.endswith(rule):
                all.append(filename)
    return all    

def __len__(self):
    return len(self.images_filepaths)

def __getitem__(self, idx):
    patches_filepath = self.images_filepaths[idx]
    # print(patches_filepath),print('im here')
    patches_paths = self.get_files(patches_filepath)[:16]
    # print( self.get_files(patches_filepath))
    print(patches_paths)
    hospital = patches_filepath.split('/')[-2]
    print(hospital)
    base_dir = INFO_PATH
    self.data = pd.read_csv(base_dir+hospital+'.csv')
    # print(self.data)
    Imgs = []
    for path in patches_paths:
        img = cv2.imread(path)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        print(img.shape)   ###############################it will be (512, 512, 3)
        if self.transform is not None:
            img = self.transform(image=img)["image"]
        img = np.array(img)

        Imgs.append(img)
    Imgs = np.array(Imgs).astype('float64')
    Imgs = Imgs.reshape((16*3,512,512))
hqh1997 commented 11 months ago

I find reason, the code below will work, thank you for your response and excellenet work in pathology, well done @LiangJunhao-THU train_transform = A.Compose( [ A.Resize(512, 512), A.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)), ToTensorV2(), ] )