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

相关文章

Linux下利用select实现串口数据读取过程

《Linux下利用select实现串口数据读取过程》文章介绍Linux中使用select、poll或epoll实现串口数据读取,通过I/O多路复用机制在数据到达时触发读取,避免持续轮询,示例代码展示设... 目录示例代码(使用select实现)代码解释总结在 linux 系统里,我们可以借助 select、

java中判断json key是否存在的几种方法

《java中判断jsonkey是否存在的几种方法》在使用Java处理JSON数据时,如何判断某一个key是否存在?本文就来介绍三种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的... 目http://www.chinasem.cn录第一种方法是使用 jsONObject 的 has 方法

Go语言中json操作的实现

《Go语言中json操作的实现》本文主要介绍了Go语言中的json操作的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录 一、jsOChina编程N 与 Go 类型对应关系️ 二、基本操作:编码与解码 三、结构体标签(Struc

Ubuntu向多台主机批量传输文件的流程步骤

《Ubuntu向多台主机批量传输文件的流程步骤》:本文主要介绍在Ubuntu中批量传输文件到多台主机的方法,需确保主机互通、用户名密码统一及端口开放,通过安装sshpass工具,准备包含目标主机信... 目录Ubuntu 向多台主机批量传输文件1.安装 sshpass2.准备主机列表文件3.创建一个批处理脚

Java轻松实现PDF转换为PDF/A的示例代码

《Java轻松实现PDF转换为PDF/A的示例代码》本文将深入探讨Java环境下,如何利用专业工具将PDF转换为PDF/A格式,为数字文档的永续保存提供可靠方案,文中的示例代码讲解详细,感兴趣的小伙伴... 目录为什么需要将PDF转换为PDF/A使用Spire.PDF for Java进行转换前的准备通过

C#使用iText获取PDF的trailer数据的代码示例

《C#使用iText获取PDF的trailer数据的代码示例》开发程序debug的时候,看到了PDF有个trailer数据,挺有意思,于是考虑用代码把它读出来,那么就用到我们常用的iText框架了,所... 目录引言iText 核心概念C# 代码示例步骤 1: 确保已安装 iText步骤 2: C# 代码程

Pandas处理缺失数据的方式汇总

《Pandas处理缺失数据的方式汇总》许多教程中的数据与现实世界中的数据有很大不同,现实世界中的数据很少是干净且同质的,本文我们将讨论处理缺失数据的一些常规注意事项,了解Pandas如何表示缺失数据,... 目录缺失数据约定的权衡Pandas 中的缺失数据None 作为哨兵值NaN:缺失的数值数据Panda

C++中处理文本数据char与string的终极对比指南

《C++中处理文本数据char与string的终极对比指南》在C++编程中char和string是两种用于处理字符数据的类型,但它们在使用方式和功能上有显著的不同,:本文主要介绍C++中处理文本数... 目录1. 基本定义与本质2. 内存管理3. 操作与功能4. 性能特点5. 使用场景6. 相互转换核心区别

MySQL批量替换数据库字符集的实用方法(附详细代码)

《MySQL批量替换数据库字符集的实用方法(附详细代码)》当需要修改数据库编码和字符集时,通常需要对其下属的所有表及表中所有字段进行修改,下面:本文主要介绍MySQL批量替换数据库字符集的实用方法... 目录前言为什么要批量修改字符集?整体脚本脚本逻辑解析1. 设置目标参数2. 生成修改表默认字符集的语句3

python库pydantic数据验证和设置管理库的用途

《python库pydantic数据验证和设置管理库的用途》pydantic是一个用于数据验证和设置管理的Python库,它主要利用Python类型注解来定义数据模型的结构和验证规则,本文给大家介绍p... 目录主要特点和用途:Field数值验证参数总结pydantic 是一个让你能够 confidentl