Skip to content

Conversation

yoshitomo-matsubara
Copy link
Contributor

@yoshitomo-matsubara yoshitomo-matsubara commented Oct 25, 2020

Hi!

Thank you for the reference code for segmentation tasks!

Recently I noticed so many UserWarning messages due to some transform implementation, and also thought its args needs little bit more flexibility like those in reference code for other tasks e.g., train.py for image classification and object detection

Summary of changes:

  1. np.asarray in ToTensor (implemented in reference code) was replaced with np.array in order to avoid repeated UserWarning messages
  2. data-path was added to args in train.py for segmentation, following the style of train.py for classification and detection as mentioned above

Versions:

  • Python 3.6.9 (on Ubuntu 18.04.4 LTS)
  • torch==1.6.0
  • torchvision==0.7.0
  • numpy==1.19.2

FYI, the following log shows repeated UserWarning to be fixed

$ python train.py --dataset coco --test-only
Not using distributed mode
Namespace(aux_loss=False, batch_size=8, dataset='coco', device='cuda', dist_url='env://', distributed=False, epochs=30, lr=0.01, model='fcn_resnet101', momentum=0.9, output_dir='.', pretrained=False, print_freq=10, resume='', start_epoch=0, test_only=True, weight_decay=0.0001, workers=16, world_size=1)
loading annotations into memory...
Done (t=10.96s)
creating index...
index created!
loading annotations into memory...
Done (t=0.39s)
creating index...
index created!
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
/home/yoshitom/tmp/vision/references/segmentation/transforms.py:81: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
  target = torch.as_tensor(np.asarray(target), dtype=torch.int64)
Test:  [   0/5000]  eta: 2:00:19    time: 1.4438  data: 1.3482  max mem: 382

Thank you!

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fmassa fmassa merged commit ff538ac into pytorch:master Oct 26, 2020
bryant1410 pushed a commit to bryant1410/vision-1 that referenced this pull request Nov 22, 2020
…or segmentation tasks (pytorch#2886)

* add a README for training object detection models

* replaced np.asarray with np.array to avoid warning messages

* added data-path for flexibility

* fixed a typo
vfdev-5 pushed a commit to Quansight/vision that referenced this pull request Dec 4, 2020
…or segmentation tasks (pytorch#2886)

* add a README for training object detection models

* replaced np.asarray with np.array to avoid warning messages

* added data-path for flexibility

* fixed a typo
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

Successfully merging this pull request may close these issues.

2 participants