Repository navigation
Allow sampling multiple patches from the same stack - #35
Merged
Merged
Conversation
it breaks jsonargparse
the metrics will be automatically reduced by lightning
ziw-liu
marked this pull request as ready for review
August 21, 2023 04:36
Contributor
Author
|
@mattersoflight I misinterpreted the training speed because as the epochs have |
ziw-liu
requested review from
edyoshikun and
mattersoflight
and removed request for
edyoshikun and
mattersoflight
August 21, 2023 04:38
mattersoflight
added a commit
that referenced
this pull request
Aug 30, 2023
* pixelshuffle decoder * Allow sampling multiple patches from the same stack (#35) * sample multiple patches from one stack * do not use type annotations from future it breaks jsonargparse * fix channel stacking for non-training samples * remove batch size from model the metrics will be automatically reduced by lightning * add flop counting script * 3d ouput head * add datamodule target dims mode * remove unused argument and configure drop path * move architecture argument to model level * DLMBL 2023 excercise (#36) * updated intro and paths * updated figures, tested data loader * setup.sh fetches correct dataset * finalized the exercise outline * semi-final exercise * parts 1 and 2 tested, part 3 outline ready * clearer variables, train with larger patch size * fix typo * clarify variable names * trying to log graph * match example size with training * reuse globals * fix reference * log sample images from the first batch * wider model * low LR solution * fix path * seed everything * fix test dataset without masks * metrics solution this needs a new test dataset * fetch test data, compute metrics * byass cellpose import error due to numpy version conflicts * final exercise * moved files * fixed formatting - ready for review * viscy -> VisCy (#34) (#39) Introducing capitalization to highlight vision and single-cell aspects of the pipeline. * trying to log graph * log graph * black --------- Co-authored-by: Shalin Mehta <shalin.mehta@gmail.com> Co-authored-by: Shalin Mehta <shalin.mehta@czbiohub.org> * fix channel dimension size for example input #40 * fix argument linking * 3D prediction writer sliding windows are blended with uniform average * update network diagram * upgrade flop counting * shallow 3D (2.5D) SSIM metric * ms-ssim * mixed loss * fix arguments * fix inheritance * fix weight checking * squeeze metric * aggregate metrics * optinal clamp to stabilize gradient of MS-SSIM * fix calling * increase epsilon * disable autocast for loss * restore relu for clamping * plot all architectures with network_diagram script --------- Co-authored-by: Shalin Mehta <shalin.mehta@czbiohub.org>
ziw-liu
added a commit
that referenced
this pull request
Nov 1, 2023
* pixelshuffle decoder * Allow sampling multiple patches from the same stack (#35) * sample multiple patches from one stack * do not use type annotations from future it breaks jsonargparse * fix channel stacking for non-training samples * remove batch size from model the metrics will be automatically reduced by lightning * add flop counting script * 3d ouput head * add datamodule target dims mode * remove unused argument and configure drop path * move architecture argument to model level * DLMBL 2023 excercise (#36) * updated intro and paths * updated figures, tested data loader * setup.sh fetches correct dataset * finalized the exercise outline * semi-final exercise * parts 1 and 2 tested, part 3 outline ready * clearer variables, train with larger patch size * fix typo * clarify variable names * trying to log graph * match example size with training * reuse globals * fix reference * log sample images from the first batch * wider model * low LR solution * fix path * seed everything * fix test dataset without masks * metrics solution this needs a new test dataset * fetch test data, compute metrics * byass cellpose import error due to numpy version conflicts * final exercise * moved files * fixed formatting - ready for review * viscy -> VisCy (#34) (#39) Introducing capitalization to highlight vision and single-cell aspects of the pipeline. * trying to log graph * log graph * black --------- Co-authored-by: Shalin Mehta <shalin.mehta@gmail.com> Co-authored-by: Shalin Mehta <shalin.mehta@czbiohub.org> * fix channel dimension size for example input #40 * fix argument linking * 3D prediction writer sliding windows are blended with uniform average * update network diagram * upgrade flop counting * shallow 3D (2.5D) SSIM metric * ms-ssim * mixed loss * fix arguments * fix inheritance * fix weight checking * squeeze metric * aggregate metrics * optinal clamp to stabilize gradient of MS-SSIM * fix calling * increase epsilon * disable autocast for loss * shuffle validation data for logging this hurts cache hit rate, but can avoid logging neighboring windows * simplify decoder structure * pop-head * fix head expansion * init conv weights * update diagnostic scripts * fix center slice metrics for 3D output (#51) * Configure the number of image samples logged at each epoch and batch (#49) * log sample size at epoch and batch levels * update example configs * do not shuffle validation dataset * fix upsampling weight initialization * fix merge * fix merge error * fix formatting --------- Co-authored-by: Shalin Mehta <shalin.mehta@gmail.com> Co-authored-by: Shalin Mehta <shalin.mehta@czbiohub.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@mattersoflight and I had a discussion about potential data utilization problem when only sampling one patch from a stack at each training step. While with longer training schedule, all ROIs will still get sampled, this does waste a lot of I/O bandwidth, since most of the data loaded from disk is not used in the batch. This problem becomes more prominent when the stack depth increases, where even local NVME pools cannot keep the GPU fed with data.
This PR implements a new data module argument
train_patches_per_stack, allowing sampling multiple patches from a single stack, effective only in training. The batch size has to be divisible by this number for collation to work. When I/O-bound, this can greatly speed up data-loading. Below is a test of single-precision batch tensor with size (32, 2, 5, 2048, 2048), worker number equals number of batches loaded (all 5 batches loaded in parallel, sharing I/O bandwidth). Data is stored on a Lustre server in the local infiniband network, and cache is warmed up by running the test several times before recording the result. Increasingtrain_patches_per_stackresults in decreased total time. However the decrease is sub-linear, as the bottleneck shifts to compute.However the
train_patches_per_stackcannot be arbitrarily large. Sampling too many patches from the same stack reduces the variance of the batch, effectively reducing the batch size (in terms of statistical power). Also the chance of sampling background will increase. In practice this should be evaluated with batch size to avoid having too few stacks for a batch.Below is the first 16 samples of the same batch when
train_patches_per_stack=4showing some 'batch effect' for samples from the same stack.