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
|
from torchvision import transforms
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import base64
|
||||||
|
|
||||||
class FilePathLoader:
|
class FilePathLoader:
|
||||||
def __init__(self, dataset, file_path_column="file_path", label_column=None):
|
def __init__(self, dataset, file_path_column="file_path", label_column=None):
|
||||||
|
@ -58,7 +58,16 @@ class JPGImageLoader:
|
||||||
|
|
||||||
def _get_image(self, item):
|
def _get_image(self, item):
|
||||||
try:
|
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)
|
img_bytes = io.BytesIO(bytes_data)
|
||||||
image = Image.open(img_bytes).convert("RGB")
|
image = Image.open(img_bytes).convert("RGB")
|
||||||
return image
|
return image
|
||||||
|
@ -66,6 +75,7 @@ class JPGImageLoader:
|
||||||
print(f"Error loading image from bytes: {e}")
|
print(f"Error loading image from bytes: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_item(self, idx):
|
def get_item(self, idx):
|
||||||
item = self.dataset.iloc[idx]
|
item = self.dataset.iloc[idx]
|
||||||
image = self._get_image(item)
|
image = self._get_image(item)
|
||||||
|
|
Loading…
Reference in New Issue