Search code examples
pythondeep-learningpytorchlstmpytorch-lightning

ValueError in trainer.fit()


I have encountered ValueError: No positive samples in targets, true positive value should be meaningless when I tried to run trainer.fit(model, dataset) for my model, but I've double checked dataset and all of the train/val/test sets had proper number of positive samples. Why would this occur and where should I start to fix this issue? Thanks!


Solution

  • Before the training loop actually starts, PL trainer will run a sanity check of validation loop for two steps. In that case, these two steps may only have one type of label (negative or positive) and crash your metrics.

    Turn it off by setting num_sanity_val_steps=0 in your trainer.

    https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#num-sanity-val-steps