96SEO 2026-02-19 22:48 11
如下是labelme官方网址#xff0c;提供了源代码#xff0c;以及相关使用方…这里主要是搬运一下能找到的

labelme标注的json文件数据转成coco数据集格式可处理目标框和实例分割的代码以供需要时参考和提供相关帮助。
如下是labelme官方网址提供了源代码以及相关使用方法包括数据集格式转换要仔细了解的可以细看。
网址https://github.com/wkentaro/labelme
如果自己使用后有其他可改进的想法可以尝试看源码修改增加相关功能
可以看到相关工作的介绍里面提供了把实例分割标注文件转成COCO格式的功能。
网址https://github.com/wkentaro/labelme/tree/main/examples/instance_segmentation
转成coco数据集格式的代码可以包含水平框和实例分割的目标轮廓代码如下
argparse.ArgumentParser(formatter_classargparse.ArgumentDefaultsHelpFormatter)parser.add_argument(input_dir,
directory)parser.add_argument(output_dir,
directory)parser.add_argument(--labels,
requiredTrue)parser.add_argument(--noviz,
osp.exists(args.output_dir):print(Output
args.output_dir)sys.exit(1)os.makedirs(args.output_dir)os.makedirs(osp.join(args.output_dir,
args.noviz:os.makedirs(osp.join(args.output_dir,
dict(infodict(descriptionNone,urlNone,versionNone,yearnow.year,contributorNone,date_creatednow.strftime(%Y-%m-%d
%H:%M:%S.%f),),licenses[dict(urlNone,
id],typeinstances,annotations[#
enumerate(open(args.labels).readlines()):class_id
__ignore__continueclass_name_to_id[class_name]
class_iddata[categories].append(dict(supercategoryNone,
glob.glob(osp.join(args.input_dir,
enumerate(label_files):print(Generating
labelme.LabelFile(filenamefilename)base
osp.splitext(osp.basename(filename))[0]out_img_file
labelme.utils.img_data_to_arr(label_file.imageData)imgviz.io.imsave(out_img_file,
img)data[images].append(dict(license0,urlNone,file_nameosp.relpath(out_img_file,
osp.dirname(out_ann_file)),heightimg.shape[0],widthimg.shape[1],date_capturedNone,idimage_id,))masks
labelme.utils.shape_to_mask(img.shape[:2],
np.asarray(points).flatten().tolist()segmentations[instance].append(points)segmentations
class_name_to_id:continuecls_id
np.asfortranarray(mask.astype(np.uint8))mask
pycocotools.mask.encode(mask)area
float(pycocotools.mask.area(mask))bbox
pycocotools.mask.toBbox(mask).flatten().tolist()data[annotations].append(dict(idlen(data[annotations]),image_idimage_id,category_idcls_id,segmentationsegmentations[instance],areaarea,bboxbbox,iscrowd0,))if
imgviz.instances2rgb(imageimg,labelslabels,masksmasks,captionscaptions,font_size15,line_width2,)out_viz_file
.jpg)imgviz.io.imsave(out_viz_file,
__main__:main()代码执行需要导入相关库缺少相关库自行下载安装。
然后是看代码执行命令
data_dataset_coco/annotations.json2、其他代码实现
save_json_path./coco.json)::param
labelme_jsonself.save_json_path
enumerate(self.labelme_json):with
json.load(fp)self.images.append(self.image(data,
self.label:self.label.append(label)points
shapes[points]self.annotations.append(self.annotation(points,
self.label:self.categories.append(self.category(label))for
self.annotations:annotation[category_id]
self.getcatid(annotation[category_id])def
utils.img_b64_to_arr(data[imageData])height,
data[imagePath].split(/)[-1]self.height
len(self.categories)category[name]
[list(np.asarray(points).flatten())]annotation[iscrowd]
self.getbbox(points)))annotation[category_id]
self.getcatid(label)annotation[id]
self.polygons_to_mask([self.height,
[left_top_c,left_top_r,right_bottom_c
polygons))PIL.ImageDraw.Draw(mask).polygon(xyxy,
self.imagesdata_coco[categories]
self.categoriesdata_coco[annotations]
json)self.data_transfer()self.data_coco
self.data2coco()print(self.save_json_path)os.makedirs(os.path.dirname(os.path.abspath(self.save_json_path)),
exist_okTrue)json.dump(self.data_coco,
argparse.ArgumentParser(descriptionlabelme
file.)parser.add_argument(labelme_images,helpDirectory
files.,typestr,)parser.add_argument(--output,
parser.parse_args()labelme_json
glob.glob(os.path.join(args.labelme_images,
*.json))labelme2coco(labelme_json,
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback