Search code examples
pythondeep-learningneural-network

How to fix error "Module is not callable"


I am getting error "Module is not callable" at the function val_dataloader step. I already saw that this error may be caused by pyhton confusion between module and class, but still I am not able to resolve it.

class UCFDataModule(pytorch_lightning.LightningDataModule):

  _CLIP_DURATION = 2  # Duration of sampled clip for each video
  _BATCH_SIZE = 8
  _NUM_WORKERS = 8  # Number of parallel processes fetching data
    
  def train_dataloader(self):

    train_dataset = pytorchvideo.data.ucf101(
        data_path = os.path.join(dataset_root_path, "train"),
        clip_sampler = pytorchvideo.data.make_clip_sampler("random", self._CLIP_DURATION),
        transform = train_transform
    )

    return torch.utils.data.DataLoader(
        train_dataset,
        batch_size = self._BATCH_SIZE,
        num_workers = self._NUM_WORKERS,
    )


  def val_dataloader(self):

    val_dataset = pytorchvideo.data.ucf101(
        data_path = os.path.join(dataset_root_path, "val"),
        clip_sampler = pytorchvideo.data.make_clip_sampler("uniform", self._CLIP_DURATION),
        decode_audio = False,
        transform = val_transform
    )

    return torch.utils.data.DataLoader(
        val_dataset,
        batch_size = self._BATCH_SIZE,
        num_workers = self._NUM_WORKERS
    )

  def test_dataloader(self):

    test_dataset = pytorchvideo.data.ucf101(
        data_path = os.path.join(dataset_root_path, "test"),
        clip_sampler = pytorchvideo.data.make_clip_sampler("uniform", self._CLIP_DURATION),
        decode_audio = False,
        transform = val_transform 
    )

    return torch.utils.data.DataLoader(
        test_dataset,
        batch_size = self._BATCH_SIZE,
        num_workers = self._NUM_WORKERS
    )
def train():
  classification_module = VideoClassificationLightningModule()
  data_module = UCFDataModule()
  trainer = pytorch_lightning.Trainer()
  trainer.fit(classification_module, data_module)
  pdb.set_trace()
train()
INFO:pytorch_lightning.utilities.rank_zero:GPU available: False, used: False
INFO:pytorch_lightning.utilities.rank_zero:TPU available: False, using: 0 TPU cores
INFO:pytorch_lightning.utilities.rank_zero:IPU available: False, using: 0 IPUs
INFO:pytorch_lightning.utilities.rank_zero:HPU available: False, using: 0 HPUs
/usr/local/lib/python3.10/dist-packages/pytorch_lightning/loops/utilities.py:70: PossibleUserWarning: `max_epochs` was not set. Setting it to 1000 epochs. To train without an epoch limit, set `max_epochs=-1`.
  rank_zero_warn(
WARNING:pytorch_lightning.loggers.tensorboard:Missing logger folder: /content/lightning_logs
INFO:pytorch_lightning.callbacks.model_summary:
  | Name  | Type | Params
-------------------------------
0 | model | Net  | 31.7 M
-------------------------------
31.7 M    Trainable params
0         Non-trainable params
31.7 M    Total params
126.695   Total estimated model params size (MB)
Sanity Checking:
0/? [00:00<?, ?it/s]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-ff9f91c35b9e> in <cell line: 1>()
----> 1 train_results = train()

13 frames
<ipython-input-11-c166a5edf011> in val_dataloader(self)
     22   def val_dataloader(self):
     23 
---> 24     val_dataset = pytorchvideo.data.ucf101(
     25         data_path = os.path.join(dataset_root_path, "val"),
     26         clip_sampler = pytorchvideo.data.make_clip_sampler("uniform", self._CLIP_DURATION),

TypeError: 'module' object is not callable

Solution

  • ucf101 is a module I think you want to use Ucf101 class you can directly use it from pytorchvideo.data or you can import it from pytorchvideo.data.ucf101.

    So your final code will look like this

    test_dataset = pytorchvideo.data.Ucf101(
            data_path = os.path.join(dataset_root_path, "test"),
            clip_sampler = pytorchvideo.data.make_clip_sampler(
                             "uniform", self._CLIP_DURATION
                           ),
            decode_audio = False,
            transform = val_transform 
    )