Did you look directly at image.size
? It depends a little on the preprocessing that was done specifically for that Kaggle competition, but MRI files are often 4D. Don’t just assume it’s 3. Or that it can be read easily with vanilla Python file operations.
You might also take a peek at one of the submitted notebooks. This one, for example,
seems to have code that reads the data files from that competition.
def load_dicom(path):
dicom=pydicom.read_file(path)
data=dicom.pixel_array
data=data-np.min(data)
if np.max(data) != 0:
data=data/np.max(data)
data=(data*255).astype(np.uint8)
return data
train_dir='../input/rsna-miccai-brain-tumor-radiogenomic-classification/train'
trainset=[]
trainlabel=[]
trainidt=[]
for i in tqdm(range(len(train_df))):
idt=train_df.loc[i,'BraTS21ID']
idt2=('00000'+str(idt))[-5:]
path=os.path.join(train_dir,idt2,'T1wCE')
for im in os.listdir(path):
img=load_dicom(os.path.join(path,im))
img=cv.resize(img,(64,64))
image=img_to_array(img)
image=image/255.0
trainset+=[image]
trainlabel+=[train_df.loc[i,'MGMT_value']]
trainidt+=[idt]
Notice that it relies on the Python package Pydicom
. https://pydicom.github.io/
ps: looks like I’m giving you the same advice @paulinpaloalto gave you here : Cannot batch tensors with different shapes in component 0. First element had shape [224,224,3] and element 2 had shape [224,224,4] - #7 by Rohit_Kumar
You need to understand your data before you try running through code written for other datasets and purposes.