feat: standardize & normalize dataset formats#116
Open
madsysharma wants to merge 4 commits into
Open
Conversation
Author
|
Hi @Brijeshthummar02 , please review this PR. Thanks. |
1 similar comment
Author
|
Hi @Brijeshthummar02 , please review this PR. Thanks. |
Author
|
Hi @Brijeshthummar02 , please review this PR. Thank you. |
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.
Standardize and normalize dataset formats
Closes #70
Summary
Adds a non-destructive dataset standardization pipeline that normalizes every sample into one consistent format: image dimensions, file format, channel layout, mask encoding, and metadata/labeling conventions, before training.
It is the normalization counterpart to the existing auditing script
dataset_quality.pyand follows the same conventions (root-level script, JSON report indataset_reports/, unit tests intests/unit/).While building this against the real codebase I found a data-integrity bug in the shipped manifest, which this PR also fixes (details below).
Problem
The raw TCGA data and
data_mask.csvare not uniform:patient_idmetadata: indata_mask.csvthepatient_idcolumn is misaligned: the same id is repeated across slices that actually belong to different patients. 3,894 of 3,929 rows have apatient_idthat does not match the patient folder in theirimage_path. A patient-grouped train/val/test split keyed on that column would leak the same patient across splits and inflate reported metrics. The folder name inimage_pathis the ground-truth TCGA id, so the pipeline re-derivespatient_idfrom it.Changes included
dataset_standardize.pytests/unit/test_dataset_standardize.pyPREPROCESSING.mdREADME.md.gitignoredataset_standardized/image dirRunning
python dataset_standardize.pygenerates two artifacts (kept out of this diff; the image dir is git-ignored):data_mask_standardized.csv: canonical manifest with corrected metadatadataset_reports/standardization_report.json: run summary & consistency checkHow it maps to the acceptance criteria
consistency_checkin the report asserts uniform resolution / channels / dtype across the processed set.{0, 255}. The 0/1masklabel is re-derived from actual mask content, flagging mislabeled rows.PREPROCESSING.mddocuments every stage, the canonical format table, the manifest schema, usage and a training example.Pipeline overview
Stage 1: Manifest standardization (no images required, works in a fresh clone): re-derives canonical
patient_id, parses a numericsliceindex, normalizes path separators, preserves the source label asoriginal_mask, and emits a fixed column order.Stage 2: Pixel standardization (for rows whose files exist): standardizes image & mask pixels, re-derives the label from the mask, and writes standardized copies to
dataset_standardized/, mirroring theTCGA_*/layout. Missing-file rows are skipped and counted, so the run succeeds with only the CSV present.Format:
{0,255}, nearest-neighbour resizepatient_idmasklabelPixel-value normalization (
/255and mean-std) is intentionally left at model-feed time to matchapp.py's existing preprocessing, so the standardized data stays reusable across both the classification and segmentation stages. The originalimage_path/mask_pathcolumns are preserved so existing code keeps working; training can switch to the newstd_*columns once data is generated.Usage
Testing
Source-first: cloned the repo and verified everything against the real
data_mask.csvand the actualTCGA_*folder/filename conventions.git apply --checkpasses on a fresh clone; tests re-run green after applying.data_mask.csv: detected 110 unique patients (matches the README), corrected 3,894 misalignedpatient_idrows, parsed all 3,929 slice indices.{0,255}, and mislabeled rows auto-corrected from mask content.Tests cover the metadata helpers, image standardization (grayscale/RGBA/odd-size + uint16 to uint8 scaling), the nearest neighbour mask guarantee, manifest correction, missing-file handling, and a full end-to-end pixel run.
Notes for reviewer
dataset_standardized/is git-ignored, consistent with the existingTCGA*/rule: dataset images are never committed.PR checklist
PREPROCESSING.mdand README pointer)