Update app.py
Browse files
app.py
CHANGED
|
@@ -141,35 +141,6 @@ run_libra.load_model = safe_load_model
|
|
| 141 |
# (because ccd imports these functions during module load)
|
| 142 |
import libra.eval.run_libra as run_libra_module
|
| 143 |
|
| 144 |
-
# Patch get_image_tensors_batch to force CPU
|
| 145 |
-
def get_image_tensors_batch_cpu(images, image_processor, model=None):
|
| 146 |
-
"""CPU-only version of get_image_tensors_batch"""
|
| 147 |
-
from PIL import Image
|
| 148 |
-
|
| 149 |
-
if not isinstance(images, list):
|
| 150 |
-
images = [images]
|
| 151 |
-
|
| 152 |
-
image_tensors = []
|
| 153 |
-
for image in images:
|
| 154 |
-
if isinstance(image, str):
|
| 155 |
-
image = Image.open(image).convert('RGB')
|
| 156 |
-
|
| 157 |
-
# Process image
|
| 158 |
-
if hasattr(image_processor, 'preprocess'):
|
| 159 |
-
image_tensor = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0]
|
| 160 |
-
else:
|
| 161 |
-
image_tensor = image_processor(image, return_tensors='pt')['pixel_values'][0]
|
| 162 |
-
|
| 163 |
-
# Force to CPU (no GPU check)
|
| 164 |
-
image_tensor = image_tensor.to(device='cpu', dtype=torch.float32)
|
| 165 |
-
image_tensors.append(image_tensor)
|
| 166 |
-
|
| 167 |
-
if len(image_tensors) == 1:
|
| 168 |
-
img = image_tensors[0].unsqueeze(0)
|
| 169 |
-
return torch.cat([img, img.clone()], dim=0)
|
| 170 |
-
else:
|
| 171 |
-
return torch.stack(image_tensors, dim=0)
|
| 172 |
-
|
| 173 |
# Replace the function in the module BEFORE ccd imports it
|
| 174 |
run_libra_module.get_image_tensors_batch = get_image_tensors_batch_cpu
|
| 175 |
print('[INFO] Replaced get_image_tensors_batch with CPU-only version')
|
|
|
|
| 141 |
# (because ccd imports these functions during module load)
|
| 142 |
import libra.eval.run_libra as run_libra_module
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
# Replace the function in the module BEFORE ccd imports it
|
| 145 |
run_libra_module.get_image_tensors_batch = get_image_tensors_batch_cpu
|
| 146 |
print('[INFO] Replaced get_image_tensors_batch with CPU-only version')
|