title: Python: TypeError: val_dataloader() missing 1 required positional argument: 'self'
body: <p>I am working on an Image Classification Task with PyTorch Lightning. However I get a <code>TypeError</code> while implementing it. I have created the datamodule and model as shown in the PyTorch Lightning examples. The model I am using is <code>VGG16</code> with Batch Normalization.</p>
  <p>In the <code>FruitsDataModule</code> I get the error only for the <code>val_dataloader</code> and not for the <code>train_dataloader</code> which is confusing because both of these funtions are doing the exact same thing just with different data.</p>
  <p>The relevant code has been shown below.</p>
  <h1>DataModule</h1>
  <pre><code>class FruitsDataModule(pl.LightningDataModule):
      
      def __init__(self):
          super().__init__()
          self.transform = transforms.Compose(
              [
                  transforms.ToTensor()
              ]
          )
          
      def setup(self, stage=None):
          
          if stage == 'fit' or stage is None:
  
              full_train_dataset = datasets.ImageFolder(
                  root = config.TRAIN_DATA_PATH,
                  transform = self.transform
              )
              
              train_dataset, val_dataset = train_test_split(
                  full_train_dataset, 
                  test_size=0.33,
                  random_state = 42
              )
              
          if stage == 'test' or stage is None:
  
              test_dataset = datasets.ImageFolder(
                  root = config.TEST_DATA_PATH,
                  transform = self.transform
              )
              
      def train_dataloader(self):
          return DataLoader(
              train_dataset,
              batch_size = config.BATCH_SIZE,
              shuffle = True
          )
          
      def val_dataloader(self):
          return DataLoader(
              val_dataset,
              batch_size = config.BATCH_SIZE,
          )
      
      def test_dataloader(self):
          return DataLoader(
              test_dataset,
              batch_size = config.BATCH_SIZE,
          )
  </code></pre>
  <h1>Model</h1>
  <pre><code>class VGGModel(pl.LightningModule):
      
      def __init__(self):
          super().__init__()
          
          self.model = models.vgg16_bn(pretrained=True)
          self.criterion = nn.CrossEntropyLoss()
          
      def forward(self, x):
          x = self.model(x)
          return x
      
      def step(self, batch):
          x, y = batch
          logits = self.forward(x)
          loss = self.criterion(logits, y)
          preds = torch.argmax(logits, dim=1)
          return loss, preds, y
          
      
      def training_step(self, batch, batch_idx):
          loss, preds, targets = self.step(batch)
          
          # log train metrics
          acc = roc_auc_score(preds, targets)
          self.log(&quot;train/loss&quot;, loss, on_step=False, on_epoch=True, prog_bar=False)
          self.log(&quot;train/acc&quot;, acc, on_step=False, on_epoch=True, prog_bar=True)
          
          return {&quot;loss&quot;: loss, &quot;preds&quot;: preds, &quot;targets&quot;: targets}
      
      
     
      def validation_step(self, batch, batch_idx):
          loss, preds, targets = self.step(batch)
  
          # log val metrics
          acc = roc_auc_score(preds, targets)
          self.log(&quot;val/loss&quot;, loss, on_step=False, on_epoch=True, prog_bar=False)
          self.log(&quot;val/acc&quot;, acc, on_step=False, on_epoch=True, prog_bar=True)
  
          return {&quot;loss&quot;: loss, &quot;preds&quot;: preds, &quot;targets&quot;: targets}
      
      
      def test_step(self, batch, batch_idx):
          loss, preds, targets = self.step(batch)
  
          # log test metrics
          acc = roc_auc_score(preds, targets)
          self.log(&quot;test/loss&quot;, loss, on_step=False, on_epoch=True)
          self.log(&quot;test/acc&quot;, acc, on_step=False, on_epoch=True)
  
          return {&quot;loss&quot;: loss, &quot;preds&quot;: preds, &quot;targets&quot;: targets}
      
     
      
      def configure_optimizers(self):
          optimizer = torch.optim.Adam(self.parameters(), lr = config.LEARNING_RATE)
          return optimizer
  </code></pre>
  <h1>Training</h1>
  <pre><code>model = VGGModel()
  
  trainer = pl.Trainer(
      max_epochs=1,
      gpus=[0],
      precision=32,
      progress_bar_refresh_rate=20
  )
  
  trainer.fit(model, datamodule = FruitsDataModule)
  </code></pre>
  <h1>Error Log</h1>
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-6-5990df7ecb15&gt; in &lt;module&gt;
        8 )
        9 
  ---&gt; 10 trainer.fit(model, datamodule = FruitsDataModule)
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in fit(self, model, train_dataloader, val_dataloaders, datamodule)
      497 
      498         # dispath `start_training` or `start_testing` or `start_predicting`
  --&gt; 499         self.dispatch()
      500 
      501         # plugin will finalized fitting (e.g. ddp_spawn will load trained model)
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in dispatch(self)
      544 
      545         else:
  --&gt; 546             self.accelerator.start_training(self)
      547 
      548     def train_or_test_or_predict(self):
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py in start_training(self, trainer)
       71 
       72     def start_training(self, trainer):
  ---&gt; 73         self.training_type_plugin.start_training(trainer)
       74 
       75     def start_testing(self, trainer):
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/training_type/training_type_plugin.py in start_training(self, trainer)
      112     def start_training(self, trainer: 'Trainer') -&gt; None:
      113         # double dispatch to initiate the training loop
  --&gt; 114         self._results = trainer.run_train()
      115 
      116     def start_testing(self, trainer: 'Trainer') -&gt; None:
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in run_train(self)
      605             self.progress_bar_callback.disable()
      606 
  --&gt; 607         self.run_sanity_check(self.lightning_module)
      608 
      609         # set stage for logging
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in run_sanity_check(self, ref_model)
      852         # to make sure program won't crash during val
      853         if should_sanity_check:
  --&gt; 854             self.reset_val_dataloader(ref_model)
      855             self.num_sanity_val_batches = [
      856                 min(self.num_sanity_val_steps, val_batches) for val_batches in self.num_val_batches
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/data_loading.py in reset_val_dataloader(self, model)
      362         has_step = is_overridden('validation_step', model)
      363         if has_loader and has_step:
  --&gt; 364             self.num_val_batches, self.val_dataloaders = self._reset_eval_dataloader(model, 'val')
      365 
      366     def reset_test_dataloader(self, model) -&gt; None:
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/data_loading.py in _reset_eval_dataloader(self, model, mode)
      276         # always get the loaders first so we can count how many there are
      277         loader_name = f'{mode}_dataloader'
  --&gt; 278         dataloaders = self.request_dataloader(getattr(model, loader_name))
      279 
      280         if not isinstance(dataloaders, list):
  
  /opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/data_loading.py in request_dataloader(self, dataloader_fx)
      396             The dataloader
      397         &quot;&quot;&quot;
  --&gt; 398         dataloader = dataloader_fx()
      399         dataloader = self._flatten_dl_only(dataloader)
      400 
  
  TypeError: val_dataloader() missing 1 required positional argument: 'self'
  </code></pre>
  <p>How to fix this?</p>