musk12 commited on
Commit
36bed8c
·
verified ·
1 Parent(s): 508f995

Update inference_vit.py

Browse files
Files changed (1) hide show
  1. 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
- img_obj = dataset[image_id]["image"] # returns PIL.Image
121
- label_idx = dataset[image_id]["label"] # integer
122
- label_name = dataset.features["label"].names[label_idx] # human-readable
 
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}")