Search code examples
pythontensorflowobject-detection

What is the current «official» way/best practice to train an object detection model using the Tensorflow framework?


My goal is to use transfer learning to train an object detection model with my own data (bounding boxes) and convert the models to tflite-format.

I did it before, using the Tensorflow Object Detection API which was great because it provided a wide range of models to use for transfer learning. But the API is no longer maintained and I want to work with something “up to date”.

So I checked on the TensorFlow page and found this tutorial but it again uses the Object Detection API, which is deprecated, as stated before.

I also found this tutorial which uses the TensorFlow Lite Model Maker library so I gave the linked Collab a try but I don’t even get past the pip-install because there are some errors regarding the required versions of different packages (we are talking about the official tutorial collab here! And I ran into the same errors when using the code on my PC).

Then there is MediaPipe with this tutorial When I run the Collab I get a warning.

“TensorFlow Addons (TFA) has ended development and introduction of new features. TFA has entered a minimal maintenance and release mode until a planned end of life in May 2024.”

So again, some kind of dead end. And when I tried to run it on my PC I had some issues with importing parts of mediapipe_model_maker.

At this point, I am running out of ideas to be honest. I’m “just” looking for a way to use transfer learning with object detection models (especially smaller ones like Mobilenet, EfficientDet). Is there really no worthy successor of Tensorflow Object Detection API? Am I missing something? Some new API I didn't find, some package I am not aware of? I am grateful for any hint!


Solution

  • Best thing I could do at this point was to use “tflite_model_maker” which was a challenge in itself because of dependency issues.

    It still says “TensorFlow Addons (TFA) has ended development and introduction of new features.TFA has entered a minimal maintenance and release mode until a planned end of life in May 2024.”

    But at least I can train “efficientdet_lite0” now until a better solution comes up (I’ve seen seen many comments on GitHub saying that MediaPipe should be used but I ran into even more dependency issues there). So in case someone else wants to train an efficientdet_lite network for object detection, that’s how I set up my Conda-environment on Windows, maybe it helps (for the code itself, see tutorial here).

    1. Start with a clean environment and install Python 3.9
    2. Next (to prevent this issue from happening):

    pip install "cython<3.0.0" wheel

    pip install "pyyaml==5.4.1" --no-build-isolation

    1. pip install tflite-model-maker
    2. pip install pycocotools (now you would have everything installed that you need but there will be errors, which I fixed with the following steps)
    3. pip install numpy==1.23.5 (to fix «AttributeError: module 'numpy' has no attribute 'object'., see here)
    4. pip install --upgrade tensorflow-datasets==4.9.1 (to fix ImportError: cannot import name 'array_record_module' from 'array_record.python'”, see here)
    5. And finally pip uninstall -y tensorflow && pip install -q tensorflow==2.8.0 (to fix “AttributeError: module 'keras.api._v2.keras.mixed_precision' has no attribute 'experimental'”, again see here)

    After that, I had a working environment to train the models. It’s ugly, but it works for the moment. ;)

    I’m still open for better solutions though...