Getting 'NotImplementedError' to loading coustom dataset

username: mchowdhu
cooked: <p>I am trying to load my custom data set in Pytorch but every time getting  ‘NotImplementedError’.I could not make sense  where I am wrong.<br>
here is my code</p>
<pre><code class="lang-auto">from __future__ import print_function, division
import os
from torch import nn
import torch,torchvision
import pandas as pd
import pandas
from torchvision.transforms import transforms
import numpy as np
import matplotlib.pyplot as plt
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms, utils
from PIL import Image

root_dirA= '/home/mchow/Downloads/homework/datasetA/'
root_dirB= '/home/mchow/Downloads/homework/datasetB/'


fname = '/home/mchow/Downloads/homework/kxr_sq_bu00.sas7bdat'

class OIDataset(Dataset):

   def __init__(self,fname, root_dir,transform=None):

     self.fp = pandas.read_sas( fname, format = 'sas7bdat', encoding='iso-8859-1')

    #get column names and find entries that end with 'KL'
     self.lfp = list(self.fp)
     self.matches = [x for x in self.lfp if 'KL'== x[-2:]]

     self.fp['ID'] = self.fp['ID'].astype('int')
     self.fp['SIDE'] = self.fp['SIDE'].astype('int')

#add 'ID' index
     self.fp_kl = self.fp[ ['ID'] + ['SIDE'] + self.matches]
     self.fp_kl.drop_duplicates(subset=['ID', 'SIDE'])
#change index
     self.kl_table = self.fp_kl.set_index('ID')
     self.root_dir = root_dir
     self.transform = transform



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


def __getitem__(self, idx):
    img_name = os.path.join(self.root_dir, self.ID[idx])

    # Read each 784 pixels and reshape the 1D array ([784]) to 2D array ([28,28])
    patches, p_id = np.load(img_name)
    # get right image
    right_image = Image.fromarray(patches['R'].astype('uint8'), 'L')

    # left image
    left_image = Image.fromarray(patches['L'].astype('uint8'), 'L')

    print(patches, p_id.shape)
    img_class = self.fp_kl[idx]
    img_ID = self.fp[idx]
    img_side = self.fp[idx]
    sample = {'subject id': (patches, p_id), 'side': right_image, 'side2': left_image}
    # Return image and the label
    if self.transform:
        sample = self.transform(sample)

    return sample

trans = transforms.Compose([transforms.ToTensor(),
                               transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5))])

if __name__ == '__main__':

  dset_train = OIDataset(fname,root_dirA,transform=trans)

```Here is the error 
</code></pre>
<p>len(dset_train)<br>
Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “/home/mchow/miniconda3/lib/python3.6/site-packages/torch/utils/data/dataset.py”, line 20, in <strong>len</strong><br>
raise NotImplementedError<br>
NotImplementedError</p>
<pre><code class="lang-auto">I will appreciate any kind of help regarding my question.</code></pre>

username: ptrblck
cooked: <p><code>__len__</code> and <code>__getitem__</code> are at the wrong indentation, thus not part of the <code>Dataset</code> class.<br>
Move them an indentation to the right and run your code again.</p>

username: mchowdhu
cooked: <p>Thank you <a class="mention" href="/u/ptrblck">@ptrblck</a>  ! Now this code is working.</p>

username: Rubz
cooked: <aside class="onebox stackexchange" data-onebox-src="https://stackoverflow.com/questions/77433096/notimplementederror-loading-a-dataset-cached-in-a-localfilesystem-is-not-suppor">
  <header class="source">

      <a href="https://stackoverflow.com/questions/77433096/notimplementederror-loading-a-dataset-cached-in-a-localfilesystem-is-not-suppor" target="_blank" rel="noopener nofollow ugc">stackoverflow.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/6759459/ari" target="_blank" rel="noopener nofollow ugc">
    <img alt="Ari" src="https://i.stack.imgur.com/YgV4g.jpg?s=256&amp;g=1" class="thumbnail onebox-avatar" width="256" height="256">
  </a>

<h4>
  <a href="https://stackoverflow.com/questions/77433096/notimplementederror-loading-a-dataset-cached-in-a-localfilesystem-is-not-suppor" target="_blank" rel="noopener nofollow ugc">NotImplementedError: Loading a dataset cached in a LocalFileSystem is not supported</a>
</h4>

<div class="tags">
  <strong>python, python-3.x, openai-api, huggingface-datasets</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stackoverflow.com/users/6759459/ari" target="_blank" rel="noopener nofollow ugc">
    Ari
  </a>
  on <a href="https://stackoverflow.com/questions/77433096/notimplementederror-loading-a-dataset-cached-in-a-localfilesystem-is-not-suppor" target="_blank" rel="noopener nofollow ugc">05:29PM - 06 Nov 23 UTC</a>
</div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


username: ptrblck
cooked: <p>I don’t see how the linked issue without any further description can be related to PyTorch as it’s using the <code>dataset</code> Python package.</p>