Spaces:
Sleeping
Sleeping
Create dataset_utils.py
Browse files- dataset_utils.py +13 -0
dataset_utils.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 2. dataset_utils.py
|
2 |
+
# Dataset loading and preprocessing
|
3 |
+
from datasets import load_dataset
|
4 |
+
from transformers import ViTImageProcessor
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
def load_insect_dataset():
|
8 |
+
return load_dataset("Francesco/insects-mytwu")
|
9 |
+
|
10 |
+
def preprocess_image(image_path):
|
11 |
+
processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
12 |
+
image = Image.open(image_path).convert("RGB")
|
13 |
+
return processor(image, return_tensors="pt")
|