Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
fix(preflight): resolve labels.csv filename by column name, not position#207
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -247,8 +247,11 @@ func ValidateImages(images []string, expectedW, expectedH int) error { | ||
| // direction for image_classification) — the caller may surface them as a | ||
| // note. | ||
| // | ||
| // filenameColumn is the CSV's first column (the ingestor reads filenames | ||
| // positionally from the id column of labels.csv). | ||
| // The image filename is read from the column NAMED "filename", not positionally: | ||
| // the ingestor does record.get("filename") over the header-keyed record | ||
| // (file_transfer.py / record_processor.py), so a `label,filename` header (filename | ||
| // not first) resolves to that column — reading rec[0] would treat the LABEL value | ||
| // as the filename and false-reject a layout the cluster ingests cleanly. | ||
| func CrossCheckLabels(csvPath string, images []string, extension string) (missing []string, orphans []string, err error) { | ||
| f, err := os.Open(csvPath) | ||
| if err != nil { | ||
| @@ -268,12 +271,14 @@ func CrossCheckLabels(csvPath string, images []string, extension string) (missin | ||
| } | ||
| referenced := make(map[string]bool) | ||
| if _, err := r.Read(); err != nil { // header | ||
| header, err := r.Read() | ||
| if err != nil { | ||
| if errors.Is(err, io.EOF) { | ||
| return nil, nil, nil // emptiness is CheckHasDataRows' diagnostic | ||
| } | ||
| return nil, nil, fmt.Errorf("reading %s: %w", filepath.Base(csvPath), err) | ||
| } | ||
| fnIdx := imageFileColIndex(header) | ||
| for { | ||
| rec, err := r.Read() | ||
| if errors.Is(err, io.EOF) { | ||
| @@ -282,10 +287,10 @@ func CrossCheckLabels(csvPath string, images []string, extension string) (missin | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("reading %s: %w", filepath.Base(csvPath), err) | ||
| } | ||
| if len(rec) == 0 { | ||
| continue | ||
| if fnIdx >= len(rec) { | ||
| continue // short/ragged row — no filename cell to check | ||
| } | ||
| name := strings.TrimSpace(rec[0]) | ||
| name := strings.TrimSpace(rec[fnIdx]) | ||
| if name == "" { | ||
| continue | ||
| } | ||
| @@ -311,6 +316,34 @@ func CrossCheckLabels(csvPath string, images []string, extension string) (missin | ||
| return missing, orphans, nil | ||
| } | ||
| // imageFileColIndex returns the header index of the column the ingestor reads each | ||
| // image's file key from: "filename" if present, else "data_id" — the ingestor's own | ||
| // precedence (image_paths.prepare_classification_pytorch_image_df / image_loader), | ||
| // position-independent for both. A label,data_id CSV (no filename column) is ingested | ||
| // cleanly by the cluster, so matching only "filename" and falling back to index 0 | ||
| // would read the label column as filenames and false-reject it (exit 3). | ||
| // | ||
| // Each name is matched exactly first, then case-insensitively with surrounding | ||
| // whitespace stripped (the ingestor's _match_column rule). "filename" wins over | ||
| // "data_id" when both resolve. Falls back to 0 only when NEITHER column exists — a | ||
| // labels.csv the ingestor rejects at validate_data regardless, not this check's job | ||
| // to diagnose. | ||
| func imageFileColIndex(header []string) int { | ||
| for _, want := range []string{"filename", "data_id"} { | ||
| for i, h := range header { | ||
| if strings.TrimSpace(h) == want { | ||
| return i | ||
| } | ||
| } | ||
| for i, h := range header { | ||
| if strings.EqualFold(strings.TrimSpace(h), want) { | ||
| return i | ||
| } | ||
| } | ||
| } | ||
| return 0 | ||
saadqbal marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // CheckAnnotationPairing previews the ingestor's FilePairingValidator | ||
| // (file_pairing_validator.py) for object_detection: every image must have | ||
| // an annotation with the same filename stem and vice versa — a mismatch in | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.