Skip to content

Fix Sliding Window Logic and Add Error Handling in Inference Scripts - #1

Open
stephen-netu wants to merge 2 commits into
apple:mainfrom
stephen-netu:main
Open

Fix Sliding Window Logic and Add Error Handling in Inference Scripts#1
stephen-netu wants to merge 2 commits into
apple:mainfrom
stephen-netu:main

Conversation

@stephen-netu

Copy link
Copy Markdown

Greetings,

This pull request addresses a critical bug in the sliding window implementation that prevented proper image coverage for non-square inputs, and adds comprehensive error handling to improve script reliability and user experience.

Key Changes

1. Sliding Window Bug Fix (reward_model_example_inference.py)

  • Problem: Original logic only slid windows in one direction based on aspect ratio, missing significant image regions for tall/wide images
  • Solution: Implemented bidirectional sliding with 50% overlap for complete coverage regardless of aspect ratio
  • Impact: Ensures accurate UI quality scoring across all image types

2. Error Handling Improvements

  • generator_model_client_inference.py:

    • Added network request error handling (timeouts, connection failures)
    • Added JSON parsing validation with KeyError handling
    • Improved error messages for debugging
  • reward_model_example_inference.py:

    • Added file loading error handling for images
    • Added model/processor loading error handling
    • Added CUDA availability check with fallback to CPU
    • Added descriptive error messages for all failure modes

3. Code Quality Enhancements

  • Added function docstrings for better documentation
  • Consistent code formatting and style improvements
  • Removed redundant logic in sliding window implementation

Testing Performed

  • Verified sliding window now covers entire image with proper overlap
  • Tested error conditions (missing files, invalid models, network failures)
  • Confirmed backward compatibility with existing usage
  • Validated performance impact is minimal

Files Modified

  • generator_model_client_inference.py
  • reward_model_example_inference.py

…hensive error handling for network requests, file loading, and model loading, and improve code documentation
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.

1 participant