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

Fix task creation with gt job and gt job frame access #8510

Merged
merged 14 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
@@ -0,0 +1,6 @@
### Fixed

- Invalid chunks for GT jobs when `?number` is used in the request and task frame step > 1
(<https://github.com/cvat-ai/cvat/pull/8510>)
- Invalid output of frames for specific GT frame requests with `api/jobs/{id}/data/?type=frame`
(<https://github.com/cvat-ai/cvat/pull/8510>)
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions cvat/apps/engine/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,7 @@ def get_frames():
frame_range = (
(
db_data.start_frame
+ chunk_number * db_data.chunk_size
+ chunk_frame_idx * frame_step
+ (chunk_number * db_data.chunk_size + chunk_frame_idx) * frame_step
)
for chunk_frame_idx in range(db_data.chunk_size)
)
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/frame_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def __len__(self):
return self._db_segment.frame_count

def validate_frame_number(self, frame_number: int) -> Tuple[int, int, int]:
frame_sequence = list(self._db_segment.frame_set)
frame_sequence = sorted(self._db_segment.frame_set)
abs_frame_number = self._get_abs_frame_number(self._db_segment.task.data, frame_number)
if abs_frame_number not in frame_sequence:
raise ValidationError(f"Incorrect requested frame number: {frame_number}")
Expand Down
7 changes: 5 additions & 2 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ def create(self, validated_data):
"The number of validation frames is not specified"
)

task_frame_provider = TaskFrameProvider(task)
seed = validated_data.pop("random_seed", None)

# The RNG backend must not change to yield reproducible results,
Expand All @@ -832,7 +833,7 @@ def create(self, validated_data):
frames: list[int] = []
overlap = task.overlap
for segment in task.segment_set.all():
segment_frames = set(segment.frame_set)
segment_frames = set(map(task_frame_provider.get_rel_frame_number, segment.frame_set))
selected_frames = segment_frames.intersection(frames)
selected_count = len(selected_frames)

Expand All @@ -841,12 +842,14 @@ def create(self, validated_data):
continue

selectable_segment_frames = set(
sorted(segment.frame_set)[overlap * (segment.start_frame != 0) : ]
sorted(segment_frames)[overlap * (segment.start_frame != 0) : ]
).difference(selected_frames)

frames.extend(rng.choice(
tuple(selectable_segment_frames), size=missing_count, replace=False
).tolist())

frames = list(map(task_frame_provider.get_abs_frame_number, frames))
elif frame_selection_method == models.JobFrameSelectionMethod.MANUAL:
frames = validated_data.pop("frames")

Expand Down
14 changes: 10 additions & 4 deletions cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,9 @@ def _update_status(msg: str) -> None:
seed = validation_params.get("random_seed")
rng = random.Generator(random.MT19937(seed=seed))

def _to_rel_frame(abs_frame: int) -> int:
return (abs_frame - db_data.start_frame) // db_data.get_frame_step()

match validation_params["frame_selection_method"]:
case models.JobFrameSelectionMethod.RANDOM_UNIFORM:
all_frames = range(db_data.size)
Expand Down Expand Up @@ -1431,7 +1434,7 @@ def _update_status(msg: str) -> None:
validation_frames: list[int] = []
overlap = db_task.overlap
for segment in db_task.segment_set.all():
segment_frames = set(segment.frame_set)
segment_frames = set(map(_to_rel_frame, segment.frame_set))
selected_frames = segment_frames.intersection(validation_frames)
selected_count = len(selected_frames)

Expand All @@ -1440,7 +1443,7 @@ def _update_status(msg: str) -> None:
continue

selectable_segment_frames = set(
sorted(segment.frame_set)[overlap * (segment.start_frame != 0) : ]
sorted(segment_frames)[overlap * (segment.start_frame != 0) : ]
).difference(selected_frames)

validation_frames.extend(rng.choice(
Expand All @@ -1457,7 +1460,7 @@ def _update_status(msg: str) -> None:
)

validation_frames: list[int] = []
known_frame_names = {frame.path: frame.frame for frame in images}
known_frame_names = {frame.path: _to_rel_frame(frame.frame) for frame in images}
unknown_requested_frames = []
for frame_filename in validation_params['frames']:
frame_id = known_frame_names.get(frame_filename)
Expand All @@ -1484,11 +1487,14 @@ def _update_status(msg: str) -> None:
# TODO: refactor
if hasattr(db_data, 'validation_layout'):
if db_data.validation_layout.mode == models.ValidationMode.GT:
def _to_abs_frame(rel_frame: int) -> int:
return rel_frame * db_data.get_frame_step() + db_data.start_frame

db_gt_segment = models.Segment(
task=db_task,
start_frame=0,
stop_frame=db_data.size - 1,
frames=db_data.validation_layout.frames,
frames=list(map(_to_abs_frame, db_data.validation_layout.frames)),
type=models.SegmentType.SPECIFIC_FRAMES,
)
elif db_data.validation_layout.mode == models.ValidationMode.GT_POOL:
Expand Down
Loading
Loading