Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training from scratch fails #21

Open
b-hakim opened this issue Sep 18, 2020 · 3 comments
Open

Training from scratch fails #21

b-hakim opened this issue Sep 18, 2020 · 3 comments

Comments

@b-hakim
Copy link

b-hakim commented Sep 18, 2020

I am having this issue when running training from scratch

Traceback (most recent call last):
  File "train.py", line 101, in <module>
    main(config, args.resume)
  File "train.py", line 55, in main
    trainer.train()
  File "/path/Human-Segmentation-PyTorch/base/base_trainer.py", line 95, in train
    result = self._train_epoch(epoch)
  File "/path/Human-Segmentation-PyTorch/trainer/trainer.py", line 81, in _train_epoch
    loss = self.loss(output, target)
  File "/path/Human-Segmentation-PyTorch/evaluation/losses.py", line 18, in dice_loss
    targets = torch.zeros_like(logits).scatter_(dim=1, index=targets.type(torch.int64), src=torch.tensor(1.0))
RuntimeError: Index tensor must have the same number of dimensions as src tensor

I guess I might have an issue in the dataset labeling. What is the correct format? I used an image of the same size for the original image and have 1 channel (I have 2 classes), so that is a mask of 1 channel containing 0 and 1 (or 0 and 255)

@FrankChengGD
Copy link

I changed that line to

targets = torch.zeros_like(logits).scatter_(dim=1, index=targets.type(torch.int64), src=torch.ones_like(logits))

in order to make the index and src in same size. It seems work for me.

I am having this issue when running training from scratch

Traceback (most recent call last):
  File "train.py", line 101, in <module>
    main(config, args.resume)
  File "train.py", line 55, in main
    trainer.train()
  File "/path/Human-Segmentation-PyTorch/base/base_trainer.py", line 95, in train
    result = self._train_epoch(epoch)
  File "/path/Human-Segmentation-PyTorch/trainer/trainer.py", line 81, in _train_epoch
    loss = self.loss(output, target)
  File "/path/Human-Segmentation-PyTorch/evaluation/losses.py", line 18, in dice_loss
    targets = torch.zeros_like(logits).scatter_(dim=1, index=targets.type(torch.int64), src=torch.tensor(1.0))
RuntimeError: Index tensor must have the same number of dimensions as src tensor

I guess I might have an issue in the dataset labeling. What is the correct format? I used an image of the same size for the original image and have 1 channel (I have 2 classes), so that is a mask of 1 channel containing 0 and 1 (or 0 and 255)

@HettieLi
Copy link

I am having this issue when running training from scratch

Traceback (most recent call last):
  File "train.py", line 101, in <module>
    main(config, args.resume)
  File "train.py", line 55, in main
    trainer.train()
  File "/path/Human-Segmentation-PyTorch/base/base_trainer.py", line 95, in train
    result = self._train_epoch(epoch)
  File "/path/Human-Segmentation-PyTorch/trainer/trainer.py", line 81, in _train_epoch
    loss = self.loss(output, target)
  File "/path/Human-Segmentation-PyTorch/evaluation/losses.py", line 18, in dice_loss
    targets = torch.zeros_like(logits).scatter_(dim=1, index=targets.type(torch.int64), src=torch.tensor(1.0))
RuntimeError: Index tensor must have the same number of dimensions as src tensor

I guess I might have an issue in the dataset labeling. What is the correct format? I used an image of the same size for the original image and have 1 channel (I have 2 classes), so that is a mask of 1 channel containing 0 and 1 (or 0 and 255)

I have the same problem as you. Try to use command 'pip install torch==1.2.0' and 'torchvision==0.4.0' to solve it.

@XXMxxm220
Copy link

type(torch.int64)

你好,我尝试更改为你的代码,但报错 inter = (outputs & targets).type(torch.float32).sum(dim=(2,3))
RuntimeError: "bitwise_and_cuda" not implemented for 'Float'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants