Update dataset.py
Browse files- dataset.py +6 -13
dataset.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
-
import os
|
| 2 |
import json
|
| 3 |
-
import zipfile
|
| 4 |
-
from PIL import Image
|
| 5 |
from torch.utils.data import Dataset
|
|
|
|
| 6 |
|
| 7 |
class CustomDataset(Dataset):
|
| 8 |
-
def __init__(self, json_path,
|
| 9 |
self.data = self.load_data(json_path, split)
|
| 10 |
-
self.
|
|
|
|
| 11 |
|
| 12 |
def load_data(self, json_path, split):
|
| 13 |
with open(json_path, 'r', encoding='utf-8') as f:
|
|
@@ -20,12 +19,6 @@ class CustomDataset(Dataset):
|
|
| 20 |
def __getitem__(self, idx):
|
| 21 |
item = self.data[idx]
|
| 22 |
image_path = item['image']
|
|
|
|
| 23 |
text = item['text']
|
| 24 |
-
|
| 25 |
-
with zipfile.ZipFile(self.zip_path, 'r') as zip_ref:
|
| 26 |
-
with zip_ref.open(image_path) as img_file:
|
| 27 |
-
image = Image.open(img_file)
|
| 28 |
-
return {"image": image, "text": text}
|
| 29 |
-
|
| 30 |
-
def load_dataset(json_path, zip_path, split):
|
| 31 |
-
return CustomDataset(json_path, zip_path, split)
|
|
|
|
|
|
|
| 1 |
import json
|
|
|
|
|
|
|
| 2 |
from torch.utils.data import Dataset
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
class CustomDataset(Dataset):
|
| 6 |
+
def __init__(self, json_path, split):
|
| 7 |
self.data = self.load_data(json_path, split)
|
| 8 |
+
self.split = split
|
| 9 |
+
|
| 10 |
|
| 11 |
def load_data(self, json_path, split):
|
| 12 |
with open(json_path, 'r', encoding='utf-8') as f:
|
|
|
|
| 19 |
def __getitem__(self, idx):
|
| 20 |
item = self.data[idx]
|
| 21 |
image_path = item['image']
|
| 22 |
+
image = Image.open(image_path)
|
| 23 |
text = item['text']
|
| 24 |
+
return {"image": image, "text": text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|