91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類(lèi)型: .py
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-16
  • 語(yǔ)言: Python
  • 標(biāo)簽: COCO??labelme??Mask-Rcnn??caffe2??

資源簡(jiǎn)介

labelme標(biāo)注數(shù)據(jù)集到COCO格式數(shù)據(jù)集轉(zhuǎn)化,用于官方版Mask-Rcnn訓(xùn)練

資源截圖

代碼片段和文件信息

#?-*-?coding:utf-8?-*-
#?!/usr/bin/env?python

import?argparse
import?json
import?matplotlib.pyplot?as?plt
import?skimage.io?as?io
import?cv2
from?labelme?import?utils
import?numpy?as?np
import?glob
import?PIL.Image
from?shapely.geometry?import?Polygon

class?labelme2coco(object):
????def?__init__(selflabelme_json=[]save_json_path=‘./new.json‘):
????????‘‘‘
????????:param?labelme_json:?所有l(wèi)abelme的json文件路徑組成的列表
????????:param?save_json_path:?json保存位置
????????‘‘‘
????????self.labelme_json=labelme_json
????????self.save_json_path=save_json_path
????????self.images=[]
????????self.categories=[]
????????self.annotations=[]
????????#?self.data_coco?=?{}
????????self.label=[]
????????self.annID=1
????????self.height=0
????????self.width=0

????????self.save_json()

????def?data_transfer(self):
????????for?numjson_file?in?enumerate(self.labelme_json):
????????????with?open(json_file‘r‘)?as?fp:
????????????????data?=?json.load(fp)??#?加載json文件
????????????????self.images.append(self.image(datanum))
????????????????for?shapes?in?data[‘shapes‘]:
????????????????????#label=shapes[‘label‘].split(‘_‘)
????????????????????label=shapes[‘label‘][:-1]
????????????????????print(shapes[‘label‘])
????????????????????print(label)
????????????????????if?label?not?in?self.label:
????????????????????????self.categories.append(self.categorie(label))
????????????????????????self.label.append(label)
????????????????????points=shapes[‘points‘]
????????????????????self.annotations.append(self.annotation(pointslabelnum))
????????????????????self.annID+=1
????????print(self.label)

????def?image(selfdatanum):
????????image={}
????????img?=?utils.img_b64_to_array(data[‘imageData‘])??#?解析原圖片數(shù)據(jù)
????????#?img=io.imread(data[‘imagePath‘])?#?通過(guò)圖片路徑打開(kāi)圖片
????????#?img?=?cv2.imread(data[‘imagePath‘]?0)
????????height?width?=?img.shape[:2]
????????img?=?None
????????image[‘height‘]=height
????????image[‘width‘]?=?width
????????image[‘id‘]=num+1
????????image[‘file_name‘]?=?data[‘imagePath‘].split(‘/‘)[-1]

????????self.height=height
????????self.width=width

????????return?image

????def?categorie(selflabel):
????????categorie={}
????????categorie[‘supercategory‘]?=?label
????????categorie[‘id‘]=len(self.label)+1?#?0?默認(rèn)為背景
????????categorie[‘name‘]?=?label
????????return?categorie

????def?annotation(selfpointslabelnum):
????????annotation={}
????????annotation[‘segmentation‘]=[list(np.asarray(points).flatten())]
????????poly?=?Polygon(points)
????????area_?=?round(poly.area6)
????????annotation[‘a(chǎn)rea‘]?=?area_
????????annotation[‘iscrowd‘]?=?0
????????annotation[‘imag

評(píng)論

共有 條評(píng)論