python棋子_使用Tensorflow对象检测API检测棋子

python棋子

I recently subscribed to a weekly data science newsletter that sent a new dataset to work on every Monday. Working as a web developer, I get little time to practice and learn all the data related stuff. Now I had a dataset in my mail on every Monday with a very high usability value and focused on a particular topic.

我最近订阅了每周一次的数据科学新闻通讯,该通讯在每个星期一发送了一个新的数据集。 作为Web开发人员,我几乎没有时间练习和学习与数据相关的所有知识。 现在,我每个星期一的邮件中都有一个数据集,具有很高的可用性值,并且专注于特定主题。

One of those topics was detecting chess pieces from the given dataset. So I decided to learn and use the Tensorflow Object Detection API.

这些主题之一是从给定的数据集中检测棋子。 因此,我决定学习并使用Tensorflow对象检测API。

Tensorflow GitHub repo contains all the scripts and provides a model zoo to select a model as per need. I selected the Faster RCNN Inception v2 model. In the given dataset, images were already divided into testing and training folders.

Tensorflow GitHub存储库包含所有脚本,并提供了一个模型动物园来根据需要选择模型。 我选择了Faster RCNN Inception v2模型。 在给定的数据集中,图像已经分为测试文件夹和训练文件夹。

Now, the first step of the process is to label or annotate an image. This can be achieved through labelImg or some other similar tool(https://github.com/tzutalin/labelImg). This will get you XML files for all the images. Then a script is needed to be executed to convert all these files to a single CSV file.

现在,该过程的第一步是标记或注释图像。 这可以通过labelImg或其他类似工具( https://github.com/tzutalin/labelImg )来实现。 这将为您提供所有图像的XML文件。 然后需要执行脚本以将所有这些文件转换为单个CSV文件。

Luckily and thankfully for me, this dataset already contained annotations.csv, so I was saved from this time consuming and boring job of labelling images.

幸运的是,对我来说,这个数据集已经包含了annotations.csv,因此我从繁琐而费力的图像标注工作中解脱了。

Second, I generated .tfrecord file for both testing and training data. After that I created the .pbtxt file which contains all the classes that I needed to detect.

其次,我为测试和培训数据生成了.tfrecord文件。 之后,我创建了.pbtxt文件,其中包含我需要检测的所有类。

item {
id: 1
name: 'whitequeen'
}
item {
id: 2
name: 'whiteking'
}item {
id: 3
name: 'whiteknight'
}item {
id: 4
name: 'whitepawn'
}item {
id: 5
name: 'whitebishop'
}item {
id: 6
name: 'whiterook'
}
item {
id: 7
name: 'blackqueen'
}
item {
id: 8
name: 'blackking'
}item {
id: 9
name: 'blackknight'
}item {
id: 10
name: 'blackpawn'
}item {
id: 11
name: 'blackbishop'
}item {
id: 12
name: 'blackrook'
}

Lastly, I changed the config file of my model by including the pbtxt and tfrecords files I had created and also mentioned the number of the classes to detect that is 12.

最后,我通过添加我创建的pbtxt和tfrecords文件来更改模型的配置文件,并提到要检测的类数为12。

Now, we train!

现在,我们训练!

I ran the training for 10000 epochs in Google colab with GPU runtime and loss for my last step was 0.14513482, but overall loss was 0.417, which is okay-ish. Before testing the inference graph that was created needs to be exported. After exporting, one receives a frozen inference graph which is used to make predictions, and several checkpoints of the model are also given.

我在带有GPU运行时的Google colab中进行了10000个时期的训练,最后一步的损失为0.14513482,但总损失为0.417,这还可以。 在测试创建的推理图之前,需要将其导出。 导出后,会收到一个冻结的推理图,该图用于进行预测,并给出了模型的几个检查点。

Test results time!!

测试结果时间!!

Image for post
Image for post
Image for post

As you can see its a mixed bag. In some cases where there are multiple objects in the picture, the model identifies most of them correctly, but when there is only a single object in picture, it doesn’t always identifies.

如您所见,它是一个混合袋。 在图片中有多个对象的某些情况下,模型可以正确识别其中的大多数对象,但是当图片中只有一个对象时,它并不总是可以识别。

Finally, credits to Luke Posey for the dataset and Sentdex for showing the process.

最后,归功于Luke Posey的数据集和Sentdex的展示过程。

Link to Sentdex’s tutorial — https://pythonprogramming.net/introduction-use-tensorflow-object-detection-api-tutorial/

链接到Sentdex的教程- https://pythonprogramming.net/introduction-use-tensorflow-object-detection-api-tutorial/

Link to my Github repository — https://github.com/virendhanwani/chess-object-detection

链接到我的Github存储库-https: //github.com/virendhanwani/chess-object-detection

Newsletter — Dataset Daily by Luke Posey

时事通讯— Luke Posey的 每日数据集

谢谢阅读! (Thanks for reading!)

翻译自: https://medium.com/swlh/detecting-chess-pieces-using-tensorflow-object-detection-api-dc26e11d48c6

python棋子

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值