Skip to content

Commit

Permalink
Merge pull request #2288 from activeloopai/change_pil_byte_calc
Browse files Browse the repository at this point in the history
[AL-2215] Change byte calculation for PIL image in shuffle buffer
  • Loading branch information
levongh committed May 5, 2023
2 parents dffa073 + 2855cec commit 6c46dd4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions deeplake/integrations/pytorch/shuffle_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,16 @@ def _sample_size(self, sample):
elif isinstance(sample, np.ndarray):
return sample.nbytes
elif isinstance(sample, Image.Image):
img = BytesIO()
sample.save(img, sample.format)
return len(img.getvalue())
size = sample.size
num_pixels = size[0] * size[1]
if sample.mode == "RGB":
num_pixels = num_pixels * 3
elif sample.mode == "RGBA":
num_pixels = num_pixels * 4
elif sample.mode == "L":
num_pixels = num_pixels * 1
num_bytes = num_pixels * 1 # change according to dtype of tensor later
return num_bytes
raise ValueError(
f"Expected input of type bytes, dict, Sequence, torch.Tensor, np.ndarray or PIL image, got: {type(sample)}"
)
Expand Down

0 comments on commit 6c46dd4

Please sign in to comment.