Skip to content

fix: resolve multiple open issues (#11, #19, #20, #7/#12/#16/#23)#27

Draft
Thmen wants to merge 4 commits intomasterfrom
cursor/-bc-e1e287e2-008a-4c44-915e-dce05cb9b70b-193c
Draft

fix: resolve multiple open issues (#11, #19, #20, #7/#12/#16/#23)#27
Thmen wants to merge 4 commits intomasterfrom
cursor/-bc-e1e287e2-008a-4c44-915e-dce05cb9b70b-193c

Conversation

@Thmen
Copy link
Copy Markdown
Owner

@Thmen Thmen commented Mar 25, 2026

Summary

This PR addresses several open issues in the EGVSR repository with code fixes and documentation improvements.

Issues Fixed

Fix #11: Circular import in LPIPS module (profile.sh fails with AttributeError)

Problem: Running profile.sh (or any code importing LPIPS) fails with:

AttributeError: module 'metrics.LPIPS' has no attribute 'models'

This was caused by a circular import chain: models/__init__.pydist_modelnetworks_basicmetrics.LPIPS.models (same __init__.py still loading).

Solution: Extract utility functions (normalize_tensor, tensor2im, l2, etc.) from models/__init__.py into a dedicated util.py module. Update networks_basic.py and dist_model.py to use relative imports (from . import util) instead of absolute imports that trigger circular dependencies. The PerceptualLoss class now uses lazy import for dist_model.

Fix #20: NaN metrics when running test.sh

Problem: All metrics (PSNR, LPIPS, tOF) show as NaN with warnings about "Mean of empty slice".

Root causes & solutions:

  1. metric_calculator.py only searched for .png files in GT directories, but data could be in .jpg format (the dataset loader already supported both). Fixed to accept png|jpg.
  2. Empty metric lists were averaged without protection, producing NaN. Added guards to skip empty lists and show informative warnings instead.
  3. Bare except: clauses in main.py silently swallowed all errors during metric computation, making debugging impossible. Replaced with except Exception as e: and proper logging.

Fix #19: test.sh usage unclear

Problem: Users didn't know how to properly invoke test.sh and profile.sh.

Solution: Added usage instructions, argument descriptions, examples, and input validation with helpful error messages to both scripts.

Fix #7, #12, #16, #23: Testing dataset download links broken

Problem: The Baidu Netdisk download link for testing datasets (Vid4, ToS3, Gvt72) is no longer available.

Solution: Updated README to mark the link as defunct and provide alternative guidance for obtaining the datasets.

Changes

File Change
codes/metrics/LPIPS/models/util.py New file: extracted utility functions
codes/metrics/LPIPS/models/__init__.py Simplified to import from util.py, lazy import for dist_model
codes/metrics/LPIPS/models/dist_model.py Use relative import for util
codes/metrics/LPIPS/models/networks_basic.py Use relative import for util
codes/metrics/metric_calculator.py Support jpg files, protect against empty lists
codes/main.py Replace bare except with proper error handling
test.sh Add usage docs, validation, error messages
profile.sh Add usage docs, validation, error messages
README.md Note about broken download links
Open in Web Open in Cursor 

cursoragent and others added 4 commits March 25, 2026 04:16
Extract utility functions from models/__init__.py into a dedicated
util.py module to break the circular import chain:
  __init__.py -> dist_model -> networks_basic -> __init__.py

- Create codes/metrics/LPIPS/models/util.py with shared helper functions
- Update __init__.py to import from util.py and use lazy import for dist_model
- Update networks_basic.py to use relative import 'from . import util'
- Update dist_model.py to use relative import 'from . import util'
- Ensure codes/metrics/__init__.py and codes/metrics/LPIPS/__init__.py exist

Co-authored-by: Thmen <Thmen@users.noreply.github.com>
…t protection (fixes #20)

- Change metric_calculator to accept both png and jpg image files
  (consistent with PairedFolderDataset which already accepts both)
- Add warning when no GT image files are found in a directory
- Add protection against averaging empty metric lists (prevents NaN)
- Replace bare except clauses in main.py with proper exception handling
- Show clear warning messages instead of silent failures

Co-authored-by: Thmen <Thmen@users.noreply.github.com>
…ile.sh (fixes #19)

- Add usage examples and argument descriptions to both scripts
- Add input validation with helpful error messages
- Add directory existence checks before running
- Users no longer need to guess the correct command format

Co-authored-by: Thmen <Thmen@users.noreply.github.com>
…#7, #12, #16, #23)

- Mark the original Baidu Netdisk link as no longer available
- Add alternative guidance for obtaining testing datasets

Co-authored-by: Thmen <Thmen@users.noreply.github.com>
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.

metric is NaN bash test.sh Run profile.sh failed [Download Testset]

2 participants