10

I am training yolov3 on my data using this code here : https://github.com/cfotache/pytorch_custom_yolo_training/

But I am getting this annoying deprecation warnings

Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead. (expandTensors at /pytorch/aten/src/ATen/native/IndexingUtils.h:20)

I tried using python3 -W ignore train.py I tried adding :

import warnings
warnings.filterwarnings('ignore')

but the warning is still persistent.

I found this piece of code on here on stackoverflow that prints that stack on warnings ,

import traceback
import warnings
import sys

def warn_with_traceback(message, category, filename, lineno, file=None, line=None):

    log = file if hasattr(file,'write') else sys.stderr
    traceback.print_stack(file=log)
    log.write(warnings.formatwarning(message, category, filename, lineno, line))

warnings.showwarning = warn_with_traceback

and here's what I get :

  File "/content/pytorch_custom_yolo_training/train.py", line 102, in <module>
   loss = model(imgs, targets)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/pytorch_custom_yolo_training/models.py", line 267, in forward
    x, *losses = module[0](x, targets)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/pytorch_custom_yolo_training/models.py", line 203, in forward
    loss_x = self.mse_loss(x[mask], tx[mask])
  File "/usr/lib/python3.6/warnings.py", line 99, in _showwarnmsg
    msg.file, msg.line)
  File "/content/pytorch_custom_yolo_training/train.py", line 29, in warn_with_traceback
    traceback.print_stack(file=log)
  /pytorch/aten/src/ATen/native/IndexingUtils.h:20: UserWarning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead.

Going to the files and functions mentioned in the stack , I don't find any uint8 . What can I to solve the problem or even stop getting these warnings ?

3 Answers3

10

Found the problem. line : loss_x = self.mse_loss(x[mask], tx[mask]) the mask variable was a ByteTensor which is deprecated . Just replaced it with a BoolTensor

0

This works for my case: Add

obj_mask = obj_mask.type(torch.BoolTensor)
noobj_mask = noobj_mask.type(torch.BoolTensor)

before

loss_x = self.mse_loss(x[obj_mask], tx[obj_mask])

in in models.py.

  • Please don't add _"thanks"_ as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Once you [earn](https://meta.stackoverflow.com/q/146472) enough [reputation](/help/whats-reputation), you will gain privileges to [upvote answers](/help/privileges/vote-up) you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See [Why is voting important](/help/why-vote). – Yunnosch Sep 29 '20 at 06:10
0

This works Fine

obj_mask = obj_mask.bool()
noobj_mask = noobj_mask.bool()
Prajot Kuvalekar
  • 5,128
  • 3
  • 21
  • 32