Thanks for reaching out on this issue.
My main problem is that I have not succeeded in taking a pre-built model from either Tensorflow Hub or Tensorflow Object Detection API, or anyother place.
As stated on another thread on this forum:
the Object Detection fine tuning story on TFHub is not perfect. Most of the OD models that were published don’t have the proper api to be fine tuned easily (like the image classification ones you mentioned).
As you know the TFX trainer module expects the function
_build_keras_model() to return a compiled Keras model.
Model HUB approach
If I’m not mistaken, I can’t use
tf.keras.Sequential() (as in the above tutorial) because there is more than one output from object detection models. The class, and the box.
I tried a naive approach with the functional API:
img_inputs = keras.Input(shape=IMAGE_SIZE + (3,))
hub_model = hub.KerasLayer(model_handle, trainable=do_fine_tuning)
outputs = hub_model(img_inputs)
model = keras.Model(inputs=img_inputs, outputs=outputs, name="obj_det_model")
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])
This got me a bit further, but will not work because of the loss function. I need a combination of the Huber and Focal functions. But implementing the loss function is a bit over my level. Even if I felt comfortable doing it, it’s not quite an “of-the-shelf” solution.
Object Detection API Approach
The Tensorflow object detection API has some very good notebook tutorials but the model that is built is of type
object_detection.meta_arcitectures.ssd_mera_arch.<MODEL>Arch. I have not found a way to get from that to a Keras model.
Trying to load a
saved model using
tf.keras.models.load_model() gives me a
<tensorflow.python.saved_model.load.Loader._recreate_base_user_object.<locals>._UserObject not a keras model.
Related(?) Github issue
Training from scratch
I’m currently following the instructions on training a model from scratch with the object detection API.
So I have tried quite a few things. I don’t see an easy way to take a predefined object detection model and use it in a TFX pipeline. I would be happy to be proven wrong with an example.