1、判断tensor是否为空
tensor_name=torch.Tensor()
print(len(tensor_name) is 0)
- 1
- 2
2、判断是否在gpu上
tensor_name=torch.Tensor()
tensor_name.is_cuda
- 1
- 2
3、图像通道变换
由于读取到的图像是W*H*C
的格式,但是在输入网络的时候要求是C * W * H
,因此在输入网络之前需要变换通道,通常采用transpose函数实现:
tensor_name=torch.Tensor()
tensor_name_t = tensor_name.transpose(2, 0, 1)
- 1
- 2
4、nelement()
pytorch中的 nelement() 可以统计 tensor (张量)中 元素的个数。
import torch
x = torch.randn(size = (4,3,5,6))
print(x.nelement())
- 1
- 2
- 3
结果是:
4*3*5*6
pytorch使用GPU
(1条消息) pytorch使用GPU_pyxiea-CSDN博客
Last、参考文献
pytorch判断是否cuda 判断变量类型_jacke121的专栏-CSDN博客
pytorch:读取的图像变换通道_xddwz的博客-CSDN博客
转换
PIL数据和numpy数据的相互转换 - niudong - 博客园
Pytorch中的variable, tensor与numpy相互转化的方法_pengge0433的博客-CSDN博客
python3 list, np.array, torch.tensor相互转换_黑白德芙Sani的博客-CSDN博客
将一个np.array转换为tensor_HYQ的博客-CSDN博客
PIL中的Image和numpy中的数组array相互转换 - 龚细军 - 博客园
Python PIL.Image与numpy.array之间的相互转换 - 知乎
PIL.Image和np.ndarray图片与Tensor之间的转换_tsq292978891的博客-CSDN博客_tensor转pil
Pytorch中的variable, tensor与numpy相互转化的方法_pengge0433的博客-CSDN博客
pytorch: tensor类型的构建与相互转换_JNing-CSDN博客
Numpy数据类型转换astype,dtype_Aurora Silent-CSDN博客_numpy类型转换
[numpy] adarray.dtype 查看数据类型_doufuxixi的博客-CSDN博客
不同方法读取图片转换成tensor
pythoncv读取3通道_Pytorch读取,加载图像数据(一)_冲田的小娇妻的博客-CSDN博客
PyTorch踩过的坑
其他
torch.backends.cudnn.benchmark ?! - 知乎
PyTorch的初始化 - 知乎
Multiprocessing best practices — PyTorch 1.7.1 documentation
increase pytorch shared memory | Data Science and Machine Learning | Kaggle
???Getting Started with PyTorch??? | Kaggle
NumPy array is not writeable
Spurious “NumPy array is not writeable” warning on torch.tensor(np_array)
· Issue #47160 · pytorch/pytorch · GitHub
UserWarning: The given NumPy array is not writeable - PyTorch Forums
UserWarning: The given NumPy array is not writeable - PyTorch Forums
Float PILImage not converted as writeable · Issue #2194 · pytorch/vision · GitHub
Object arrays cannot be loaded when allow_pickle=False
Python解決Object arrays cannot be loaded when allow_pickle=False @ K_程式人 :: 痞客邦 ::
评论记录:
回复评论: