mahmoodlab / CLAM

Data-efficient and weakly supervised computational pathology on whole slide images - Nature Biomedical Engineering
http://clam.mahmoodlab.org
GNU General Public License v3.0
1.02k stars 340 forks source link

error reading DIR_TO_COORDS h5 files #171

Closed archanabhardwaj closed 1 year ago

archanabhardwaj commented 1 year ago

Great pipeline to work on WSI data. I am trying to run the data using CLAM pipeline.

I started with .tif files and created patches and stiches using following command

_python create_patches_fp.py --source example_data_AB --save_dir example_data_AB_patches1 --patchsize 256 --seg --patch --stitch

Next, with Cuda enabled conda environment, I used following command to get features from each side.

Option 1 :

DIR_TO_COORDS = example_data_AB_patches1

CUDA_VISIBLE_DEVICES=0 python extract_features_fp.py --data_h5_dir example_data_AB_patches1 --data_slide_dir example_data_AB --csv_path example_data_AB_patches1/process_list_autogen.csv --feat_dir example_data_AB_features1 --batch_size 512 --slide_ext .tif

warn(f"Failed to load image Python extension: {e}") initializing dataset loading model checkpoint

progress: 0/5 normal_002 Traceback (most recent call last): File "/work_beegfs/usr/usr/Images_DATA/CODES/clam/CLAM/extract_features_fp.py", line 113, in output_file_path = compute_w_loader(h5_file_path, output_path, wsi, File "/work_beegfs/usr/usr/Images_DATA/CODES/clam/CLAM/extract_features_fp.py", line 34, in compute_w_loader dataset = Whole_Slide_Bag_FP(file_path=file_path, wsi=wsi, pretrained=pretrained, File "/work_beegfs/usr/usr/Images_DATA/CODES/clam/CLAM/datasets/dataset_h5.py", line 123, in init self.patch_level = f['coords'].attrs['patch_level'] File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "/home/usr/.conda/envs/clam4/lib/python3.10/site-packages/h5py/_hl/attrs.py", line 56, in getitem attr = h5a.open(self._id, self._e(name)) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py/h5a.pyx", line 80, in h5py.h5a.open KeyError: "Can't open attribute (can't locate attribute: 'patch_level')"

Option 2 :

DIR_TO_COORDS = example_data_AB_patches1/patches

warn(f"Failed to load image Python extension: {e}") initializing dataset loading model checkpoint

progress: 0/5 normal_002 Traceback (most recent call last): File "/work_beegfs/usr/usr/Images_DATA/CODES/clam/CLAM/extract_features_fp.py", line 113, in output_file_path = compute_w_loader(h5_file_path, output_path, wsi, File "/work_beegfs/usr/usr/Images_DATA/CODES/clam/CLAM/extract_features_fp.py", line 34, in compute_w_loader dataset = Whole_Slide_Bag_FP(file_path=file_path, wsi=wsi, pretrained=pretrained, File "/work_beegfs/usr/usr/Images_DATA/CODES/clam/CLAM/datasets/dataset_h5.py", line 121, in init with h5py.File(self.file_path, "r") as f: File "/home/usr/.conda/envs/clam4/lib/python3.10/site-packages/h5py/_hl/files.py", line 567, in init fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr) File "/home/usr/.conda/envs/clam4/lib/python3.10/site-packages/h5py/_hl/files.py", line 231, in make_fid fid = h5f.open(name, flags, fapl=fapl) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py/h5f.pyx", line 106, in h5py.h5f.open FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = 'example_data_AB_patches1/patches/patches/normal_002.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

I am getting error while reading h5 files. It would appreciate all the suggestion.

Thanks in advance

fedshyvana commented 1 year ago

If your patching complete successfully, there should be an attribute "patch_level" stored in the .h5 to indicate the level at which it's patched (see here) whereas here i'm not sure its telling you you can't find that attribute.

can you perhaps manually open a few of the .h5 files you have and verify that if one or more of them are missing the attributes?