I am currently learning python and machine learning while I get a job offer where I can telecommute. For family and health reasons I can’t afford the luxury of working outside my city, my autonomous community, my country, for me it is a luxury I can’t afford, so I have to accept my reality and prepare myself for the future. Since I started to touch the world of big data with hadoop and Spark, I started to see the world of machine learning and deep learning through Spark, and at the time I decided that it was time to learn a new language, scala or python. I decided to choose python because I was going to learn Spark as well, better to select the language in which it was written. I also thought at the time that python is a slow language, with inferior performance, and that it was something similar to bash. I still think so, but it is clear that python has something that neither java, nor scala, nor bash has. It has a community behind it in the world of AI and deeplearning that no other language has, so it’s better to learn it now while you still can.
The thing is that I’m taking courses on Udemy, with good teachers and I’m taking the time to learn python, good practices when developing with python, deep learning issues and everything related to it. For example, I’ve always been fascinated by a scene where Finch, the creator of the machine in Person of Interest, would authenticate himself with it using a camera, and then the machine would be able to recognise him, as well as all the people. I’ve been looking at how to achieve this, using frameworks like opencv, tensorflow and keras. opencv is for accessing your webcam, basically, capturing frames, drawing over those frames and I guess a lot of other things. tensorflow and keras are frameworks for training models to receive input frames from the camera in a format they can understand so that after that process, future captures can be compared with a database from the past.

In this route you can see my efforts when creating a script that uses opencv, tensorflow and keras to first try to train a model by capturing a number of frames from the camera, and then once the model is trained, load it and to be able to ask him for predictions about new image captures made with the camera in real time. Easy, right?
Well, there are several problems, especially when it comes to choosing the appropriate strategy, and also having the appropriate hardware to train these models in a reasonable time. I have a macbook pro with an i9 2.4Ghz, 8 cores, 32 GB DDR4 ram and an AMD Radeon Pro come 20 4GB. A team that at first I thought would be enough. How naive he was. The problem is not the memory, it is not a lot but it is not a little either, especially for doing initial tests, the problem is the GPU, which does not have mature support for these deep learning libraries that NVIDIA GPUs do have.
If you look at the code, in the execution of, for example, https://github.com/alonsoir/IA_DeepLearning_Course/blob/main/whoami.py

you can see the main function:

try:
        device = "/device:GPU:0"
        # isGPUAvailable = tf.test.is_gpu_available()
        isGPUAvailable = tf.config.list_physical_devices('GPU')

        if len(isGPUAvailable) == 0:
            print("GPU not available...")
            devices = tf.config.list_physical_devices(device)
            if len(devices) == 0:
                print("Tensorflow just can use the cpu.")
        else:
            print("It looks like there is a GPU you can use.")
        with tf.device(device):
            main()

If GPU is available, main function will run behind the umbrella of the GPU. If not, you will use just the cpu.

Trust me, the difference between running the train method using a GPU or just CPU is huge.

After that script I decide that since I don’t have the equipment to be able to do the tests to create a suitable model with the correct weights, I decide to try to use a specialized framework. I found one, deepface, in which you have to start from a folder structure on the machine where you want to run, so that you will have the photos of the users that you want to check. It works more or less well, in my opinion the threshold is low, so you can get false positives, in my tests up to a third, but I suppose we will have to play with the parameters and choose one model or another. It allows you to select between several models and several parameters to achieve a better match. Another more serious problem, in my opinion, is that if you want to add new people, or new photos, you have to delete the file generated the previous time with the previous state, add the new folder with the new photos, start again so that it can be force a new model to be generated by putting a person in front of it to generate it. This limitation is serious and implies that you would have to do this process at another time when your business is closed, for example, or find a mechanism so that new models can be automatically updated using snapshots.

This is my test, you will have to download deepface framework using pip, just run:

pip install deepface

and you are ready to go and run the demo.

python whoami-deepface.py

The web cam will run, you will have to change the _db_path variable, in my case points to /Users/aironman/git/users/database. Just change /Users/aironman/git/ to whatever folder you want, just respect /users/database and create folders with your name and inside them copy some photo.

This is the output in a terminal. Check another examples in that github repo, i will create more examples.

Deja un comentario