PrepareNS_coco_24net.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:mlstudy_week7 作者: ByungKeon-Ko 项目源码 文件源码
def create_ns (tmp_imgpath, cnt_ns, network_list, threshold1, threshold2 ) :

    tmp_img = Image.open("%s/%s" %(coco_path, tmp_imgpath), 'r' )
    org_img = Image.open("%s/%s" %(coco_path, tmp_imgpath), 'r' )

    down_scale = 1
    if (max(tmp_img.size[0], tmp_img.size[1]) > 3000) :
        down_scale = 6
    elif (max(tmp_img.size[0], tmp_img.size[1]) > 2500) :
        down_scale = 5
    elif (max(tmp_img.size[0], tmp_img.size[1]) > 2000) :
        down_scale = 4
    elif (max(tmp_img.size[0], tmp_img.size[1]) > 1500) :
        down_scale = 3
    elif (max(tmp_img.size[0], tmp_img.size[1]) > 1000) :
        down_scale = 2
    elif (max(tmp_img.size[0], tmp_img.size[1]) > 750) :
        down_scale = 1.5
    size = tmp_img.size

    resize_ratio = float(MinFace)/ 12. * down_scale
    try :
        tmp_img = tmp_img.resize( (int(size[0]/resize_ratio), int(size[1]/resize_ratio)), Image.BILINEAR )
    except IOError :
        sys.exit("truncated byte error!")

    false_pos_annot = image_search.detect_pos(network_list, tmp_img, threshold1, threshold2, 'aflw', resize_ratio )

    if len(false_pos_annot) <= 0 :
        return 0

    # if type(false_pos_annot)==list :
    #   false_pos_annot = image_search.apply_nms( false_pos_annot )
    # else :
    #   false_pos_annot = image_search.apply_nms( false_pos_annot.tolist() )

    # image_search.save_annot(false_pos_annot)
    cnt_save = 0
    for j in xrange( len(false_pos_annot) ) :
        if net_name == '24net' :
            path = "%s/NS_det24_2/ns-%d.jpg" %(base_path, cnt_ns+cnt_save)
            org_img = org_img.convert('RGB')
            image_search.save_patch(org_img, false_pos_annot[j], path, net_name)
            cnt_save = cnt_save + 1

        elif net_name == '48net' :
            path = "%s/NS_det48_2/ns-%d.jpg" %(base_path, cnt_ns+cnt_save)
            org_img = org_img.convert('RGB')
            image_search.save_patch(org_img, false_pos_annot[j], path, net_name)
            cnt_save = cnt_save + 1

    return cnt_save

# -----------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号