-
Notifications
You must be signed in to change notification settings - Fork 4
Oc-ccl finetune code #23
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
Open
DeFisch
wants to merge
5
commits into
main
Choose a base branch
from
oc-ccl-finetune
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
81cfdeb
Release one-shot fine-tuning (OC-CCL) code
DeFisch bf3916d
Fix OC-CCL expansion: Open-Close Cycle Consistency Loss
DeFisch 28b361a
Fix remaining one-shot wording in OC-CCL TODO and docstrings
DeFisch 5cefe79
Use cautious-robot for butterfly image downloads
DeFisch 86de0ad
Commit images.csv with Zenodo md5 checksums for reproducible downloads
DeFisch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """ | ||
| Build images.csv from the train/test JSON splits, enriched with md5 checksums | ||
| fetched from the Zenodo public API. The CSV is consumed by cautious-robot: | ||
|
|
||
| cautious-robot -i images.csv -o images/ \ | ||
| --checksum-algorithm md5 --verifier-col md5 | ||
|
|
||
| Maintenance script — re-run only if the train_test_separate/*.json files change. | ||
| The output images.csv is checked into the repo so users do not need network | ||
| access until they actually download images. | ||
| """ | ||
|
|
||
| import csv | ||
| import json | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
| DATA_ROOT = Path(__file__).resolve().parent | ||
| SPLIT_DIR = DATA_ROOT / "train_test_separate" | ||
| OUT_CSV = DATA_ROOT / "images.csv" | ||
|
|
||
|
|
||
| def parse_zenodo_url(url): | ||
| """https://zenodo.org/record/<id>/files/<name> -> (id, name).""" | ||
| record, _, name = url.split("/record/")[1].partition("/files/") | ||
| return record, name | ||
|
|
||
|
|
||
| def fetch_record_md5s(record_id): | ||
| """Return {filename: md5_hex} for one Zenodo record.""" | ||
| api_url = f"https://zenodo.org/api/records/{record_id}" | ||
| with urllib.request.urlopen(api_url) as r: | ||
| meta = json.load(r) | ||
| md5s = {} | ||
| for f in meta.get("files", []): | ||
| digest = f.get("checksum", "") | ||
| if digest.startswith("md5:"): | ||
| md5s[f["key"]] = digest[len("md5:"):] | ||
| return md5s | ||
|
|
||
|
|
||
| def main(): | ||
| entries = {} | ||
| for json_file in sorted(SPLIT_DIR.rglob("*.json")): | ||
| for image_id, url, _mask in json.load(open(json_file)): | ||
| entries.setdefault(image_id, url) | ||
|
|
||
| record_ids = sorted({parse_zenodo_url(url)[0] for url in entries.values()}) | ||
| print(f"Fetching md5s for {len(record_ids)} Zenodo records...") | ||
| md5_by_record = {} | ||
| for rid in record_ids: | ||
| md5_by_record[rid] = fetch_record_md5s(rid) | ||
| print(f" record {rid}: {len(md5_by_record[rid])} files") | ||
|
|
||
| rows = [] | ||
| missing = [] | ||
| for image_id, url in sorted(entries.items()): | ||
| rid, name = parse_zenodo_url(url) | ||
| md5 = md5_by_record.get(rid, {}).get(name) | ||
| if md5 is None: | ||
| missing.append((image_id, url)) | ||
| continue | ||
| ext = Path(url).suffix | ||
| rows.append((f"{image_id}{ext}", url, md5)) | ||
|
|
||
| if missing: | ||
| raise SystemExit( | ||
| f"Missing md5 for {len(missing)} files (first 5): {missing[:5]}" | ||
| ) | ||
|
|
||
| with open(OUT_CSV, "w", newline="") as f: | ||
| w = csv.writer(f) | ||
| w.writerow(["filename", "file_url", "md5"]) | ||
| w.writerows(rows) | ||
| print(f"Wrote {len(rows)} rows to {OUT_CSV}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
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.