数据标注:批量转换json文件,出现AttributeError: module ‘labelme.utils‘ has no attribute ‘draw_label‘错误

本文主要是介绍数据标注:批量转换json文件,出现AttributeError: module ‘labelme.utils‘ has no attribute ‘draw_label‘错误,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

labelme版本更换为3.11.2

"D:\Anaconda3\Lib\site-packages\labelme\utils\draw.py"缺失?:

import io
import os.path as ospimport numpy as np
import PIL.Image
import PIL.ImageDraw
import PIL.ImageFontdef label_colormap(N=256):def bitget(byteval, idx):return ((byteval & (1 << idx)) != 0)cmap = np.zeros((N, 3))for i in range(0, N):id = ir, g, b = 0, 0, 0for j in range(0, 8):r = np.bitwise_or(r, (bitget(id, 0) << 7 - j))g = np.bitwise_or(g, (bitget(id, 1) << 7 - j))b = np.bitwise_or(b, (bitget(id, 2) << 7 - j))id = (id >> 3)cmap[i, 0] = rcmap[i, 1] = gcmap[i, 2] = bcmap = cmap.astype(np.float32) / 255return cmapdef _validate_colormap(colormap, n_labels):if colormap is None:colormap = label_colormap(n_labels)else:assert colormap.shape == (colormap.shape[0], 3), \'colormap must be sequence of RGB values'assert 0 <= colormap.min() and colormap.max() <= 1, \'colormap must ranges 0 to 1'return colormap# similar function as skimage.color.label2rgb
def label2rgb(lbl, img=None, n_labels=None, alpha=0.5, thresh_suppress=0, colormap=None,
):if n_labels is None:n_labels = len(np.unique(lbl))colormap = _validate_colormap(colormap, n_labels)colormap = (colormap * 255).astype(np.uint8)lbl_viz = colormap[lbl]lbl_viz[lbl == -1] = (0, 0, 0)  # unlabeledif img is not None:img_gray = PIL.Image.fromarray(img).convert('LA')img_gray = np.asarray(img_gray.convert('RGB'))# img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)# img_gray = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2RGB)lbl_viz = alpha * lbl_viz + (1 - alpha) * img_graylbl_viz = lbl_viz.astype(np.uint8)return lbl_vizdef draw_label(label, img=None, label_names=None, colormap=None, **kwargs):"""Draw pixel-wise label with colorization and label names.label: ndarray, (H, W)Pixel-wise labels to colorize.img: ndarray, (H, W, 3), optionalImage on which the colorized label will be drawn.label_names: iterableList of label names."""import matplotlib.pyplot as pltbackend_org = plt.rcParams['backend']plt.switch_backend('agg')plt.subplots_adjust(left=0, right=1, top=1, bottom=0,wspace=0, hspace=0)plt.margins(0, 0)plt.gca().xaxis.set_major_locator(plt.NullLocator())plt.gca().yaxis.set_major_locator(plt.NullLocator())if label_names is None:label_names = [str(l) for l in range(label.max() + 1)]colormap = _validate_colormap(colormap, len(label_names))label_viz = label2rgb(label, img, n_labels=len(label_names), colormap=colormap, **kwargs)plt.imshow(label_viz)plt.axis('off')plt_handlers = []plt_titles = []for label_value, label_name in enumerate(label_names):if label_value not in label:continuefc = colormap[label_value]p = plt.Rectangle((0, 0), 1, 1, fc=fc)plt_handlers.append(p)plt_titles.append('{value}: {name}'.format(value=label_value, name=label_name))plt.legend(plt_handlers, plt_titles, loc='lower right', framealpha=.5)f = io.BytesIO()plt.savefig(f, bbox_inches='tight', pad_inches=0)plt.cla()plt.close()plt.switch_backend(backend_org)out_size = (label_viz.shape[1], label_viz.shape[0])out = PIL.Image.open(f).resize(out_size, PIL.Image.BILINEAR).convert('RGB')out = np.asarray(out)return outdef draw_instances(image=None,bboxes=None,labels=None,masks=None,captions=None,
):import matplotlib# TODO(wkentaro)assert image is not Noneassert bboxes is not Noneassert labels is not Noneassert masks is Noneassert captions is not Noneviz = PIL.Image.fromarray(image)draw = PIL.ImageDraw.ImageDraw(viz)font_path = osp.join(osp.dirname(matplotlib.__file__),'mpl-data/fonts/ttf/DejaVuSans.ttf')font = PIL.ImageFont.truetype(font_path)colormap = label_colormap(255)for bbox, label, caption in zip(bboxes, labels, captions):color = colormap[label]color = tuple((color * 255).astype(np.uint8).tolist())xmin, ymin, xmax, ymax = bboxdraw.rectangle((xmin, ymin, xmax, ymax), outline=color)draw.text((xmin, ymin), caption, font=font)return np.asarray(viz)

 

这篇关于数据标注:批量转换json文件,出现AttributeError: module ‘labelme.utils‘ has no attribute ‘draw_label‘错误的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1143970

相关文章

在MySQL中实现冷热数据分离的方法及使用场景底层原理解析

《在MySQL中实现冷热数据分离的方法及使用场景底层原理解析》MySQL冷热数据分离通过分表/分区策略、数据归档和索引优化,将频繁访问的热数据与冷数据分开存储,提升查询效率并降低存储成本,适用于高并发... 目录实现冷热数据分离1. 分表策略2. 使用分区表3. 数据归档与迁移在mysql中实现冷热数据分

C#解析JSON数据全攻略指南

《C#解析JSON数据全攻略指南》这篇文章主要为大家详细介绍了使用C#解析JSON数据全攻略指南,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、为什么jsON是C#开发必修课?二、四步搞定网络JSON数据1. 获取数据 - HttpClient最佳实践2. 动态解析 - 快速

linux批量替换文件内容的实现方式

《linux批量替换文件内容的实现方式》本文总结了Linux中批量替换文件内容的几种方法,包括使用sed替换文件夹内所有文件、单个文件内容及逐行字符串,强调使用反引号和绝对路径,并分享个人经验供参考... 目录一、linux批量替换文件内容 二、替换文件内所有匹配的字符串 三、替换每一行中全部str1为st

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

MySQL 8 中的一个强大功能 JSON_TABLE示例详解

《MySQL8中的一个强大功能JSON_TABLE示例详解》JSON_TABLE是MySQL8中引入的一个强大功能,它允许用户将JSON数据转换为关系表格式,从而可以更方便地在SQL查询中处理J... 目录基本语法示例示例查询解释应用场景不适用场景1. ‌jsON 数据结构过于复杂或动态变化‌2. ‌性能要

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

基于Python开发一个图像水印批量添加工具

《基于Python开发一个图像水印批量添加工具》在当今数字化内容爆炸式增长的时代,图像版权保护已成为创作者和企业的核心需求,本方案将详细介绍一个基于PythonPIL库的工业级图像水印解决方案,有需要... 目录一、系统架构设计1.1 整体处理流程1.2 类结构设计(扩展版本)二、核心算法深入解析2.1 自

Python自动化批量重命名与整理文件系统

《Python自动化批量重命名与整理文件系统》这篇文章主要为大家详细介绍了如何使用Python实现一个强大的文件批量重命名与整理工具,帮助开发者自动化这一繁琐过程,有需要的小伙伴可以了解下... 目录简介环境准备项目功能概述代码详细解析1. 导入必要的库2. 配置参数设置3. 创建日志系统4. 安全文件名处

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

SpringBoot中六种批量更新Mysql的方式效率对比分析

《SpringBoot中六种批量更新Mysql的方式效率对比分析》文章比较了MySQL大数据量批量更新的多种方法,指出REPLACEINTO和ONDUPLICATEKEY效率最高但存在数据风险,MyB... 目录效率比较测试结构数据库初始化测试数据批量修改方案第一种 for第二种 case when第三种