学习中遇到各种小知识点(不断更新)

Shoelace公式

Shoelace公式,也叫高斯面积公式,俗称鞋带公式。根据按时针顺序的顶点坐标可求确定区域内多边形的面积。公式为:
在这里插入图片描述
当X的下标大于n时:Xn+1=X1,Yn+1=Y1。并且当点顺为顺时针时,面积为负,点顺序为逆时针时。面积为正。利用这个公式来判断文本框的输入四个点的顺序,使其均为逆时针,并且筛选掉面积太小的框

#Shoelace公式
def polygon_area(poly):
    '''
    compute area of a polygon
    '''
    edge = [
        (poly[1][0] - poly[0][0]) * (poly[1][1] + poly[0][1]),
        (poly[2][0] - poly[1][0]) * (poly[2][1] + poly[1][1]),
        (poly[3][0] - poly[2][0]) * (poly[3][1] + poly[2][1]),
        (poly[0][0] - poly[3][0]) * (poly[0][1] + poly[3][1])
    ]
    return np.sum(edge) / 2.


def check_and_validate_polys(polys, tags, xxx_todo_changeme):
    '''
    check so that the text poly is in the same direction,
    and also filter some invalid polygons
    :param polys:
    :param tags:
    :return:
    '''
    (h, w) = xxx_todo_changeme
    if polys.shape[0] == 0:
        return polys
    polys[:, :, 0] = np.clip(polys[:, :, 0], 0, w - 1)
    polys[:, :, 1] = np.clip(polys[:, :, 1], 0, h - 1)

    validated_polys = []
    validated_tags = []
    for poly, tag in zip(polys, tags):
        p_area = polygon_area(poly)
        if abs(p_area) < 1:
            # print poly
            print('invalid poly')
            continue
        if p_area > 0:
            print('poly in wrong direction')
            poly = poly[(0, 3, 2, 1), :]
        validated_polys.append(poly)
        validated_tags.append(tag)
    return np.array(validated_polys), np.array(validated_tags)

图片去均值

1.是什么,均值分为图像均值和像素均值,图像均值是指,对训练集所有图片同一空间位置的像素值求均值,像素均值是指,对训练集所有图像的R,G和B通道求均值。
2.为什么,类似于数据归一化,为了防止梯度爆炸,所以对图片也要进行“归一化”。
3.怎么做,直接用图片各通道的原像素值减去均值:

def __mean_image_subtraction(self, images, means = [123.68, 116.78, 103.94]):
      '''
      image normalization,subtract the mean of every channel
      :param images: bathsize *channnel* w * h 
      '''
      num_channels = images.data.shape[1]
      if len(means) != num_channels:
          raise ValueError('len(means) must match the number of channels')
      for i in range(num_channels):
          images.data[:, i, :, :] -= means[i]

      return images

self.modules() 和 self.children()

在初始化参数时,可以利用这两个函数。
对于这样一个网络:
在这里插入图片描述
self.children()存储网络结构的子层模块,也就是net’s children那一层
self.modules()采用深度优先遍历的方式,存储了net的所有模块,包括net itself,net’s children, children of net’s children。

#initialization
for m in self.modules():
    if isinstance(m, nn.Conv2d):
        m.weight.data.normal_().fmod_(2).mul_(0.01).add_(0)
        #init.xavier_uniform_(m.weight.data)
    elif isinstance(m, nn.BatchNorm2d):
        m.weight.data.fill_(1)
        m.bias.data.zero_()
    elif isinstance(m, nn.Linear):
        init.xavier_uniform_(m.weight.data)
        m.bias.data.zero_()

参考网址:https://blog.csdn.net/dss_dssssd/article/details/83958518
PS:对于named_children()和named_modules()函数,同上图,前者返回net’s children的layer名,后者返回所有模块的名字。

OCR领域的一些名词解释

RPN(RegionProposal Network):区域生成网络
Seq2Seq:一般通过Encoder-Decoder(编码-解码)框架实现从序列到序列的转换。
CTC(Connectionist Temporal Classification):decoder不知道输入输出是否对齐的情况使用的算法
FPN(feature pyramid networks):多尺度的object detection算法
OHEM(Online Hard Example Mining):自动地选择 had negative 来进行训练
RoI(Region of interest):图片中认为有存在目标的区域
dropout:防止过拟合,我们在前向传播的时候,让某个神经元的激活值以一定的概率p停止工作,这样可以使模型泛化性更强,因为它不会太依赖某些局部的特征。
concat和add:concat是通道数的增加;add是特征图相加,通道数不变
ICDAR:(International Conference on Document Analysis and Recognition)国际文档分析和识别大会

在使用router-link标签进行路由跳转时,可以通过query参数来传递参数。你可以在:to属性指定要跳转的路径,例如path:'/resourceInfo',然后在query以键值对的方式添加要传递的参数。例如,如果要传递resourceId参数,可以这样写:<router-link :to="{path:'/resourceInfo',query:{resourceId:o.resourceId}}"> //里面写你包裹的元素 </router-link>。在接收参数的页面,你可以通过this.$route.query来获取传递的参数。例如,在created()生命周期钩子可以使用this.resourceId = this.$route.query.resourceId来获取resourceId参数的值。\[1\] 在Angular,使用routerLink属性进行路由跳转时,可以通过queryParams参数来传递参数。例如,如果要传递id参数,可以这样写:<a \[routerLink\]="\['/product'\]" \[queryParams\]="{id:1}">详情</a>。在接收参数的组件,可以通过ActivatedRoute来获取参数的值。例如,在ngOnInit()生命周期钩子,可以使用this.routeInfo.snapshot.params\['id'\]来获取id参数的值。另外,也可以使用this.routeInfo.params.subscribe()方法来订阅参数的变化,并在回调函数获取参数的值。\[2\]\[3\] #### 引用[.reference_title] - *1* [vue使用router-link跳转时传递参数](https://blog.csdn.net/Yanzudada/article/details/105978653)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Angualr routerLink 两种传参方法及参数的使用](https://blog.csdn.net/qq_29483485/article/details/81513013)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值