Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions nougat/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import logging
import os
from math import prod
import operator
from pathlib import Path
from functools import partial
from functools import partial, reduce
import random
from typing import Dict, Tuple, Callable
from PIL import Image, UnidentifiedImageError
Expand Down Expand Up @@ -247,7 +248,13 @@ def __getitem__(self, idx: int) -> Tuple[torch.Tensor, torch.Tensor]:
if sample is None:
# if sample is broken choose another randomly
return self[random.randint(0, self.dataset_length - 1)]
if sample is None or sample["image"] is None or prod(sample["image"].size) == 0:
try:
# Python 3.8+
is_empty_sample = prod(sample["image"].size) == 0
except:
# Python 3.7
is_empty_sample = reduce(operator.mul, sample["image"].size, 1) == 0
if sample is None or sample["image"] is None or is_empty_sample:
input_tensor = None
else:
input_tensor = self.nougat_model.encoder.prepare_input(
Expand Down