(video_path, num_segments=8)
| 143 | return image |
| 144 | |
| 145 | def load_video(video_path, num_segments=8): |
| 146 | vr = VideoReader(video_path, ctx=cpu(0)) |
| 147 | num_frames = len(vr) |
| 148 | frame_indices = get_index(num_frames, num_segments) |
| 149 | |
| 150 | # transform |
| 151 | crop_size = 224 |
| 152 | scale_size = 224 |
| 153 | input_mean = [0.48145466, 0.4578275, 0.40821073] |
| 154 | input_std = [0.26862954, 0.26130258, 0.27577711] |
| 155 | |
| 156 | transform = T.Compose([ |
| 157 | GroupScale(int(scale_size), interpolation=InterpolationMode.BICUBIC), |
| 158 | GroupCenterCrop(crop_size), |
| 159 | Stack(), |
| 160 | ToTorchFormatTensor(), |
| 161 | GroupNormalize(input_mean, input_std) |
| 162 | ]) |
| 163 | |
| 164 | images_group = list() |
| 165 | for frame_index in frame_indices: |
| 166 | img = Image.fromarray(vr[frame_index].asnumpy()) |
| 167 | images_group.append(img) |
| 168 | video = transform(images_group) |
| 169 | return video |
| 170 | |
| 171 | class StoppingCriteriaSub(StoppingCriteria): |
| 172 |
no test coverage detected