Skip to content

[Minor] Add HDF5 export to report_spectf.py#93

Open
jakehlee wants to merge 1 commit intodevelopfrom
spectf_lee
Open

[Minor] Add HDF5 export to report_spectf.py#93
jakehlee wants to merge 1 commit intodevelopfrom
spectf_lee

Conversation

@jakehlee
Copy link
Copy Markdown
Collaborator

This PR adds the ability to export OOD model predictions as an HDF5 to report_spectf.py. We intentionally avoid exporting sim test results because they are generated at runtime. The HDF5 produced here is aligned with the input OOD HDF5 and can be compared against the labels as-is.

@jakehlee jakehlee changed the title [Minor] Add HDf5 export to report_spectf.py [Minor] Add HDF5 export to report_spectf.py Apr 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional CLI flag to models/spectf/report_spectf.py to export OOD prediction probabilities (y_hat_ood) into an HDF5 file alongside the generated report artifacts.

Changes:

  • Add --export flag to the report generator CLI.
  • When enabled, write y_hat_ood to outdir/y_hat_ood.h5 using h5py.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

y_hat_ood[i*bs:i*bs+batch_len] = batch_y_hat

if export:
export_path = os.path.join(outdir, "y_hat_ood.h5")
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The export always writes to a fixed filename ("y_hat_ood.h5") in outdir, so repeated runs will silently overwrite previous exports. Consider incorporating the run_name/timestamp into the filename and/or failing when the destination already exists unless an explicit overwrite flag is provided.

Suggested change
export_path = os.path.join(outdir, "y_hat_ood.h5")
export_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
export_filename = f"y_hat_ood_{export_timestamp}.h5"
export_path = os.path.join(outdir, export_filename)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good suggestion.

Comment on lines +195 to +196
with h5py.File(export_path, "w") as f:
f.create_dataset("y_hat_ood", data=y_hat_ood)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y_hat_ood is being exported as float64 because the array is built via .astype(float) and np.zeros_like(..., dtype=float). For large OOD sets this can double disk usage; consider exporting as float32 and (optionally) using HDF5 compression (e.g., gzip) to keep file sizes manageable.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

@michaelkiper michaelkiper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants