图像分割数据集制作,主要分为4步,用于语义分割还是实例分割,分不清楚,只是针对代码制作的自己的数据集。

数据整体差别不大,用复制加速了一下。

1、cmd:labelme,先画一个json作为模板

2、制作label

通过代码批量复制json,每个图片都复制同样的label,然后在此基础上修改能稍快一些

然后labelme手动调整

主要是json图片数据那块,需要转换一下

import os
import glob
import PIL.Image
from labelme.logger import logger
from labelme import PY2
from labelme import QT4
import io
import json
import os.path as osp
from scipy import ndimage
import base64
from labelme import utilspath =r"图像文件夹位置"
jsonpath = r"json文件夹位置"
jsonone = r"1370559239.json"#将被复制的模板#这块很重要
def load_image_file(filename):try:image_pil = PIL.Image.open(filename)except IOError:logger.error('Failed opening image file: {}'.format(filename))return# apply orientation to image according to exifimage_pil = utils.apply_exif_orientation(image_pil)with io.BytesIO() as f:ext = osp.splitext(filename)[1].lower()if PY2 and QT4:format = 'PNG'elif ext in ['.jpg', '.jpeg']:format = 'JPEG'else:format = 'PNG'image_pil.save(f, format=format)f.seek(0)return f.read()def newjson(jsonone,path,jsonpath):data = json.load(open(jsonone))imagePath = data["imagePath"]imageps = imagePath.split("\\")imgpath =os.listdir(path)for j in range(2,len(imgpath)):imgp = imgpath[j]print(imgp)imageps[-1] = imgpimagePathnew=imageps[0]for i in range(1,len(imageps)):imagePathnew = imagePathnew+"\\"+imageps[i]data["imagePath"] = imagePathnew#这块很重要imageData = load_image_file(path+"\\"+imgp)imageData = base64.b64encode(imageData).decode('utf-8')data["imageData"] = imageDataimage = PIL.Image.open(path+"\\"+imgp)data["imageHeight"] = image.heightdata["imageWidth"] = image.widthjsonnew = jsonpath + "\\" + imgp.split('.')[0] + '.json'json.dump(data, open(jsonnew, 'w'))

3、将json转换成png图片

顺带也分了一下训练集和测试集

import base64
import json
import os
import os.path as osp
import PIL.Image
from labelme import utils
import randomdef main():jsonpath = r"json文件夹"#应该是从json里面直接读的图片数据outpath = r"png文件夹"ratio = 0.8if not osp.exists(outpath):os.mkdir(outpath)namelist=[]paths = os.listdir(jsonpath)for onepath in paths:name = onepath.split(".")[0]json_file = jsonpath+"\\"+onepathoutfile = outpath+"\\"+name+".png"namelist.append(name)data = json.load(open(json_file))imageData = data.get("imageData")if not imageData:imagePath = os.path.join(os.path.dirname(json_file), data["imagePath"])with open(imagePath, "rb") as f:imageData = f.read()imageData = base64.b64encode(imageData).decode("utf-8")img = utils.img_b64_to_arr(imageData)label_name_to_value = {"_background_": 0}for shape in sorted(data["shapes"], key=lambda x: x["label"]):label_name = shape["label"]if label_name in label_name_to_value:label_value = label_name_to_value[label_name]else:label_value = len(label_name_to_value)label_name_to_value[label_name] = label_valuelbl, _ = utils.shapes_to_label(img.shape, data["shapes"], label_name_to_value)utils.lblsave(outfile, lbl)random.shuffle(namelist)n_total = len(namelist)offset = int(n_total * ratio)train = namelist[:offset]val = namelist[offset:]with open(outpath+"\\train.txt","w") as f:for i in range(len(train)):f.write(str(train[i])+"\n")f.close()with open(outpath+"\\val.txt","w") as f:for i in range(len(val)):f.write(str(val[i])+"\n")f.close()if __name__ == "__main__":main()

png结果图片

4、制作训练集

我其实训练的时候只用到了,原图和3生成的png,将数据分为训练和测试写入txt,就可以了

训练模型调别人的:GitHub - bubbliiiing/deeplabv3-plus-pytorch: 这是一个deeplabv3-plus-pytorch的源码,可以用于训练自己的模型。

5、测试c++

为了让c++调用,将pth转成带网络结构的pt文件

    weight = torch.load(“*.pth”)model.load_state_dict(weight, strict=True)model = model.eval()# 注意模型输入的尺寸example = torch.rand(1, 3, 512, 512)traced_script_module = torch.jit.trace(model, example)name = lp.replace(".pth",".pt")traced_script_module.save(name)

opencv调用,Python版

image = cv2.imread("img_path")orininal_h,orininal_w,_ = image.shapeimage=cv2.resize(image, (512, 512))#image.convertTo(image,cv2.CV_32F, 1.0 / 255, 0)image = image/255.0image_data  = np.expand_dims(np.transpose((np.array(image, np.float32)), (2, 0, 1)), 0)img_tensor = torch.from_numpy(image_data)pr = module.forward(img_tensor)[0]pr = F.softmax(pr.permute(1, 2, 0), dim=-1).cpu().detach().numpy()# cv2.imshow("pr",pr)# cv2.waitKey(0)pr = cv2.resize(pr, (orininal_w, orininal_h), interpolation=cv2.INTER_LINEAR)pr = pr.argmax(axis=-1)colors = [(0, 0, 0), (128, 0, 0), (0, 128, 0), (128, 128, 0), (0, 0, 128), (128, 0, 128), (0, 128, 128),(128, 128, 128), (64, 0, 0), (192, 0, 0), (64, 128, 0), (192, 128, 0), (64, 0, 128), (192, 0, 128),(64, 128, 128), (192, 128, 128), (0, 64, 0), (128, 64, 0), (0, 192, 0), (128, 192, 0), (0, 64, 128),(128, 64, 12)]seg_img = np.reshape(np.array(colors, np.uint8)[np.reshape(pr, [-1])], [orininal_h, orininal_w, -1])image = Image.fromarray(np.uint8(seg_img))image.save("")

记录::图像分割数据集制作过程相关推荐

  1. 图像分割数据集制作matlab,制作自己的图像语义分割数据集

    本文教你如何正确制作自己的图像语义分割数据集.假设我当前目录下有500张图片,命名从1.jpg开始,一直往上递增,我事先已经调整好了图像的大小. 首先下载Labelme工具:https://githu ...

  2. 使用labelme制作自己的深度学习图像分割数据集

    要实现深度学习图像分割应用,首先要获取图像分割标注数据,比如PASCAL VOC.COCO.SBD等大型数据集,但这些数据集主要用于训练预训练模型和评价分割模型精度性能,针对实际应用还需要我们根据项目 ...

  3. 利用Arcgis制作图像分割数据集

    利用Arcgis制作图像分割数据集,以制作农村道路标签数据进行二分类为例 一,进行矢量化获取矢量数据 二,制作掩膜 三,mask图像导出 四,原始遥感影像裁剪 五,mask图片和遥感图像裁剪及训练集. ...

  4. 记录《Binaural Audio Generation via Multi-task Learning》的h5文件制作过程

    记录Binaural Audio Generation via Multi-task Learning的h5文件制作过程 源h5文件 这篇论文是使用的Gao等人在<2.5D Visual Sou ...

  5. 图像分割 | FCN数据集制作的全流程(图像标注)

    图像分割 | FCN数据集制作的全流程(图像标注) 一 全卷积神经网络 文章所有代码已上传至github,觉得好用就给个star吧,谢谢 https://github.com/315386775/FC ...

  6. 磁带数据存储器制作过程记录

    磁带数据存储器制作过程记录 前期准备20200805 同类产品 磁带硬件 电路硬件及控制芯片 制作20200819 电路图补充20210805 下阶段任务计划 未完待续------ 有交好的基佬说磁带 ...

  7. pybullet GGCNN数据集制作(三)

    目录 深度相机 驱动安装 pyrealsense2安装 学校端口问题用以下方法安装 其它相关环境安装 Vscode配置anaconda环境 数据集制作和加载 调用深度相机进行数据集制作 代码部分 运行 ...

  8. YOLOv4数据集制作与批量处理工具.py代码

    这篇文章主要复现数据集打标签的制作过程,以及与YOLOv4的数据集制作和数据增强. 包括: 一.voc标签 二..xml(voc格式)转.txt(yolo格式) 三.批量改文件名 四.批量修改txt文 ...

  9. 【项目实践】基于Mask R-CNN的道路物体检测与分割(从数据集制作到视频测试)...

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 1.内容概要 Mask R-CNN的框架是对Faster R-CNN的扩展,与BBox识别并行的增加一 ...

最新文章

  1. 计算机二级c语言程序,二级C语言考试系统
  2. SSH框架整合(代码加文字解释)
  3. python好学吗mooc中文网-Python语言程序设计
  4. 论文笔记之:Instance-aware Semantic Segmentation via Multi-task Network Cascades
  5. pps服务器未响应_服务响应时间与分布
  6. c语言有分数的怎么编,用C语言编程平均分数
  7. P1377 [TJOI2011]树的序 笛卡尔树优化建树
  8. android 自定义 popupwindow,Android自定义弹出窗口PopupWindow使用技巧
  9. 做折线图_python的visvis库做折线图(line.py)代码详解
  10. Hadoop入门基础教程 Hadoop之服务器基础环境搭建
  11. css3 animation
  12. mybatis plus当月数据查询_mybatis plus的3种查询方式(小结)
  13. python实现将文件下内每张图片按顺序命名为txt文本文件中的内容
  14. css-flex 常见面试题
  15. win10u盘被写保护怎么解除_如何去掉写保护?tf磁盘被写保护?win10如何去掉写保护?【U盘写保护怎么去掉?】Microsoft Windows...
  16. Android 最常用的设计模式二 安卓Rxjava源码分析—观察者模式Observer(有实例)
  17. java计算机毕业设计晨光文具店进销存系统设计与开发源码+数据库+系统+lw文档+部署
  18. 苹果服务器系统状态查询网址
  19. 2022年朝阳区科技创新课之“产品创新与成果转化”训练营活动圆满结束
  20. mac拷贝图片window打不开

热门文章

  1. 复习新托福iBT英文写作经验汇总
  2. 【观察】VMware:二十而冠,以梦为马不负韶华
  3. c语言的算法一定要雪狐嘛,c语言的编程风格
  4. Python处理‘\u’开头的字符串
  5. 中型载货汽车离合器及传动轴设计【4张CAD图纸+论文+英文翻译】
  6. 视频帧率和分辨率对QoE的影响
  7. windows搭建hadoop分布式系统架构
  8. datagrid数据表格使用方法
  9. Deformable DETR 实战(训练及预测)
  10. Deformable ConvNets v2: More Deformable, Better Results