(image_file, input_size=224)
| 124 | return model, tokenizer |
| 125 | |
| 126 | def load_image(image_file, input_size=224): |
| 127 | if image_file.startswith('http') or image_file.startswith('https'): |
| 128 | response = requests.get(image_file) |
| 129 | image = Image.open(BytesIO(response.content)).convert('RGB') |
| 130 | else: |
| 131 | image = Image.open(image_file).convert('RGB') |
| 132 | |
| 133 | crop_pct = 224 / 256 |
| 134 | size = int(input_size / crop_pct) |
| 135 | transform = T.Compose([ |
| 136 | T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img), |
| 137 | T.Resize(size, interpolation=InterpolationMode.BICUBIC), |
| 138 | T.CenterCrop(input_size), |
| 139 | T.ToTensor(), |
| 140 | T.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)) |
| 141 | ]) |
| 142 | image = transform(image) |
| 143 | return image |
| 144 | |
| 145 | def load_video(video_path, num_segments=8): |
| 146 | vr = VideoReader(video_path, ctx=cpu(0)) |
no outgoing calls
no test coverage detected