生吃代码学到的一点东西-1

numpy

  1. scatter_(input, dim, index, src)将src中数据根据index中的索引按照dim的方向填进input中.

  2. numpy.clip(a, a_min, a_max, out=None) 将array a的值限制在a_min, a_max两个数之间

  3. np.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation=‘linear’, keepdims=False) 百分位数是统计中使用的度量,表示小于这个值的观察值的百分比。

  4. numpy.repeat()重复

    np.repeat(3, 4)
    #array([3, 3, 3, 3])
    x = np.array([[1,2],[3,4]])
    np.repeat(x, 2)
    #array([1, 1, 2, 2, 3, 3, 4, 4])
    np.repeat(x, 3, axis=1)
    #array([[1, 1, 1, 2, 2, 2],
    #       [3, 3, 3, 4, 4, 4]])
    np.repeat(x, [1, 2], axis=0)
    #array([[1, 2],
    #       [3, 4],
    #       [3, 4]])
    
  5. np.linspace() 用于在线性空间中以均匀步长生成数字序列。 第一个参数是开头,第二个参数是结尾,第三个参数是多少步。

skimage

  1. skimage.restoration.denoise_bilateral(image, win_size=None, sigma_color=None, sigma_spatial=1, bins=10000, mode=‘constant’, cval=0, multichannel=None, sigma_range=None) 使用双边滤波器去噪图像。

pytorch

  1. torch.load()加载模型

  2. model.eval ()使得所有层进入评估模式,非训练模式

  3. model.cuda()模型加载到gpu

  4. transform.compose()把两个操作合并在一起

  5. transform.ToTensor()#把H,W,C转为C,H,W

  6. torch.unqueeze()返回一个新的张量,在指定位置插入一个大小为1的维度。返回的张量与该张量共享相同的基础数据。

    x = torch.tensor([1, 2, 3, 4])
    torch.unsqueeze(x, 0)
    #tensor([[ 1,  2,  3,  4]])
    torch.unsqueeze(x, 1)
    #tensor([[ 1],
    #        [ 2],
    #        [ 3],
    #        [ 4]])
    
  7. torch.cat(inputs, dimension=0) → Tensor 在给定维度上对输入的张量序列seq 进行连接操作。

    >>> x = torch.randn(2, 3)
    >>> x
    
     0.5983 -0.0341  2.4918
     1.5981 -0.5265 -0.8735
    [torch.FloatTensor of size 2x3]
    
    >>> torch.cat((x, x, x), 0)
    
     0.5983 -0.0341  2.4918
     1.5981 -0.5265 -0.8735
     0.5983 -0.0341  2.4918
     1.5981 -0.5265 -0.8735
     0.5983 -0.0341  2.4918
     1.5981 -0.5265 -0.8735
    [torch.FloatTensor of size 6x3]
    
    >>> torch.cat((x, x, x), 1)
    
     0.5983 -0.0341  2.4918  0.5983 -0.0341  2.4918  0.5983 -0.0341  2.4918
     1.5981 -0.5265 -0.8735  1.5981 -0.5265 -0.8735  1.5981 -0.5265 -0.8735
    [torch.FloatTensor of size 2x9]
    
    
    
  8. outputs = torch.stack(inputs, dim=0) → Tensor 增加新的维度进行堆叠

  9. torch.permute()转置

  10. torch.view()相当于numpy的resize()

  11. torch.repeat(n1,n2,n3,n4),第1维、第2维、第3维、第4维的重复次数

  12. torch.detach() 克隆,但将计算图脱离出来,就是两个分开。

MoviePy

  1. ImageSequenceClip图片创建视频
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值