ysbecca / py-wsi

Python package for dealing with whole slide images (.svs) for machine learning, particularly for fast prototyping. Includes patch sampling and storing using OpenSlide. Patches may be stored in LMDB, HDF5 files, or to disk. It is highly recommended to fork and download this repository so that personal customisations can be made for your work.
https://ysbecca.github.io/programming/2018/05/22/py-wsi.html
GNU General Public License v3.0
161 stars 93 forks source link

Help Needed: Encountered Following Error : Unable to process images further #2

Closed hitesha14 closed 6 years ago

hitesha14 commented 6 years ago

There are 3 Images, 3 XML files and 3 .svs files. I am using Aperio Image Scope for processing. I have installed required libraries, set the paths correctly. These are my parameters, file directory of SVS images, patch size, level (magnification), and overlap.

import py_wsi import lmdb file_dir = "C:/Users/hits/filesxml/" xml_dir = file_dir patch_size = 200 level = 2 db_location = "" db_name = "patch_db" overlap = 0

I am encountering following error: ValueError: not enough values to unpack (expected 4, got 0). There is problem with this code line augment = False. I have gone through your code base, haven't been able to figure out the problem.

The stack trace is given below:

import py_wsi.dataset as ds import py_wsi.imagepy_toolkit as imagepy_toolkit dataset = ds.read_datasets(turtle, set_id=1, valid_id=0, total_sets=2, shuffle_all=True, augment=False) ValueError Traceback (most recent call last)

in () 4 total_sets=2, 5 shuffle_all=True, ----> 6 augment=False) C:\Users\hits\Anaconda3\lib\site-packages\py_wsi\dataset.py in read_datasets(turtle, set_id, valid_id, total_sets, shuffle_all, augment, is_test) 155 dataset.valid = fetch_dataset(turtle, valid_id, total_sets, augment) 156 if shuffle_all: --> 157 dataset.train.shuffle_all() 158 dataset.valid.shuffle_all() 159 C:\Users\hits\Anaconda3\lib\site-packages\py_wsi\dataset.py in shuffle_all(self) 76 list_all = list(zip(self._images, self._labels, self._image_cls, self._coords)) 77 random.shuffle(list_all) ---> 78 self._images, self._labels, self._image_cls, self._coords = zip(*list_all) 79 80 # [self._images, self._labels, self._image_cls, self._ids, self._coords] = \ ValueError: not enough values to unpack (expected 4, got 0)
ysbecca commented 6 years ago

I think the error is not with the augment but with the shuffle_all. When it is trying to shuffle the train object - i.e., shuffle all the images with their labels, classes and coords, it is finding that there are no images. Try with shuffle_all=False and then output len(dataset.train.images). My guess is that this will be 0. It is possible that the combination of your selected patch_size and level actually return no patches.

I am currently working on an update to py_wsi which will add three major improvements which will be helpful in general, and particularly when dealing with much larger datasets:

I will also post a blog post soon on understanding patch_size and tile level. The test patch sampling functionality should also be very helpful. I would strongly suggest downloading the update when it is available, and I appreciate any feedback after that.