title: Simple way to load specific sample using Pytorch dataloader
body: <p>I am currently training a 3D CNN for binary classification with relatively sparse labels (~ 1% of voxels in label data correspond to target class). </p>
  
  <p>In order to perform basic sanity checks during the training (e.g. does the network learn at all?) it would be handy to present the network with a small, handpicked subset of training examples having an above-average fraction of target class labels.</p>
  
  <p>As suggested by the Pytorch documentation, I implemented my own <code>dataset</code> class (inheriting from <code>torch.utils.data.Dataset</code>) which provides training examples via it's <code>__get_item__</code> method to the <code>torch.utils.data.DataLoader</code>.</p>
  
  <p>In the <a href="https://pytorch.org/tutorials/beginner/data_loading_tutorial.html" rel="noreferrer">pytorch tutorials</a> I found, the <code>DataLoader</code> is used as an iterator to generate the training loop like so:</p>
  
  <pre><code>for i, data in enumerate(self.dataloader):
  
      # Get training data
      inputs, labels = data
  
      # Train the network
      # [...]
  </code></pre>
  
  <p><strong>What I am wondering now is whether there exist a simple way to load a single or a couple of specific training examples</strong> (using a the linear index understood by <code>Dataset</code>'s <code>__get_item__</code> method). However, <code>DataLoader</code> does not have a <code>__get_item__</code> method and repeatedly calling <code>__next__</code> until I reach the desired index does not seem elegant. </p>
  
  <p>Apparently one possible way to solve this would be to define a custom <code>sampler</code> or <code>batch_sampler</code> inheriting from the abstract <code>torch.utils.data.Sampler</code>. But this seems over the top to retrieve a few specific samples. </p>
  
  <p>I suppose I am overlooking something very simple and obvious here. Any advice appreciated!</p>