Notes about generating mask from coco

https://forums.fast.ai/t/image-segmentation-on-coco-dataset-summary-questions-and-suggestions/36816/3

I created this function that can remove from IMG_PATH all files which are not listed in annotation file (to avoid error in databunch) for existing annotations it creates the imageMask:

# lbl_names = get_image_files(pathmask_train)
# #lbl_names[:3]
CATEGORY_NAMES=['row']
ANNOTATION_FILE=ROOT_PATH+'allrows/train.json'#其实也是pathmask_train的str格式,为方便与资料网站对应
#ANNOTATION_FILE



coco = coco.COCO(ANNOTATION_FILE)
#coco
catIds = coco.getCatIds(catNms=CATEGORY_NAMES);
imgIds = coco.getImgIds(catIds=catIds);
imgDict = coco.loadImgs(imgIds)
len(imgIds) , len(catIds)

imgDF = pd.DataFrame.from_dict(imgDict)
#imgDF[:3]
def dataPreparation():
    deleted = 0
    processed = 0
    imgCounter = 0
    for f in listdir(IMG_PATH):
        imgCounter = imgCounter + 1
        if(imgCounter == IMG_COUNT_LIMIT):
            break
        df = imgDF[imgDF['file_name']==f]
        if(df.empty):
          #print("delete file: "+f)
            os.remove(IMG_PATH/f) 
            deleted = deleted + 1
        else:
            createImageForMask(f)
            processed = processed + 1
    print('deleted '+str(deleted)+' files')
    print('processed '+str(processed)+' files')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值