GithubHelp home page GithubHelp logo

Comments (3)

NielsRogge avatar NielsRogge commented on May 11, 2024

Why is this memory consuming?

Normally, in PyTorch, dataloaders are Python generators, meaning they will only consume RAM when iterating over them.

from transformers-tutorials.

sankalptambe avatar sankalptambe commented on May 11, 2024

Why is this memory consuming?

Normally, in PyTorch, dataloaders are Python generators, meaning they will only consume RAM when iterating over them.

Yeah @NielsRogge , I thought so, and I tried that but it caused the below error.

ValueError: Images must of type `PIL.Image.Image`, `np.ndarray` or `torch.Tensor` (single example),`List[PIL.Image.Image]`, `List[np.ndarray]` or `List[torch.Tensor]` (batch of examples), but is of type <class 'generator'>

The processor() below expects Images as a List[PIL.Image.Image].I am new to all this. Could you help me here?

Below is the code.

class LMDataset(torch.utils.data.Dataset):
    def __init__(self, encodings):
        self.encodings = encodings

    def __getitem__(self, idx):
        item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
        return item

    def __len__(self):
        return len(self.encodings)

processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased", revision="no_ocr")

train_encodings = processor(
        [Image.open(image).convert('RGB') for image in tqdm(train_df['image'])], # <--- this is causing memory issues.
        train_df['words'].tolist(),
        boxes=train_df['boxes'].tolist(),
        word_labels=[[label2id[label] for label in labels] for labels in train_df['labels'].tolist()],
        return_tensors="pt", padding='max_length', truncation=True)

train_dataset = LMDataset(train_encodings)

from transformers-tutorials.

sankalptambe avatar sankalptambe commented on May 11, 2024

Yes my mistake. Missed the 'yield'. Fixed that and working now.

from transformers-tutorials.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.