Data processing with numpy or pytorch

Numpy

Numpy从数值范围创建数组:arange()、linspace()、logsapce()

  • numpy.arange(start=0, stop, step=1, dtype): start 与 stop 指定的范围以及 step 设定的步长,生成一个 ndarray,不包含stop值;
  • np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): 创建一个等差数列构成的一维数组,num为样本量;
  • np.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None): 创建一个等比数列构成的一维数组,base为底;

Pytorch

pytorch中torch.view()、squeeze()、unsqueeze()、max()

numel()
permute()
tqdm fire 网络参数初始化问题 meshgrid() stack ravel np.newaxis where astype()

numpy.prob()连乘 assert

a.shape=(1,4,4) a[:,:,0::4].shape=(1,4,1) 而a[:,:,0].shape=(1,4)

if set model.eval() ——> model.training = Flase

python类方法中使用:修饰符@staticmethod和@classmethod的作用与区别,还有装饰器@property的使用

PyTorch之前向传播函数forward

open.cv读入图片的尺寸是(H,W,C)

Input type(torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be he same:::原因可能是model放进了GPU而输入数据没有放到GPU。

expected object of backend CPU but got backend CUDA for sequence element 1 in sequence argument at position #1 ‘tensors’:CUDA与CPU的数据不能混在一起运算,不会自由转换,

when set model.eval(), self.training/model.training = False?

ValueError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.

------ 本文结束 ------