Update inference_vit.py
Browse files- inference_vit.py +6 -3
inference_vit.py
CHANGED
|
@@ -116,10 +116,13 @@ def load_image_by_id2(image_id):
|
|
| 116 |
"""
|
| 117 |
Load image and label directly from Hugging Face dataset
|
| 118 |
"""
|
|
|
|
|
|
|
| 119 |
try:
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
| 123 |
return img_obj, label_name
|
| 124 |
except Exception as e:
|
| 125 |
print(f"Error loading image {image_id}: {e}")
|
|
|
|
| 116 |
"""
|
| 117 |
Load image and label directly from Hugging Face dataset
|
| 118 |
"""
|
| 119 |
+
global dataset # make sure dataset is global
|
| 120 |
+
|
| 121 |
try:
|
| 122 |
+
# select train split
|
| 123 |
+
img_obj = dataset['train'][image_id]["image"] # returns PIL.Image
|
| 124 |
+
label_idx = dataset['train'][image_id]["label"] # integer
|
| 125 |
+
label_name = dataset['train'].features["label"].names[label_idx] # human-readable
|
| 126 |
return img_obj, label_name
|
| 127 |
except Exception as e:
|
| 128 |
print(f"Error loading image {image_id}: {e}")
|