Pytorch报错|UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writ
完整错误如下:
/data/home/file_name/.conda/envs/cmr/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py:63: 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/opt/conda/conda-bld/pytorch_1603729006826/work/torch/csrc/utils/tensor_numpy.cpp:141.)return default_collate([torch.as_tensor(b).copy() for b in batch]) 翻译一下:
给定的NumPy数组不可写,PyTorch不支持不可写张量 。这意味着您可以使用张量写入底层(假定不可写)NumPy数组 。在将数组转换为张量之前,可能需要复制数组以保护其数据或使其可写 。 解决办法:
根据
/data/home/file_name/.conda/envs/cmr/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py:63 找到第63行进行修改:
【Pytorch报错|UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writ】# 将return default_collate([torch.as_tensor(b) for b in batch])# 修改为return default_collate([torch.as_tensor(b.copy()) for b in batch]) 问题解决!
- 春季老年人吃什么养肝?土豆、米饭换着吃
- 三八妇女节节日祝福分享 三八妇女节节日语录
- 老人谨慎!选好你的“第三只脚”
- 校方进行了深刻的反思 青岛一大学生坠亡校方整改校规
- 脸皮厚的人长寿!有这特征的老人最长寿
- 长寿秘诀:记住这10大妙招 100%增寿
- 春季老年人心血管病高发 3条保命要诀
- 眼睛花不花要看四十八 老年人怎样延缓老花眼
- 香槟然能防治老年痴呆症? 一天三杯它人到90不痴呆
- 老人手抖的原因 为什么老人手会抖
