python - xml中的注释转换为json?
问题描述
我正在使用MASK RCNN keras 和 tensorflow,我想知道是否有人能够使用 xml 注释文件进行训练,或者是否有人将 xml 转换为 json。如果我将 xml 文件更改为 json,有人可以向我展示如何使用 load_() 函数的示例吗?
我用 VIA 工具做了一些注释,它是正确的,(训练和检测)但我真的很想使用 xml 注释,因为已经完成并且需要很长时间才能重新开始。
我已将我的 xml 文件转换为 json,但我的注释中没有多边形或区域,我该如何使用它?谢谢你。
我会很感激。
annotations1 = json.load(open(os.path.join(dataset_dir, "dataset.json")))
annotations = list(annotations1.values()) # don't need the dict keys
annotations = [a for a in annotations if a['images']]
for a in annotations:
polygons = [r['shape_attributes'] for r in a['regions'].values()]
image_path = os.path.join(dataset_dir, a['filename'])
image = skimage.io.imread(image_path)
height, width = image.shape[:2]
self.add_image(
"damage",
image_id=a['filename'],
path=image_path,
width=width, height=height,
polygons=polygons)
解决方案
您需要创建自己的脚本来从 XML 转换为 JSON,或者干脆删除该load_mask()
函数。
推荐阅读
- mysql - oracle和mysql之间的数据传输
- c# - Visual Studio 2019 - 构建花费的时间比他们应该的要长得多
- bash - 如何在 Bash 脚本中用任何内容替换反斜杠
- java - 映射如何嵌入休眠 sql 查询
- delphi - 再次显示表单时,RadioButtons 保存上次检查而不是所需的
- java - 为什么我的 java while 循环继续以真实状态打印?
- kendo-ui - 如何通过视图模型将 DropDownList 中的选定值传递给控制器的操作方法?
- intellij-idea - 如何从 IntelliJ IDEA v. 2019.3 中的单个测试运行中删除新选项“从上下文创建 testName 运行配置”?
- javascript - 本地时间网页上的 JavaScript 代码
- r - 根据 R 中另一列值的部分字符串匹配查找数据帧的子集