corrected loading
This commit is contained in:
parent
b5da2e477d
commit
51da6b5aa2
|
@ -5,7 +5,7 @@ from torch.utils.data import DataLoader
|
|||
from torchvision import transforms
|
||||
import random
|
||||
import re
|
||||
|
||||
import base64
|
||||
|
||||
class FilePathLoader:
|
||||
def __init__(self, dataset, file_path_column="file_path", label_column=None):
|
||||
|
@ -55,16 +55,26 @@ class JPGImageLoader:
|
|||
|
||||
if self.bytes_column not in dataset.columns:
|
||||
raise ValueError(f"Column '{self.bytes_column}' not found in dataset.")
|
||||
|
||||
|
||||
def _get_image(self, item):
|
||||
try:
|
||||
bytes_data = item[self.bytes_column]
|
||||
# Retrieve the string data
|
||||
data = item[self.bytes_column]
|
||||
|
||||
# Check if the data is a string, and decode it
|
||||
if isinstance(data, str):
|
||||
bytes_data = base64.b64decode(data) # Adjust decoding as per your data encoding format
|
||||
else:
|
||||
bytes_data = data
|
||||
|
||||
# Load the bytes into a BytesIO object and open the image
|
||||
img_bytes = io.BytesIO(bytes_data)
|
||||
image = Image.open(img_bytes).convert("RGB")
|
||||
return image
|
||||
except Exception as e:
|
||||
print(f"Error loading image from bytes: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_item(self, idx):
|
||||
item = self.dataset.iloc[idx]
|
||||
|
|
Loading…
Reference in New Issue