Conversation
…y needs to be added)
… Fix normalisation for multchannel data
…ctly for arbitrary data channels. Improve batching logic and handling of 1D Manipulations
- Fix test_axes_validators.py to allow 1D axes (X, SX, TX, CX, SCX, STX) - Add MaxBlurPool1D layer tests - Add 1D UNet architecture tests - Add end-to-end 1D N2V training tests Covers: axes validation, MaxBlurPool1D, 1D UNet, N2V training/prediction
…tests. Remove redundant dropout and attention code. Type checking
|
Just to introduce myself, I'm Tom, a first year PhD student at the University of Birmingham working under the supervision of Alexander Krull. I've been working on the application of his N2V algorithm to Raman Spectroscopy and other types of data. |
Hi Tom! Thanks for your PRs, we are happy CAREamics might be of use to your projects and hi to Alex! The PRs are touching on many aspects of the code base and we are in the middle of a major refactoring, therefore we will need a few days to review and assess the various changes. We will come back to you with detailed feedback! |
|
Hi Tom, I tried to get in touch with Alex because I could not find your contact details. Given the depth of the changes necessary to accommodate your needs, I think it would be good to have a discussion first. Do you mind getting in touch with me by emails? You can find it on the HT website! |
Description
Note
tldr: Adds support for 1D data (spectroscopy, time series, sensor data) in CAREamics N2V, including 1D UNet architecture, patching, tiling, and multichannel processing.
Background - why do we need this PR?
CAREamics previously only supported 2D and 3D image data. However, many scientific applications require denoising of 1D data:
Without 1D support, users had to artificially pad their data to 2D or use external tools. This PR enables native 1D data processing through N2V.
Overview - what changed?
conv_dim=1for 1D convolutionsImplementation - how did you implement the changes?
1D UNet Architecture:
The UNet automatically uses 1D convolutions (
nn.Conv1d) whenconv_dims=1, with linear upsampling instead of bilinear.Axes Validation:
Modified validators to detect single spatial dimensions and route to 1D-specific validation. Axes like "X", "SX", "TX", "CX" are now valid.
Patching Logic:
_extract_patches_1d()handles 1D array shapes (S, C, X) or (S, X)num_patches_per_sampleMultichannel Processing:
Enhanced N2V to support per-channel models where input/output channels can differ:
Normalisation properly handles channel mismatches using
target_channel_indices.Changes Made
New features or files
check_axes_validity_1d()insrc/careamics/config/validators/axes_validators.py_extract_patches_1d()insrc/careamics/dataset/patching/sequential_patching.pyMaxBlurPool1D mode (dim=1) insrc/careamics/models/layers.pytarget_channel_indicesparameter inDenormalizetransformnum_patches_per_sampleconfiguration for random patchingpatching_seedfor reproducible random patchingtest_layers_1d.py,test_unet_1d.py,test_careamist_1d.pyModified features or files
Core Architecture:
src/careamics/models/unet.py: Added 1D upsampling (linear mode), 1D skip connectionssrc/careamics/config/architectures/unet_config.py: Acceptsconv_dims=1, validation warningsConfiguration:
src/careamics/config/validators/axes_validators.py: Routes 1D axes to new validatorsrc/careamics/config/data/data_config.py: Validates patch size matches spatial dimssrc/careamics/config/configuration_factories.py: Added 1D Raman example in docstringPatching & Tiling:
src/careamics/dataset/patching/sequential_patching.py: Routes to 1D/2D/3D based on axessrc/careamics/dataset/patching/validate_patch_dimension.py: Validates 1D patch dimensionssrc/careamics/dataset/tiling/tiled_patching.py: Already had_compute_crop_and_stitch_coords_1d()Transforms:
src/careamics/transforms/normalize.py: Handles channel mismatch (N input → M output)src/careamics/transforms/denormalize.py: Addedtarget_channel_indicesfor per-channel statsLightning Module:
src/careamics/lightning/lightning_module.py: Passestarget_channel_indicesto denormaliseAlgorithm Config:
src/careamics/config/algorithms/n2v_algorithm_config.py: Disabledmodel_matching_in_out_channelsvalidatorRemoved features or files
None. All changes maintain backward compatibility.
How has this been tested?
Unit Tests Added:
Axes Validation (
test_axes_validators.py):MaxBlurPool1D (
test_layers_1d.py):1D UNet (
test_unet_1d.py):End-to-End N2V (
test_careamist_1d.py):Multichannel Tests (
test_n2v_algorithm_config.py,test_denormalize_perchannel.py):Manual Testing:
Tested on real Raman spectroscopy data with successful denoising results. Also using auxiliary channels lead to an improvement.
Related Issues
Breaking changes
None. All changes are backward compatible
Additional Notes and Examples
Example 1D Usage:
Multichannel Example:
Random Patching Example:
Please ensure your PR meets the following requirements: