数据标注:批量转换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

相关文章

SpringBoot+Docker+Graylog 如何让错误自动报警

《SpringBoot+Docker+Graylog如何让错误自动报警》SpringBoot默认使用SLF4J与Logback,支持多日志级别和配置方式,可输出到控制台、文件及远程服务器,集成ELK... 目录01 Spring Boot 默认日志框架解析02 Spring Boot 日志级别详解03 Sp

MySQL 删除数据详解(最新整理)

《MySQL删除数据详解(最新整理)》:本文主要介绍MySQL删除数据的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、前言二、mysql 中的三种删除方式1.DELETE语句✅ 基本语法: 示例:2.TRUNCATE语句✅ 基本语

MySQL查询JSON数组字段包含特定字符串的方法

《MySQL查询JSON数组字段包含特定字符串的方法》在MySQL数据库中,当某个字段存储的是JSON数组,需要查询数组中包含特定字符串的记录时传统的LIKE语句无法直接使用,下面小编就为大家介绍两种... 目录问题背景解决方案对比1. 精确匹配方案(推荐)2. 模糊匹配方案参数化查询示例使用场景建议性能优

关于集合与数组转换实现方法

《关于集合与数组转换实现方法》:本文主要介绍关于集合与数组转换实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、Arrays.asList()1.1、方法作用1.2、内部实现1.3、修改元素的影响1.4、注意事项2、list.toArray()2.1、方

MyBatisPlus如何优化千万级数据的CRUD

《MyBatisPlus如何优化千万级数据的CRUD》最近负责的一个项目,数据库表量级破千万,每次执行CRUD都像走钢丝,稍有不慎就引起数据库报警,本文就结合这个项目的实战经验,聊聊MyBatisPl... 目录背景一、MyBATis Plus 简介二、千万级数据的挑战三、优化 CRUD 的关键策略1. 查

python实现对数据公钥加密与私钥解密

《python实现对数据公钥加密与私钥解密》这篇文章主要为大家详细介绍了如何使用python实现对数据公钥加密与私钥解密,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录公钥私钥的生成使用公钥加密使用私钥解密公钥私钥的生成这一部分,使用python生成公钥与私钥,然后保存在两个文

mysql中的数据目录用法及说明

《mysql中的数据目录用法及说明》:本文主要介绍mysql中的数据目录用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、版本3、数据目录4、总结1、背景安装mysql之后,在安装目录下会有一个data目录,我们创建的数据库、创建的表、插入的

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

SpringBoot中4种数据水平分片策略

《SpringBoot中4种数据水平分片策略》数据水平分片作为一种水平扩展策略,通过将数据分散到多个物理节点上,有效解决了存储容量和性能瓶颈问题,下面小编就来和大家分享4种数据分片策略吧... 目录一、前言二、哈希分片2.1 原理2.2 SpringBoot实现2.3 优缺点分析2.4 适用场景三、范围分片