HenriquesLab / HenriquesLab/ZeroCostDL4Mic
In Stardist2D number_of_steps is calculated assuming all training data has the same size
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 652
- Forks
- 144
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Although the training works even if the input images are of different widths or heights, number_of_steps is calculated using the dimensions of a randomly selected image.
To Reproduce
Steps to reproduce the behavior:
- open StarDist_2D_ZeroCostDL4Mic.ipynb
- Scroll down to 'section 4.1 "Prepare the training data and model for training"
- See code:
number_of_steps = int(Image_XImage_Y/(patch_sizepatch_size))*(int(len(X)/batch_size)+1)
if (Use_Data_augmentation):
augmentation_factor = Multiply_dataset_by
number_of_steps = number_of_steps * augmentation_factor
Where Image_X and Image_Y are the dimensions of a random image
Expected behavior
I suggest to replace it with the following simple fix that loop through the input images and exactly calculates the number of steps:
number_of_steps = calc_number_of_steps(X)
Where calc_number_of_steps is:
import math
def calc_number_of_steps(X):
num_steps = 0
for x in X:
assert x.shape[0] >= patch_size and x.shape[1] >= patch_size , "patch size must not be greater that smallest image dimension"
num_steps += int(x.shape[0]/patch_size) * int(x.shape[1]/patch_size)
num_steps = math.ceil(num_steps/batch_size)
if (Use_Data_augmentation):
augmentation_factor = Multiply_dataset_by
num_steps *= augmentation_factor
return num_steps
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open StarDist_2D_ZeroCostDL4Mic.ipynb and go to section 4.1, then inspect how number_of_steps uses Image_X and Image_Y. Try training data with different image dimensions, update the calculation so all input images are accounted for, and verify that the resulting step count and patch-size validation behave as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100