Skip to content

Refactor evaluation flow #309

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
merged 7 commits into from
May 26, 2023
Merged

Refactor evaluation flow #309

merged 7 commits into from
May 26, 2023

Conversation

hadipash
Copy link
Collaborator

Thank you for your contribution to the MindOCR repo.
Before submitting this PR, please make sure:

Motivation

  • Set return type to dictionary in det_postprocess.py to match the project's default data handling flow.
  • Moved checkpoints summary printing to the end of training to reduce visual noise in training logs.
  • Fixed bug that caused evaluation crash if no postprocessing is set.

This was referenced May 24, 2023
Copy link
Collaborator

@SamitHuang SamitHuang left a comment

Choose a reason for hiding this comment

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

It's high recommended to add a unit test for DetBasePostprocessing as it is a common API, to ensure it works as expected in different settings.

if isinstance(sample, np.ndarray):
result = np.round(sample * shape[:1:-1])
else:
result = [np.round(s * shape[:1:-1]) for s in sample]
Copy link
Collaborator

Choose a reason for hiding this comment

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

shape[:1:-1]) --> shape[::-1]. otherwise, it will be wrong if scale_h, and scale_w are different.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the shape's values are [h, w, scale_h, scale_w]. shape[:1:-1] takes the last 2 values (which are scale_h and scale_w) and reverse them to match x, y order of data.

self._scale_fields = rescale_fields

@staticmethod
def _scale_sample(sample: Union[List[np.ndarray], np.ndarray], shape: np.ndarray):
Copy link
Collaborator

Choose a reason for hiding this comment

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

the name sample is easy to get confuse with data sample. but the input here are polygons, curves, or boxes for text region representation. replacing sample with field or result will be intuitive, e.g., _rescale_result(...)

def _scale_sample(sample: Union[List[np.ndarray], np.ndarray], shape: np.ndarray):
# shape: [h, w, scale_h, scale_w]
if isinstance(sample, np.ndarray):
result = np.round(sample * shape[:1:-1])
Copy link
Collaborator

@SamitHuang SamitHuang May 25, 2023

Choose a reason for hiding this comment

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

Either we np.clip the rounded coordinates in origin_width, orgin_height to avoid being out of the image. Or we don't clip and still keep float type here, then np.clip all at one in the end.

@SamitHuang
Copy link
Collaborator

related to this pr: #316

@SamitHuang SamitHuang merged commit 674c100 into mindspore-lab:main May 26, 2023
import cv2
import numpy as np
from shapely.geometry import Polygon
import mindspore as ms
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line#236 and Line#242 need this import.

@hadipash hadipash deleted the refactor branch May 30, 2023 05:47
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.

5 participants