ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

206 - The right way to segment large images by applying a trained U-Net model on smaller patches

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 มี.ค. 2021
  • Do not apply a model trained on smaller images to directly segment large images -will not work!!! (Code shared to prove this point).
    Divide images into patches of smaller sizes and then perform the prediction.
    Code generated in the video can be downloaded from here:
    github.com/bns...
    Dataset info: Electron microscopy (EM) dataset from
    www.epfl.ch/la...
    To annotate images and generate labels, you can use APEER (for free):
    www.apeer.com
    To install patchify: pip install patchify

ความคิดเห็น • 80

  • @matthewmiller828
    @matthewmiller828 3 ปีที่แล้ว +6

    Incredible, exactly what I needed. Don't stop with these remarkable videos!

  • @pohkeamtan9876
    @pohkeamtan9876 2 ปีที่แล้ว +2

    This video is excellent. I like the negative examples (to prove a point) and the two approaches provided. I was just starting with segmentation with patches training and was struggling with how to handle actual images of various sizes.

  • @rubenguerrerorivera7462
    @rubenguerrerorivera7462 2 ปีที่แล้ว +1

    Awesome! Sreeni is simple amazing, his videos are way packed with a lot of valuable information and still very entertaining!
    One of my favorite channels!

  • @shoghi2547
    @shoghi2547 2 หลายเดือนก่อน

    Great video. If it had also mentioned the solution when the image size is not divisible by 256, that would have been excellent.

  • @kerenzhang5571
    @kerenzhang5571 2 ปีที่แล้ว +3

    I have been using patch-based methods to segment large 3D images. I think the key here is to select the right field of view. Because when you use patches the FOV becomes smaller, many people choose to randomly crop the patches from the original large images. However. there are two issues with too much cropping: 1. The number of training samples will increase too much and some of them have a lot of overlapping so that the training is less efficient. 2. some of the structures need larger context to segment (non-local) and if those important context happens to be cropped out, it's gonna confuse the network. This will not be a big issue if the original images is quite repetitive (same textures like cells). But if it's distinct structure, I don't personally recommend too much random cropping and cascade network might be more useful.

  • @hasannasirkhan2883
    @hasannasirkhan2883 3 ปีที่แล้ว

    Contents are just amazing! Really appreciated your hard work Sir 👍

  • @ai_innovation87
    @ai_innovation87 2 ปีที่แล้ว

    big fan of your content, sir
    from every video i learn something new

  • @rachelbj3840
    @rachelbj3840 2 ปีที่แล้ว

    Thanks Sreeni, I owe you a great deal!!

  • @johanhaggle7949
    @johanhaggle7949 9 หลายเดือนก่อน +2

    You say that patches should be at least 4 times bigger than the objects. But what if the object is not small mitochondria but some bigger object that covers a big part of the image?

  • @reallynotadatascientist
    @reallynotadatascientist ปีที่แล้ว +4

    Hi @DigitalSreeni, thank you for yet another informative lesson!
    I'm wondering though, if you WANT the inference to overlap (so at 21:48 of the video, instead of (256, 256), step = 256, let's say the step = 128), how can you merge those patches of segmentation inference (mask) after the prediction? What would be the correct/efficient way to "reconstructed_image = np.reshape" and "predicted_patches_reshaped = unpatchify"?

  • @isaaclhk
    @isaaclhk ปีที่แล้ว +1

    Wow this so so helpful even after 2 years! This is a gem of a channel. I've got a question for patch based segmentation though. If i wanted to validate and test my model, should i evaluate the performance based on patches? Or should val set be evaluated by patch and test set by the combined image, or should both val and test sets be evaluated based on the whole image? Would greatly appreciate anyone's insight. Thanks!

  • @manishsingh-fv7dr
    @manishsingh-fv7dr 3 ปีที่แล้ว

    Hi Srini ..thanks for uploading this .
    Very informative

  • @uemersonpinheirojunior1267
    @uemersonpinheirojunior1267 2 ปีที่แล้ว +1

    very good! thanks, this tutorial help me a lot

  • @MyNguyen-rt5eb
    @MyNguyen-rt5eb 2 ปีที่แล้ว +3

    Such a great technique and awesome tutorial! I have a question though, what happen if the patch numbers do not fit well with the image size?. In your video, the patch is sufficiently divided into integer number. What would happen if it does not and what should we do with the overlap image?

    • @enesbolukbas8709
      @enesbolukbas8709 2 ปีที่แล้ว +1

      SIZE_X = (image.shape[1]//patch_size)*patch_size #Nearest size divisible by our patch size
      SIZE_Y = (image.shape[0]//patch_size)*patch_size #Nearest size divisible by our patch size
      image = PIL.Image.crop((0 ,0, SIZE_X, SIZE_Y)) #Crop from top left corner

  • @منةالرحمن
    @منةالرحمن 3 ปีที่แล้ว

    You're the best 💖
    I was about to ask you for that
    Thanks

  • @shivamkumar-qp1jm
    @shivamkumar-qp1jm 3 ปีที่แล้ว +2

    Code is not updated on GitHub for this video

  • @jco7257
    @jco7257 3 ปีที่แล้ว

    Thank you for this. Great help! 💙

  • @akshaybatra1777
    @akshaybatra1777 ปีที่แล้ว

    My images are 16 bit grayscale and the masks are boolen (0 and 1). Do I need to convert my normalize images to 0 - 255 range?

  • @JS-tk4ku
    @JS-tk4ku 3 ปีที่แล้ว

    perfect, it's what I'm looking for

  • @johanhaggle7949
    @johanhaggle7949 9 หลายเดือนก่อน +1

    Can you please provide the code in this notebook?

    • @DigitalSreeni
      @DigitalSreeni  9 หลายเดือนก่อน

      all my code is available on my GitHub page, please check the description under the video.

  • @mohammaddehghan8762
    @mohammaddehghan8762 2 ปีที่แล้ว

    this tutorial very helpful for me thank you

  • @jaiswalfelipe1269
    @jaiswalfelipe1269 ปีที่แล้ว

    Hi! could you please elaborate more why setting "None" to input tensors works fine during training and not during inference?

  • @denistran7400
    @denistran7400 2 ปีที่แล้ว

    Thanks for the great video. I'm curious as to why feeding the larger size image didnt go so well. From all my readings online, many people are saying that since this is a fully convolutional network, the features would have been learned and should be detectable even if we feed an image that is larger (the features would need to be same dimensions as during training however). Why did it yield such horrible results in this application?

    • @DigitalSreeni
      @DigitalSreeni  2 ปีที่แล้ว

      A fully convolutional network can handle images of different size, but it doesn't mean it gets the segmentation right. If you've used objects of various sizes as part of your training, then you would see decent results on images of different sizes. In my case, all objects are of similar size so if a new image is presented where the object size varies (or pixel size), the model fails to segment properly.

  • @fazankabir2029
    @fazankabir2029 3 ปีที่แล้ว

    Thank you Sreeni Sir for providing such useful tutorials I have been watching them past 2 hours. I have just one question regarding "patch size", what if i have original image has size of 1080*1920 in such case what would you suggest the patch_size gonna be to cover the whole image or is there any other way?. Thank you in advance :)

    • @ghoshizzle
      @ghoshizzle 2 ปีที่แล้ว +1

      I think as long as your dimension is divisible by your step size, the whole image will be covered. For example an image with dimension 512 and patch size 256 and step 128 will be covered with 3 patches in each dimension (9 total). Hope that makes sense

  • @KingJulien12_0
    @KingJulien12_0 ปีที่แล้ว

    Is there a Solution if my image is 5000x5000px. In the edges are problems with the shape and patchify stops working.

  • @manjunathhegde2811
    @manjunathhegde2811 2 ปีที่แล้ว

    How do I define the model if I used Resnet as backbone ( Video 216).. so that I can segment large imge

  • @Ahmetkumas
    @Ahmetkumas 3 ปีที่แล้ว

    Is it possible to reconstruct unet multi-class mask results like (3, 512,512))? If yes how can we do that? If that is available, can I use patchify? or needs something custom?

  • @sivava1500
    @sivava1500 7 หลายเดือนก่อน

    Great video

  • @ernestiu7398
    @ernestiu7398 3 ปีที่แล้ว

    Would you also make a tutorial on how you upload your codes to Github and manage them?

  • @tejangavandi1981
    @tejangavandi1981 2 ปีที่แล้ว

    Fantastic Explanation!!!

  • @qazisamiullahkhan1497
    @qazisamiullahkhan1497 ปีที่แล้ว

    Please make a video on liver segmentation from ct scan

  • @kannanv9304
    @kannanv9304 3 ปีที่แล้ว

    Ajarn, You used "Patchify" on the fly........Can we use "Patchify" off line also to patch/crop Training Images and their corresponding masks? In that way, apart from Augmentation, can have more images/masks for training the model......Your views please.....

  • @johnnysmith6876
    @johnnysmith6876 2 ปีที่แล้ว

    Really struggling to get this running with RGB image patches. Someone kindly help me out? Thanks.

  • @akshaybatra1777
    @akshaybatra1777 ปีที่แล้ว

    How do I train the model on the patches?

  • @sumsumsp
    @sumsumsp 3 ปีที่แล้ว

    Hi sir,
    How edge cells predicted can be taken, if it is predicted as different class in multi-class system ?
    Can you show how we can segment out each cells and save it in a folder?

  • @jaddyroot
    @jaddyroot 3 ปีที่แล้ว

    Hello Screeni. I'm trying to remake your patching solution for large grayscale images. I want it to work with ordinary color images, because trained my own U-net with inception backbone based on your tutorial. So I can't make it work with color images, I used your manual solution and your patchify library solution, but I always get different error about wrong shapes. It worked once for me, but just for the color image with equal height and width (square image) and the result was not informative. Is it possible to make it work with color images or it would be better to retrain my network with grayscale images as training data?

    • @DigitalSreeni
      @DigitalSreeni  3 ปีที่แล้ว

      Color images should work especially with inception as it uses 299x299x3 (color images). I am not sure about what the exact issue you are facing. I don't think it is handling color images but rather about input dimensions. If you are using Inception you may be forced to crop your images to 299x299x3 size. Please have a look at their documentation: github.com/qubvel/segmentation_models/blob/master/segmentation_models/backbones/inception_v3.py

  • @bhanusrinivaskoppolu4814
    @bhanusrinivaskoppolu4814 3 ปีที่แล้ว

    Sir can you say on how to train the model with patched images and reconstructing them

  • @shivamkumar-qp1jm
    @shivamkumar-qp1jm 3 ปีที่แล้ว

    if We do this on satellite image after converting tif to jpg then will it not change lat long ?

  • @yishumalhotra4261
    @yishumalhotra4261 3 ปีที่แล้ว

    What should I do if the dataset has images of different sizes? Should I resize them to a particular size and the divide into patches?

    • @DigitalSreeni
      @DigitalSreeni  3 ปีที่แล้ว +2

      Crop them to same size. I do not recommend resizing for semantic segmentation.

  • @venkatesanr9455
    @venkatesanr9455 3 ปีที่แล้ว

    Hi Sreeni, Thanks for your highly informative content. I have only 250 images for my segmentation experiment whether I can try U-net or go with ML approaches like Random forest/Xgboost. Kindly suggest your experience

    • @Droiduxx
      @Droiduxx ปีที่แล้ว

      Hi, did you have the occasion to test both ? I am currently in the same situation

  • @PardeepKumar-th2oj
    @PardeepKumar-th2oj 3 ปีที่แล้ว

    hey , great work done , when will upload the code in github

  • @jaiswalfelipe1269
    @jaiswalfelipe1269 2 ปีที่แล้ว

    Does patchify work on 23 band images? I have a tif file which is 4000x4000x23

    • @DigitalSreeni
      @DigitalSreeni  2 ปีที่แล้ว

      I haven't tried it on such images. Just give it a try and see, I have a suspicion that it may work. Can you share the file with me, in case it is ok with you for me to use it in one of my videos? I will give it a try with patchify and if it works I will make a training video so others can benefit.

    • @jaiswalfelipe1269
      @jaiswalfelipe1269 2 ปีที่แล้ว

      @@DigitalSreeni Sure! how can I dm you for the information?

  • @DeepakKumar-vn5qx
    @DeepakKumar-vn5qx 3 ปีที่แล้ว

    14:49 35th line is not sure what is the purpose?

  • @csktututorials9072
    @csktututorials9072 3 ปีที่แล้ว

    session crashed due to memory usuage in googlecolab,how can i solve

    • @DigitalSreeni
      @DigitalSreeni  3 ปีที่แล้ว +1

      Depends on why it crashes. If the dataset size is too large you obviously need more resources, so you may need colab pro. Or you can try to train on a subset of images each epoch.

  • @subratabhattacharjee992
    @subratabhattacharjee992 3 ปีที่แล้ว

    When I run the program using "patchify" and "unpatchify", I get this error. 'window_shape` is incompatible with `arr_in.shape`. Can anyone solve this problem?

    • @DigitalSreeni
      @DigitalSreeni  3 ปีที่แล้ว

      It appears that the window shape you are using is not compatible with your image size. If your image is 520x520 pixels and your window size is 256x256, the math does not work as 256x2 = 512. There will be some pixels left over. Pick a window size that you can divide your image into.

    • @faaalsh8784
      @faaalsh8784 2 ปีที่แล้ว

      You either use grey images or you may need to add channels to your patches size: (256, 256, 3)

  • @abubakrshafique7335
    @abubakrshafique7335 3 ปีที่แล้ว

    Best VIdeo. Thank you

  • @busayoawobade7177
    @busayoawobade7177 3 ปีที่แล้ว

    Great video!
    I'm slowing becoming a fan.
    I'm having a bit of an issue using patchify on an image with 3 channels. I'm getting an array shape of (4992, 1, 252, 252, 3) and I expect a shape of (4992, 252, 252, 3)

    • @DigitalSreeni
      @DigitalSreeni  3 ปีที่แล้ว +1

      Yes, this is correct for 3 channel images. Just drop the 1 from your array by reshaping.

    • @busayoawobade7177
      @busayoawobade7177 3 ปีที่แล้ว

      @@DigitalSreeni Ohh great. I'll do that

    • @georgemiller6010
      @georgemiller6010 3 ปีที่แล้ว

      @@busayoawobade7177 Hey, same issue. How'd did you get rid of the 1?

    • @busayoawobade7177
      @busayoawobade7177 3 ปีที่แล้ว

      ​@@georgemiller6010 You have to reshape it.
      I ltook another approach tho. I can't remember how i exactly solved this particular one. But reshaping it is what you have to do.

    • @Ak44878
      @Ak44878 2 ปีที่แล้ว

      @@busayoawobade7177 @DigitalSreeni I got the same error. Any solution?

  • @ownhaus
    @ownhaus 3 ปีที่แล้ว

    There is a better way if you use more patches and smoothing between them. Take a look at the github project Vooban /
    Smoothly-Blend-Image-Patches.

  • @alexandergrishin7084
    @alexandergrishin7084 3 ปีที่แล้ว

    Hi! Great tutorial as always! I'd like to ask why predictions on the large image without resizing don't work. The network is fully convolutional and technically can be applied to an image of arbitrary size higher then the receptive field. If you resize it, you change the scale and all your filters become useless, because you introduce images from a distribution that they never were trained on. but if the scale isn't changed, why is it dependent on the image size?

    • @petruszwart6310
      @petruszwart6310 2 ปีที่แล้ว

      Edge effects most likely. When doing spatial convolutions / pooling, zero or reflective padding is used. When the surface to circumference ratio is changed, the distribution of what you find in your receptive field changes.

  • @adityagandhamal2351
    @adityagandhamal2351 3 ปีที่แล้ว

    Thank you!!

  • @taifouryousra5484
    @taifouryousra5484 3 ปีที่แล้ว

    please how can i use patches with pytorch ?

    • @DigitalSreeni
      @DigitalSreeni  3 ปีที่แล้ว

      Sorry, I am not very much familiar with pytorch. Hopefully, someone else can help.

    • @petruszwart6310
      @petruszwart6310 2 ปีที่แล้ว

      Something like this:
      import patchify
      import einops
      import numpy as np
      img = np.zeros((1024,1024)) # mock image
      # patchify
      patched_image = patchify.patchify( img, (128,128,step=56)
      # restack with einops
      patched_image_for_pytorch = einops.rearrange(pactched_image, "N M Y X -> (N M) () Y X" )
      patched_image_for_pytorch = nn.Tensor(patched_image_for_pytorch)
      [didn't check this of course, but something like this should work]

  • @khondokermirazulmumenin8201
    @khondokermirazulmumenin8201 3 ปีที่แล้ว

    Hi, make a video for YOLO algorithm.