Skip to main content

Following Messi with TensorFlow and Object Detection

In previous publications we were using TensorFlow in combination with the Object Detection model, but always making use of the traditional pre-established datasets [example COCO database]. This time our challenge should take us another level and I will propose analyze a segment of a soccer game and identify its players [at least one of them].

When talking about soccer, the first thing that came to mind is look for the talented Argentinian star Lionel Messi. I will propose something:
  • Let’s train a personalized model that allows us to locate Argentine star.
  • Let’s analyze a real transmission [in this case I selected Uruguay-Argentina by Conmebol qualifying August 31, 2017] to see what results we can get.
  • Let us think if it is possible to improve or contribute something to the tactics of this passionate sport, using this technology.
Note: We will use TensorFlow and the proposed model for Object Detection, all under the Apache License 2.0 license.

In this opportunity I will start by showing you the result obtained:


If you find them interesting, I invite you to dedicate a few more minutes to follow the step by step to understand the procedure of building this model.

We should complete three important moments:
  • Build the custom dataset with the objects to be detected. [in this case Lionel Messi in full action].
  • Train and evaluate the model using TensorFlow.
  • Use the created model.
Step by Step process:

Build the custom dataset Moment

  1. If we explore the official documentation, we will find an exclusive section to build our custom dataset. Here you can see it.
  2. We need the images of the objects we want to detect and we need to label them.
    1. For this case I used the RectLabel tool, a good option for MacOS. [there are other alternatives like LabelImg]
    2. Then for the first tests I collected about 119 images [very little number, but is only for testing purposes] of a soccer game.
    3. I have labeled about 100 units selecting the Argentine star.

    Note: To put this example into production, it will definitely require many more images in this step.

  3. The next step is to convert the photos and their corresponding tags into TFFormat files. Here you can see the script used. [I used a intermediate step to convert the xml annotation labels to a csv, here the script]
  4. Remember that the ideal environment is to build a training set and the evaluation set.

Train/eval the custom model Moment

      5. With these complete files, we will begin to train and evaluate the model.
    1. For this step I have used ML Engine since I did not have the local infrastructure to perform the process in 1 hour average. [here is the official description of the procedure]
    2. 5 workers using standard gpu.
    3. it is also highly recommended to associate TensorBoard to visualize the training and evaluation process.
    4. Remember to use a direct interaction with Google Cloud Storage. In other words, all files must be in this type of repository in order to interact with the training engine.


*After a 21.77 units used, 1 hour 9 mins and about 20k iterations we have several checkpoints and an acceptable model.

       6. Using the most advanced checkpoint, we proceed to convert the trained model to inference. [Here you can see the official documentation]

Use custom model Moment

       7. Finished this procedure we will use the model from these options:
    1. script that uses the model and generates a video with the result of the detections. Here is the implementation example.
    2. script that can evaluate the video in realtime and decode the labels to calculate the appearances of the Argentine star. Here is the implementation example.
Note: same demo using slow-motion. Here

** more implementation information here [tensorflow-code-experiencesgithub repository]

Perhaps it is the beginning of an interesting line of work… how sports tactics can be improved, incorporating more players and validating associations. For now, we are using only the traditional TV transmission delivered, but what would happen if we had the option of cameras with more details or a complete view of the soccer field.

The positions of all the players could be calculated, in fact we validated that the players can be easily identified, then… could we find better tactics based on player’s position and their well-known skills?

I hope you had fun with this procedure, and I hope to see more and more TF implementations in sports disciplines such as this.

original publication: medium link

Licencia Creative Commons
Following Messi with TensorFlow and Object Detection por Nicolas Bortolotti se distribuye bajo una Licencia Creative Commons AtribuciĆ³n-CompartirIgual 4.0 Internacional.

Comments

Popular posts from this blog

Google Assistant, simpleness of interaction to call a webhook

The creation of an application using Google Assistant is very simple and represent a big impact to interact with users in diverse environments and particularly in home Hey Google ...Where is my dog? If we plan to connect a security camera system, the challenge of finding my pet in an automated way is more feasible, then I will give more details of how I intend to do it. Now we are going to prepare the functionality of the assistant’s requests. To create an agent and interact with Google Assistant , we will use DialogFlow . Let's see the main elements to create an agent, and using this agent call a webhook with some functionality. * Part of the objective will be to try to prepare the logic of interaction with a home security system * Arlo System From the DialogFlow console, we will create a new agent: We can customize different support languages, for this case I will use English to facilitate the testing of the agent. [You can include Spanish and also go in

SMI Developer Day - Session 2 was pure developers adrenaline

A new session of SMI Developer Day program has been conducted at the Cultural Center Borges in Buenos Aires. The event was pure adrenaline to the ecosystem of technology development in Google. A great attendance and I could feel pure adrenaline at the conference on May 8 at the Cultural Center Borges in the context of SMI Developer Day event . In this opportunity we present an approach to development Web solutions , innovative technologies such as HTML5 and present an option for persistence in disconnected scenarios. A great conversation environments with a lot of questions, showed the state of motivation of the developer community in the region. A region full of talent. A region that every day becomes more involved in technology , mobility , computing in the cloud. Furthermore, this region strengthens a vision of entrepreneurship, and drive an amazing ecosystem. An excellent shared moment with the community

An service option to interact with Arlo cameras

Interacting with the Arlo system is very attractive for who acquired the hardware and enjoy all the benefits of these equipments. Which by the way are very good, flexible and full of good properties. To interact with this system with a developer's perspective I found two interesting python-based projects. Python-arlo:  https://github.com/tchellomello/python-arlo Arlo:  https://github.com/jeffreydwalter/arlo Both propose different features but Python-arlo has a good documentation and structure of its API. The objective for this integration is to support applications from Google Assistant , for this reason I  integrated the service into an App Engine flex env project. I included flask as an interaction framework and with this I have the option to use a service interface. This would be our ideal architectural map: We looking for continue with the application initiated from: Hey Google ... Where is my dog? * Of course we will have to implement