-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Top-down Centered-instance Pipeline #16
Conversation
… docstring to make_centered_bboxes, fixed find_global_peaks_rough; added crop_bboxes
…leupsamplingblock, encoder, decoder; added unet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 4
Files selected for processing (6)
- sleap_nn/data/augmentation.py (6 hunks)
- sleap_nn/data/instance_centroids.py (1 hunks)
- sleap_nn/data/instance_cropping.py (2 hunks)
- sleap_nn/data/pipelines.py (1 hunks)
- tests/data/test_instance_cropping.py (1 hunks)
- tests/data/test_pipelines.py (1 hunks)
Files skipped from review due to trivial changes (1)
- sleap_nn/data/instance_cropping.py
Additional comments (Suppressed): 9
sleap_nn/data/instance_centroids.py (1)
- 87-93: The changes in this hunk are minimal and mostly cosmetic, changing the variable name
example
toex
. The logic remains the same and there doesn't seem to be any issues with it. However, ensure that the change of variable name does not affect other parts of the code whereexample
might have been used.tests/data/test_instance_cropping.py (2)
29-29: The
InstanceCropper
class now takes a tuple for the crop size instead of separate width and height parameters. Ensure that all calls to this class throughout the codebase have been updated to match the new signature.35-35: The key for bounding box data in the sample dictionary has changed from
"bbox"
to"instance_bbox"
. Make sure that any code that accesses this data is updated accordingly.sleap_nn/data/augmentation.py (6)
100-105: The attribute
rotation
is unchanged and does not require any action.122-132: The attributes
random_crop_hw
andrandom_crop_p
have replaced the oldcrop_hw
andcrop_p
. Ensure that all references to these attributes in the codebase have been updated accordingly.150-170: The parameters of the constructor function have been updated. The changes include renaming
crop_hw
andcrop_p
torandom_crop_hw
andrandom_crop_p
, respectively, and changing default values for some parameters. Make sure that all calls to this function throughout the codebase have been updated to match the new signature.188-192: The instance variables
random_crop_hw
andrandom_crop_p
have replaced the oldcrop_hw
andcrop_p
. Ensure that all references to these variables in the codebase have been updated accordingly.259-276: The condition for applying random crop has been updated to check for
random_crop_p
instead ofcrop_p
, andrandom_crop_hw
instead ofcrop_hw
. This change is consistent with the updates made to the class attributes and constructor parameters.285-312: The
__iter__
method has been significantly updated to handle two different cases: when"instance_image"
and"instance"
keys are present in the example, and when"image"
and"instances"
keys are present. This change seems to improve the flexibility of the method by allowing it to handle different types of input data. However, ensure that the logic of the method still works as expected with these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Files selected for processing (2)
- sleap_nn/data/pipelines.py (1 hunks)
- tests/data/test_pipelines.py (1 hunks)
Files skipped from review due to trivial changes (1)
- tests/data/test_pipelines.py
Additional comments (Suppressed): 1
sleap_nn/data/pipelines.py (1)
- 48-51: Ensure that all calls to this class throughout the codebase have been updated to match the new signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Files selected for processing (1)
- sleap_nn/data/pipelines.py (1 hunks)
Additional comments (Suppressed): 1
sleap_nn/data/pipelines.py (1)
- 47-49: Ensure that all calls to this class throughout the codebase have been updated to match the new signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (1)
- sleap_nn/data/pipelines.py (1 hunks)
Additional comments (Suppressed): 5
sleap_nn/data/pipelines.py (5)
1-6:
7-16: Ensure that all the imported modules are used in the code and remove any unnecessary imports to keep the code clean and efficient.
18-31: The
SleapDataset
class is well implemented. It takes anIterDataPipe
as input and provides a dictionary with relevant outputs when iterated over.32-47: This block of code checks if the shape of
instance_image
has 4 dimensions, and if so, it removes one dimension usingsqueeze(dim=0)
. This could potentially lead to unexpected results if the first dimension ofinstance_image
has more than one element. Consider verifying this logic and its implications on the rest of the pipeline.50-60: The
TopdownConfmapsPipeline
class is initialized with adata_config
which is aDictConfig
. This configuration is used later in the pipeline creation methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 7
Files selected for processing (11)
- sleap_nn/architectures/common.py (2 hunks)
- sleap_nn/data/augmentation.py (6 hunks)
- sleap_nn/data/confidence_maps.py (3 hunks)
- sleap_nn/data/general.py (1 hunks)
- sleap_nn/data/instance_centroids.py (2 hunks)
- sleap_nn/data/instance_cropping.py (2 hunks)
- sleap_nn/data/normalization.py (2 hunks)
- sleap_nn/data/pipelines.py (1 hunks)
- sleap_nn/data/providers.py (2 hunks)
- tests/data/test_instance_cropping.py (1 hunks)
- tests/data/test_pipelines.py (1 hunks)
Files skipped from review due to trivial changes (1)
- sleap_nn/data/providers.py
Additional comments (Suppressed): 25
sleap_nn/data/general.py (1)
- 1-38: The
KeyFilter
class is well implemented. It provides a way to filter keys from the data pipeline, which can be useful for focusing on specific parts of the data during processing. The use of type hints and clear comments enhances readability and maintainability.sleap_nn/data/normalization.py (2)
1-6: The import of
Dict
fromtyping
is added but it's not used in this hunk. Ensure that it's used in the code outside this hunk, otherwise, it's an unnecessary import.18-28: Type hints and return type annotations have been added to the
__init__
and__iter__
methods. This improves code readability and provides better documentation for the expected types of inputs and outputs.sleap_nn/architectures/common.py (2)
1-6: The import of
List
fromtyping
is added but not used in the provided hunks. Ensure that it's used in the parts of the code not shown here, otherwise, it should be removed to avoid unnecessary imports.136-142: Type hinting has been added for the function
get_children_layers
. This improves code readability and helps with static type checking.sleap_nn/data/instance_centroids.py (2)
1-5: The import of
Dict
from thetyping
module is new in this hunk. Ensure that it's used in the code that follows this hunk.79-93: The changes made to the
InstanceCentroidFinder
class are mostly cosmetic, with the exception of adding type hints and return type annotations to the__init__
and__iter__
methods. These changes improve the readability of the code and provide better documentation for the expected types of inputs and outputs.- def __init__( - self, - source_dp: IterDataPipe, - anchor_ind: Optional[int] = None, - ): + def __init__( + self, + source_dp: IterDataPipe, + anchor_ind: Optional[int] = None, + ) -> None: - def __iter__(self): + def __iter__(self) -> Dict[str, torch.Tensor]:sleap_nn/data/instance_cropping.py (4)
1-5: The import of
Tuple
from thetyping
module is a new addition. Ensure that it's used appropriately in the code.64-67: The constructor of
InstanceCropper
now takes a tuplecrop_hw
instead of separatecrop_width
andcrop_height
. This change simplifies the function signature and enhances readability. However, make sure all calls to this constructor throughout the codebase have been updated to match the new signature.76-79: The
make_centered_bboxes
function now takes height and width from thecrop_hw
tuple. This is consistent with the changes made to the constructor.95-101: The keys in the
instance_example
dictionary have been updated. The key"bbox"
has been changed to"instance_bbox"
, and the key"instance_image"
now includes a call tosqueeze(0)
. These changes improve clarity and consistency in the code. However, ensure that all references to these keys in the rest of the codebase have been updated accordingly.sleap_nn/data/confidence_maps.py (2)
1-5: The import statement
from typing import Dict, Optional
has been updated to includeDict
. This change is likely due to the addition of type hints in the code. Ensure that all uses ofDict
are correctly implemented.10-16: The function signature for
make_confmaps()
has been updated with a return type annotation-> torch.Tensor
. This improves code readability and provides better documentation for the expected output type of the function.sleap_nn/data/augmentation.py (5)
100-105: The attribute
crop_hw
has been removed and replaced withrandom_crop_hw
. Ensure that all references tocrop_hw
in the codebase have been updated torandom_crop_hw
.122-132: The default values for
erase_scale
,erase_ratio
, andrandom_crop_p
have been changed. Make sure these changes do not affect the expected behavior of the data augmentation pipeline.150-170: The default probabilities for applying affine transformations, uniform noise, Gaussian noise, contrast adjustment, brightness adjustment, random erasing, and mixup have been set to 0. This means these augmentations will not be applied by default. If this is intended, it's fine. Otherwise, you might want to adjust these default values.
259-276: The check for
random_crop_hw
being greater than 0 has been added. This is a good practice as it prevents unexpected behavior when the crop size is 0. However, ensure that this does not conflict with any use cases where a crop size of 0 might be intentionally used.285-312: The logic for handling examples with
"instance_image"
and"instance"
keys has been added. This improves the flexibility of the data augmentation pipeline by allowing it to handle different types of input data. However, make sure that this new logic is covered by the test suite to ensure it works as expected.tests/data/test_instance_cropping.py (2)
29-29: Ensure that all calls to
InstanceCropper
throughout the codebase have been updated to match the new signature, which now takes a tuple for the crop size.46-47: The shape assertions for "instance_image" and "instance_bbox" have changed from the old hunk. Ensure these changes are intentional and correctly reflect the expected shapes after modifications in the data processing pipeline.
sleap_nn/data/pipelines.py (5)
46-47: Ensure that
self.data_config.preprocessing.crop_hw
is always defined and has valid values before passing it toInstanceCropper
. If it's not defined or invalid, it could lead to unexpected behavior or errors.48-53: Check if
self.data_config.augmentation_config.random_crop
is always defined and has valid values before accessing its attributes. If it's not defined or invalid, it could lead to unexpected behavior or errors.55-58: Ensure that
self.data_config.augmentation_config.augmentations
is always defined and has valid values before unpacking it as arguments toKorniaAugmenter
. If it's not defined or invalid, it could lead to unexpected behavior or errors.60-64: Check if
self.data_config.preprocessing.conf_map_gen
is always defined and has valid values before accessing its attributes. If it's not defined or invalid, it could lead to unexpected behavior or errors.65-66: Ensure that
self.data_config.general.keep_keys
is always defined and has valid values before passing it toKeyFilter
. If it's not defined or invalid, it could lead to unexpected behavior or errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Files selected for processing (8)
- sleap_nn/data/augmentation.py (7 hunks)
- sleap_nn/data/confidence_maps.py (3 hunks)
- sleap_nn/data/general.py (1 hunks)
- sleap_nn/data/instance_centroids.py (2 hunks)
- sleap_nn/data/instance_cropping.py (2 hunks)
- sleap_nn/data/normalization.py (2 hunks)
- sleap_nn/data/providers.py (2 hunks)
- tests/data/test_instance_cropping.py (1 hunks)
Additional comments (Suppressed): 23
sleap_nn/data/normalization.py (2)
1-6: The addition of typing imports is a good practice for better code readability and static type checking. This change aligns with the goals of the PR.
18-28: The addition of return type hints in the function signatures improves the clarity of the code and provides better static type checking. This change also aligns with the goals of the PR.
sleap_nn/data/instance_centroids.py (2)
1-5: The import of
Dict
andIterator
from thetyping
module is a good addition for better type hinting and code readability.79-93: The changes in this hunk are mostly cosmetic, with no significant alterations to the logic or functionality. The introduction of type hints improves code readability and provides better static type checking.
sleap_nn/data/confidence_maps.py (3)
1-5: The import statement
from typing import Dict, Iterator, Optional
has been updated to includeDict
andIterator
. This is a good practice as it improves code readability and provides better static type checking.10-16: The function signature for
make_confmaps()
has been updated to include a return type hint. This is a good practice as it improves code readability and provides better static type checking.70-84: The method signature for the
__init__()
and__iter__()
methods of theConfidenceMapGenerator
class have been updated to include return type hints. This is a good practice as it improves code readability and provides better static type checking.sleap_nn/data/instance_cropping.py (2)
1-5: The import of
Dict
,Iterator
, andTuple
from thetyping
module is a good addition for better type hinting and code readability.64-67: The change to use a single attribute
crop_hw
(a tuple) instead of separatecrop_width
andcrop_height
attributes simplifies the function signature and makes it easier to manage. However, ensure that all calls to this function throughout the codebase have been updated to match the new signature.sleap_nn/data/providers.py (4)
1-6: The import of
Dict
andIterator
from thetyping
module is new. Ensure that these types are used appropriately in the rest of the code.21-23: Type hint for the
labels
parameter has been added to the constructor. This improves readability and provides better static type checking.26-29: Type hint for the
filename
parameter and return type hint have been added to thefrom_filename
method. This enhances code readability and provides better static type checking.31-34: Return type hint has been added to the
__iter__
method. This improves code readability and provides better static type checking.tests/data/test_instance_cropping.py (3)
29-29: The
InstanceCropper
class now takes a tuple for the crop size instead of separate width and height parameters. Ensure that all calls to this class throughout the codebase have been updated to match the new signature.46-46: The shape of the "instance_image" has changed from (1, 1, 100, 100) to (1, 100, 100). This change should be verified across the codebase to ensure it doesn't break any functionality that relies on the old shape.
47-47: The key for bounding box data in the sample dictionary has changed from "bbox" to "instance_bbox". Make sure to update all references to this key in the codebase.
sleap_nn/data/augmentation.py (7)
1-5: The import statement
from typing import Iterator
has been added. Ensure that this new import is used in the code.100-105: The attribute
crop_hw
andcrop_p
have been removed from the class. Make sure that these attributes are not being referenced anywhere else in the codebase.122-132: The default values for
erase_scale
anderase_ratio
have been changed. Verify if these changes align with the intended functionality of the code.150-170: The parameters
affine_p
,uniform_noise_p
,gaussian_noise_p
,contrast_p
,brightness_p
,erase_p
, andmixup_p
have their default values changed to 0.0. This means these augmentations will be disabled by default. If this is intentional, no action is needed. Otherwise, consider reverting these changes.188-192: The attribute
crop_hw
andcrop_p
have been replaced withrandom_crop_hw
andrandom_crop_p
. Make sure that these new attributes are correctly used in the rest of the code.259-276: The cropping operation has been updated to use the new attributes
random_crop_hw
andrandom_crop_p
. The logic seems correct as it checks if both height and width are greater than 0 before applying the crop.282-312: The
__iter__
method has been significantly modified. It now handles two cases: when both "instance_image" and "instance" keys are present in the example, and when both "image" and "instances" keys are present. The augmentation is applied accordingly. This change appears to improve the flexibility of the method to handle different types of input data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (2)
- sleap_nn/data/general.py (1 hunks)
- sleap_nn/data/instance_cropping.py (2 hunks)
Additional comments (Suppressed): 4
sleap_nn/data/general.py (1)
- 1-39: The
KeyFilter
class is well implemented. It provides a way to filter keys from the data dictionary based on the providedkeep_keys
list. The logic in the__iter__
method correctly handles both cases wherekeep_keys
is provided or not. The use of type hints and docstrings enhances readability and understanding of the code.sleap_nn/data/instance_cropping.py (3)
1-5: The import statement
from typing import Dict, Iterator, Optional, Tuple
has been added. Ensure that these types are used appropriately throughout the code.58-67: The
InstanceCropper
class now takes a tuple for crop dimensions instead of separate height and width parameters. This is a good change as it simplifies the function signature and makes the code more maintainable.64-67: Ensure that all calls to this class throughout the codebase have been updated to match the new signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Files selected for processing (1)
- sleap_nn/data/instance_cropping.py (2 hunks)
Additional comments (Suppressed): 1
sleap_nn/data/instance_cropping.py (1)
- 1-5: The import statement has been updated to include additional types
Dict
,Iterator
, andTuple
for better type hinting. This is a good practice as it improves code readability and allows for static type checking.
Summary by CodeRabbit
SleapDataset
andTopdownConfmapsPipeline
classes for high-level pipeline configurations in data processing.crop_width
andcrop_height
attributes into a singlecrop_hw
attribute in theInstanceCropper
class for better clarity and maintainability.KorniaAugmenter
class to userandom_crop_hw
andrandom_crop_p
parameters, improving flexibility in data augmentation.test_sleap_dataset
andtest_topdownconfmapspipeline
to validate the functionality of the newly introduced classes.