PyTorch DataLoader NotImplementedError

Jinyoung: <p>Hi<br>
I have tried to implement own my Dataset &amp; DataLoader for my neural net, but I encounterd ‘NotImplementError’.</p>
<p>Below is my code:</p>
<pre><code class="lang-auto">class GenDataset(Dataset):
    def __init__(self, pddataset, args):
        super(GenDataset, self).__init__()

        self.pddataset = pddataset

        if torch.cuda.is_available():
            torch.set_default_tensor_type('torch.cuda.FloatTensor')
        else:
            torch.set_default_tensor_type('torch.FloatTensor')


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


    def _getitem__(self, index):
        return self.pddataset[index]
</code></pre>
<p>And Below is my PyTorch DataLoader code that I implemented.</p>
<pre><code class="lang-auto">import os, sys
sys.path.append('/home/byun/PROject/DEEPSEEKER/')
import argparse
import numpy as np
import pandas as pd

import torch
from torch.utils.data import Dataset, DataLoader
from FUNC.GenDataset import GenDataset

def DATAset_partition(args):
    ########################################
    #
    # Generate setting variables
    #
    ########################################   
    pardir = args.pardir
    p_dir = os.getcwd()
    Data_path = f'{pardir}/DATA'


    df = pd.read_csv(f'{pardir}/CSV/All_HistoData-1.csv')
    print(f'# The loaded Data shape: {df.shape}')
    train_set = df.iloc[: n_train, :]
    val_set   = df.iloc[: n_val, :]
    test_set  = df.iloc[: n_test, :]
    print(f'# The train: {train_set.shape}')
    print(f'# The validation: {val_set.shape}')
    print(f'# The test: {test_set.shape}')
    
    ########################################
    #
    # Load Data
    #
    ########################################   
    train_loader = GenDataset(train_set, args)
    valid_loader = GenDataset(val_set, args)
    test_loader = GenDataset(test_set, args)
    
    partition = {'train': train_loader,
                 'val': valid_loader,
                 'test': test_loader}

    return partition


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    args = parser.parse_args("")
    args.dataset_mode = 'train'
    args.num_total = 1000
    args.val_size = 0.2
    args.test_size = 0.1
    args.train_batch_size = 50
    args.pardir = '/home/byun/PROject/DEEPSEEKER'
    partition = DATAset_partition(args)

    trainloader = DataLoader(partition['train'], batch_size=args.train_batch_size, shuffle=True)

    for idx, data in enumerate(trainloader):
        print(data)
</code></pre>
<p>And the picture below is the error I met.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/2/0213e2ac6307d2ec7385debe7212a3b67f57f080.png" data-download-href="https://discuss.pytorch.org/uploads/default/0213e2ac6307d2ec7385debe7212a3b67f57f080" title="Screenshot from 2020-07-20 15-34-20"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/2/0213e2ac6307d2ec7385debe7212a3b67f57f080_2_690x128.png" alt="Screenshot from 2020-07-20 15-34-20" data-base62-sha1="inyFYfd368MTMr31Y72kKhspMc" width="690" height="128" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/2/0213e2ac6307d2ec7385debe7212a3b67f57f080_2_690x128.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/2/0213e2ac6307d2ec7385debe7212a3b67f57f080_2_1035x192.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/2/0213e2ac6307d2ec7385debe7212a3b67f57f080.png 2x" data-dominant-color="411E36"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2020-07-20 15-34-20</span><span class="informations">1164×217 43.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>As I searched, the ‘NotImplementedError’  is due to indentation. But I couldn’t find any indentation typo.</p>
<p>Please let me know what am i miss…<br>
Thank you for your reply in advance!</p>

Nikronic: <p>Hi, it might be strange but you missed a <code>_</code> in definition of <code>__getitem__</code> and that is why it cannot find your implementation.</p>
<aside class="quote no-group" data-username="Jinyoung" data-post="1" data-topic="89840">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jinyoung/48/21064_2.png" class="avatar"> Jinyoung:</div>
<blockquote>
<p><code>    def _getitem__(self, index):</code></p>
</blockquote>
</aside>
<p>Bests</p>

Jinyoung: <p>Oh thank you!! <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>