File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -196,11 +196,18 @@ def _generic_time_based_sampler(
196
196
)
197
197
else :
198
198
assert seconds_between_clip_starts is not None # appease type-checker
199
+ # The torch.arange documentation warns that floating point rounding errors
200
+ # are possible for non-integer steps when comparing to end.
201
+ # To prevent this, we check if the last clip_start_seconds value is
202
+ # equal to the end value, and remove it.
203
+ # docs.pytorch.org/docs/2.8/generated/torch.arange.html
199
204
clip_start_seconds = torch .arange (
200
205
sampling_range_start ,
201
206
sampling_range_end , # excluded
202
- round ( seconds_between_clip_starts , 6 ) ,
207
+ seconds_between_clip_starts ,
203
208
)
209
+ if clip_start_seconds [- 1 ] >= sampling_range_end :
210
+ clip_start_seconds = clip_start_seconds [:- 1 ]
204
211
num_clips = len (clip_start_seconds )
205
212
206
213
all_clips_timestamps = _build_all_clips_timestamps (
You can’t perform that action at this time.
0 commit comments