(video_path, num_segments=8)
| 206 | return image |
| 207 | |
| 208 | def load_video(video_path, num_segments=8): |
| 209 | vr = VideoReader(video_path, ctx=cpu(0)) |
| 210 | num_frames = len(vr) |
| 211 | frame_indices = get_index(num_frames, num_segments) |
| 212 | |
| 213 | # transform |
| 214 | crop_size = 224 |
| 215 | scale_size = 224 |
| 216 | input_mean = [0.48145466, 0.4578275, 0.40821073] |
| 217 | input_std = [0.26862954, 0.26130258, 0.27577711] |
| 218 | |
| 219 | transform = T.Compose([ |
| 220 | GroupScale(int(scale_size), interpolation=InterpolationMode.BICUBIC), |
| 221 | GroupCenterCrop(crop_size), |
| 222 | Stack(), |
| 223 | ToTorchFormatTensor(), |
| 224 | GroupNormalize(input_mean, input_std) |
| 225 | ]) |
| 226 | |
| 227 | images_group = list() |
| 228 | for frame_index in frame_indices: |
| 229 | img = Image.fromarray(vr[frame_index].asnumpy()) |
| 230 | images_group.append(img) |
| 231 | video = transform(images_group) |
| 232 | return video |
| 233 | |
| 234 | class StoppingCriteriaSub(StoppingCriteria): |
| 235 |
no test coverage detected