Coder Social home page Coder Social logo

choosehappy / pytorchdigitalpathology Goto Github PK

View Code? Open in Web Editor NEW
120.0 7.0 66.0 31.34 MB

An implementation of Unet for pytorch designed for digital pathology segmentation

License: MIT License

MATLAB 0.01% Jupyter Notebook 94.65% Python 5.34%

pytorchdigitalpathology's People

Contributors

choosehappy avatar fuschiarlz avatar julienmassonnet avatar pjl54 avatar rahulnair502 avatar rlzcoding avatar tasvora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorchdigitalpathology's Issues

Adaptions for n_classes>2

Thank you for sharing this sophisticated script.
I got problems figuring out which exact changes to make in order to run it with data containing 7 classes of which I want to ignore the one containing background: first while making th hdf5 file and second during the training.
Is it possible you could explain the corresponding lines in detail?

colab

E possivel rodar esse projeto no colab ?

Bug From PILLOW? Integer Overflow

For data sets occasionally containing slides with too many regions or area > 4-byte INT_MAX, a runtime error will be reported from the lower level operations on PILs, while using cv2.imread.

DataLoader IndexError: Index out of range

I am loading my data into a pytable according to your code. Then, I am trying to train the U - net using your code as is. I get and IndexError: Index out of range at line

for ii, ( X, y, y_weight) in enumerate( dataLoader[ phase]):

How could I resolve this? When I am using the dataset[ phase] directly it works without any problem so far.

EDIT : I have solved the issue be resolving a bug in creating the pytable database. Previously the database was being created successfully without showing that bug. An indicator of the bug is when the amount of patch images is not the same as the amount of mask/label patch images.

Thanks.

Squeeze the patches of masks before appending them to ndarray may be unnecessary or raise errors.

Hi,
it appears that the slicing in numpy array would automatically remove the trailing singleton dimension.
The slice io_arr_out[:,:,:,0] is already npatches x patch_size x patch_size, given that the shape of io_arr_out is
npatches x patch_size x patch_size x 3 (for 3-channel inputs).

Also, in one of my slides, the annotated area without downsampling is already small enough, and the downsampled ROI yields a tile smaller than the patch_size, which makes its padded version of io_arr_out
to be 1x patch_size x patch_size x 3.

Using squeeze will incorrectly collapse the leading singleton dimension which we don't want to drop, and raise errors because the rank of the result will mismatch the rank of the hdf5 array.

TypeError: self.dims,self.dims_chunk,self.maxdims cannot be converted to a Python object for pickling

I used the project on your website from here and nuclei dataset on your dataset from here
after I made the pytable file by make_hdf5.py

patch_size=500 #size of the tiles to extract and save in the database, must be >= to training size
stride_size=250 #distance to skip between patches, 1 indicated pixel wise extraction, patch_size would result in non-overlapping tiles
mirror_pad_size=250 # number of pixels to pad *after* resize to image with by mirroring (edge's of patches tend not to be analyzed well, so padding allows them to appear more centered in the patch)
test_set_size=.1 # what percentage of the dataset should be used as a held out validation/testing set
resize=1 #resize input images
classes=[0,1] #

I train by train_unet.ipnb

but the error showed up

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-a5149657a6ab> in <module>
     16             model.eval()   # Set model to evaluate mode
     17 
---> 18         for ii , (X, y, y_weight) in enumerate(dataLoader[phase]): #for each of the batches
     19             X = X.to(device)  # [Nbatch, 3, H, W]
     20             y_weight = y_weight.type('torch.FloatTensor').to(device)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in __iter__(self)
    191 
    192     def __iter__(self):
--> 193         return _DataLoaderIter(self)
    194 
    195     def __len__(self):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\utils\data\dataloader.py in __init__(self, loader)
    467                 #     before it starts, and __del__ tries to join but will get:
    468                 #     AssertionError: can only join a started process.
--> 469                 w.start()
    470                 self.index_queues.append(index_queue)
    471                 self.workers.append(w)

~\AppData\Local\Continuum\anaconda3\lib\multiprocessing\process.py in start(self)
    110                'daemonic processes are not allowed to have children'
    111         _cleanup()
--> 112         self._popen = self._Popen(self)
    113         self._sentinel = self._popen.sentinel
    114         # Avoid a refcycle if the target function holds an indirect

~\AppData\Local\Continuum\anaconda3\lib\multiprocessing\context.py in _Popen(process_obj)
    221     @staticmethod
    222     def _Popen(process_obj):
--> 223         return _default_context.get_context().Process._Popen(process_obj)
    224 
    225 class DefaultContext(BaseContext):

~\AppData\Local\Continuum\anaconda3\lib\multiprocessing\context.py in _Popen(process_obj)
    320         def _Popen(process_obj):
    321             from .popen_spawn_win32 import Popen
--> 322             return Popen(process_obj)
    323 
    324     class SpawnContext(BaseContext):

~\AppData\Local\Continuum\anaconda3\lib\multiprocessing\popen_spawn_win32.py in __init__(self, process_obj)
     87             try:
     88                 reduction.dump(prep_data, to_child)
---> 89                 reduction.dump(process_obj, to_child)
     90             finally:
     91                 set_spawning_popen(None)

~\AppData\Local\Continuum\anaconda3\lib\multiprocessing\reduction.py in dump(obj, file, protocol)
     58 def dump(obj, file, protocol=None):
     59     '''Replacement for pickle.dump() using ForkingPickler.'''
---> 60     ForkingPickler(file, protocol).dump(obj)
     61 
     62 #

~\AppData\Local\Continuum\anaconda3\lib\site-packages\tables\hdf5extension.cp37-win_amd64.pyd in tables.hdf5extension.Array.__reduce_cython__()

TypeError: self.dims,self.dims_chunk,self.maxdims cannot be converted to a Python object for pickling

what mistake did I make?

Edges and Loss function

  1. In the image attached,

image

no edge is shown, although I would expect one. If I re - run the cell, sometimes an edge is shown, sometimes is not. Is this normal? I use edge_weight = 10 to help NN to separate better one region from the other. I apply the following transformations,

INPUT IMAGE TRANS
transforms.ToPILImage()
, transforms.RandomVerticalFlip()
, transforms.RandomHorizontalFlip()
# these need to be in a reproducible order, first affine transforms and then color
, transforms.RandomCrop(size=(patch_size,patch_size),pad_if_needed=True)
, transforms.RandomResizedCrop(size=patch_size)
, transforms.RandomAffine( 90, translate = (0.5, 0.5), scale = ( 0.5, 2.5))
, transforms.RandomRotation(180)
, transforms.ColorJitter(brightness=0, contrast=0, saturation=0, hue=.5)
, transforms.RandomGrayscale()
, transforms.ToTensor()

LABEL IMAGE TRANS
transforms.ToPILImage()
, transforms.RandomVerticalFlip()
, transforms.RandomHorizontalFlip()
# these need to be in a reproducible order, first affine transforms and then color
, transforms.RandomCrop( size = ( patch_size, patch_size), pad_if_needed = True)
, transforms.RandomResizedCrop( size = patch_size, interpolation = PIL.Image.NEAREST)
, transforms.RandomAffine( 90, translate = (0.5, 0.5), scale = ( 0.5, 2.5))
, transforms.RandomRotation( 180)

  1. In the original paper and your code, CrossEntropyLoss is used which in Pytorch is designed for multi class classification (-log of soft max). Given that the network outputs a binary mask, shouldn't Binary Cross Entropy Loss employed instead? If so, the output should be [N, 1, H, W] instead of [N, Nclass, H, W] that is now, in order to work properly. Is this correct? What's the meaning of Nclass?

Thanks, happy July :)

typo?

The block_shape expect the mask to be 3-channel patches, while the squeeze operation only performs on the 1st channel only, which is also what is pushed into the h5 array.

make_output_unet_cmd.py excution

i use this
ipdb> make_output_unet_cmd.py imgBF.tif --model epistroma_unet_best_model,pth
ipdb> make_output_unet_cmd.py *.tif --model epistroma_unet_best_model,pth

but it make error.

invaild syntax. how i can solve this.

tif file and pth file exist at same file

i use window

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.