Skip to content
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

perf: shallow copy instead of deepcopy #197

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from copy import copy
from typing import Dict
from typing import List
from typing import Optional
Expand Down Expand Up @@ -123,7 +124,7 @@ def filter_object_results(
is_target = False

if is_target:
filtered_object_results.append(object_result)
filtered_object_results.append(copy(object_result))

return filtered_object_results

Expand Down Expand Up @@ -198,7 +199,7 @@ def filter_objects(
transforms=transforms,
)
if is_target:
filtered_objects.append(object_)
filtered_objects.append(copy(object_))
return filtered_objects


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from __future__ import annotations

from copy import copy
from typing import Dict
from typing import List
from typing import Optional
Expand Down Expand Up @@ -89,6 +89,23 @@ def __init__(
transforms=frame_ground_truth.transforms,
)

def copy_with_shallow_results(self) -> PerceptionFrameResult:
"""
Create a shallow copy of the current PerceptionFrameResult instance.

This method creates a new instance of PerceptionFrameResult by performing a shallow copy
of the current instance. The `metrics_score` and `pass_fail_result` attributes are also
shallow copied to the new instance.

Returns:
PerceptionFrameResult: A new instance of PerceptionFrameResult with shallow copied attributes.
"""

new_instance = copy(self)
new_instance.metrics_score = copy(self.metrics_score)
new_instance.pass_fail_result = copy(self.pass_fail_result)
return new_instance

def evaluate_frame(
self,
previous_result: Optional[PerceptionFrameResult] = None,
Expand Down
2 changes: 1 addition & 1 deletion perception_eval/perception_eval/tool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def filter_frame_by_distance(
Returns:
PerceptionFrameResult: Filtered frame results.
"""
ret_frame = deepcopy(frame)
ret_frame = frame.copy_with_shallow_results()

if min_distance is not None:
min_distance_list = [min_distance] * len(ret_frame.target_labels)
Expand Down
Loading