kbressem / faimed3d

Extension to fastai for volumetric medical data
MIT License
33 stars 13 forks source link

ImageDataLoaders3D.from_df lops off leading '/' and then says it can't find the file #69

Closed paul-reiners closed 6 months ago

paul-reiners commented 7 months ago

I have data that looks like this:

,level_0,index,file,Gd,loes-score,max-saliency,max-saliency-x,max-saliency-y,max-saliency-z,prediction,error,saliency-map-file
0,126,158,/home/feczk001/shared/data/loes_scoring/nascene_deid/BIDS/defaced/sub-6421HECH_ses-20140922_space-MNI_mprage.nii.gz,0,3.5,4.666442945653425,44,66,138,3.4262464046478267,0.07375359535217285,/home/feczk001/shared/projects/S1067_Loes/data/MNI-space_Loes_data_saliency/sub-6421HECH_ses-20140922_space-MNI_mprage_salience.nii.gz
1,127,102,/home/feczk001/shared/data/loes_scoring/nascene_deid/BIDS/defaced/sub-6421HECH_ses-20140922_space-MNI_mprageGd.nii.gz,1,3.5,6.463980875508624,68,85,86,3.405237197875977,0.09476280212402344,/home/feczk001/shared/projects/S1067_Loes/data/MNI-space_Loes_data_saliency/sub-6421HECH_ses-20140922_space-MNI_mprageGd_salience.nii.gz
2,139,35,/home/feczk001/shared/data/loes_scoring/nascene_deid/BIDS/defaced/sub-5896ZAMC_ses-20130130_space-MNI_mprage.nii.gz,0,3.0,6.3110978556663735,66,100,80,3.2402114868164062,0.24021148681640625,/home/feczk001/shared/projects/S1067_Loes/data/MNI-space_Loes_data_saliency/sub-5896ZAMC_ses-20130130_space-MNI_mprage_salience.nii.gz
3,135,58,/home/feczk001/shared/data/loes_scoring/nascene_deid/BIDS/defaced/sub-5896ZAMC_ses-20121129_space-MNI_mprage.nii.gz,0,3.0,5.2144760142388185,42,43,50,3.2648842334747314,0.26488423347473145,/home/feczk001/shared/projects/S1067_Loes/data/MNI-space_Loes_data_saliency/sub-5896ZAMC_ses-20121129_space-MNI_mprage_salience.nii.gz
4,128,64,/home/feczk001/shared/data/loes_scoring/nascene_deid/BIDS/defaced/sub-6133TEPO_ses-20130416_space-MNI_mprage.nii.gz,0,3.0,5.013212930617059,64,98,76,3.2893197536468506,0.2893197536468506,/home/feczk001/shared/projects/S1067_Loes/data/MNI-space_Loes_data_saliency/sub-6133TEPO_ses-20130416_space-MNI_mprage_salience.nii.gz

I then have this code:

dls = ImageDataLoaders3D.from_df(d, 
                                 fn_col = 'file', 
                                 label_col = 'loes-score',
                                 item_tfms = ResizeCrop3D(crop_by = (0., 0.1, 0.1), 
                                                          resize_to = (20, 150, 150), 
                                                          perc_crop = True),
                                 bs = 2, 
                                 )

which gives me this error while trying to process the first row:

TypeError: the path "home/feczk001/shared/projects/S1067_Loes/data/MNI-space_Loes_data/sub-5828KAFA_ses-20120620_space-MNI_mprageGd.nii.gz" is neither a valid directory nor a file

Note the missing '/' at the beginning of the file path in the error message. The leading '/' is not missing from the file column of the dataframe.

kbressem commented 6 months ago

It has been a long time, since I worked on this project and fastai also underwent a lot of changes. Please make sure you use the correct version of fastai. If I remember correctly, the csv should filenames relative to the path variable in the from_df function. Try adding path='/'

paul-reiners commented 6 months ago

Yes, that fixed it.