TensorFlow2 Object Detection Api(二)


本文提到的代码在最后都会提供

labelme 安装

pip install labelme

labelme 使用

转换图片的大小

这里我使用的模型是:ssd_resnet50_v1_fpn_640x640_coco17_tpu-8,所以我们将图片更改到640*640的尺寸。resize_images.py

python resize_images.py -d images/ -s 640 640

转换成coco数据集格式

将labelme打好标签的文件生成两个文件夹:train,test 分别生成。labelme2coco.py

python labelme2coco.py train --output train.json
python labelme2coco.py test --output test.json

转成TFRecord格式

我们需要TFRecord格式的文件用于在Tensorflow中训练模型。models项目里提供了create_coco_tf_record.py 文件,但是在我使用的过程中出现了一些小问题,所以我使用了网络上提供的经过更改的文件。

python create_coco_tf_record.py 
--logtostderr 
--train_image_dir=images/train 
--test_image_dir=images/test 
--train_annotations_file=images/train.json 
--test_annotations_file=images/test.json 
--include_masks=True 
--output_dir=./

Labelmap准备

train.json
这是我们生成的coco类型的Json文件,我们写的Labelmap要和他的id匹配,注意:Labelme的Id是categories的id+1.

{
  	"images": [...],
	"categories": [
	    {
	      "supercategory": "iphone",
	      "id": 0,
	      "name": "iphone"
	    },
	    {
	      "supercategory": "keyboard",
	      "id": 1,
	      "name": "keyboard"
	    },
	    {
	      "supercategory": "markCup",
	      "id": 2,
	      "name": "markCup"
	    }
	  ],
	  "annotations": [...]

labelmap:
我自己这个文件叫做:coco_format.pbtxt。

item {
    id: 1
    name: 'iphone'
}

item {
    id: 2
    name: 'keyboard'
}

item {
    id: 3
    name: 'markCup'
}

至此数据准备工作结束。
参考:

https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html#preparing-the-dataset
https://gilberttanner.com/blog/train-a-mask-r-cnn-model-with-the-tensorflow-object-detection-api

上面提到的代码同时提供CSDN下载地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃瓜小白鼠

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值