| 193 | return image |
| 194 | |
| 195 | def load_image(image, input_size=224): |
| 196 | crop_pct = 224 / 256 |
| 197 | size = int(input_size / crop_pct) |
| 198 | transform = T.Compose([ |
| 199 | T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img), |
| 200 | T.Resize(size, interpolation=InterpolationMode.BICUBIC), |
| 201 | T.CenterCrop(input_size), |
| 202 | T.ToTensor(), |
| 203 | T.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)) |
| 204 | ]) |
| 205 | image = transform(image) |
| 206 | return image |
| 207 | |
| 208 | def load_video(video_path, num_segments=8): |
| 209 | vr = VideoReader(video_path, ctx=cpu(0)) |