fizyr / keras-retinanet

Keras implementation of RetinaNet object detection.
Apache License 2.0
4.38k stars 1.96k forks source link

Anchor parameters passing to Keras-retinanet to convert model to serving format #1356

Closed ajinkya933 closed 4 years ago

ajinkya933 commented 4 years ago

@faustomorales @hgaiser
I am referring to Keras retinanet . My target is to deploy model.h5 on tensorflow serving. To do that I use below script (script reference: https://github.com/fizyr/keras-retinanet/issues/676#issuecomment-508958949 )for converting model to tf-serving format

from keras import backend as K
import tensorflow as tf
from tensorflow.python import saved_model
from tensorflow.python.saved_model.signature_def_utils_impl import (
    build_signature_def, predict_signature_def
)
from keras_retinanet import models
import shutil
import os

export_path = 'retinanet_savedmodel'
model = models.convert_model(
    model=models.backbone(backbone_name='resnet50').retinanet(num_classes=8),
    nms=True,
    class_specific_filter=True,
    anchor_params=None
)
model.load_weights('model.h5')

print('Output layers', [o.name[:-2] for o in model.outputs])
print('Input layer', model.inputs[0].name[:-2])
if os.path.isdir(export_path):
    shutil.rmtree(export_path)
builder = saved_model.builder.SavedModelBuilder(export_path)

signature = predict_signature_def(
    inputs={'images': model.input},
    outputs={
        'output1': model.outputs[0],
        'output2': model.outputs[1],
        'output3': model.outputs[2]
    }
)

sess = K.get_session()
builder.add_meta_graph_and_variables(sess=sess,
                                     tags=[saved_model.tag_constants.SERVING],
                                     signature_def_map={'predict': signature})
builder.save()

I am able to get successful prediction. But the successful predictions are observed only for default anchor parameters. In my code I have changed the anchor parameters. These changed anchor parameters are stored in config.ini file

[anchor_parameters] 
sizes   = 16 32 64 128 256 
strides = 8 16 32 64 128 
ratios  = 0.5 1 2 3 
scales  = 1 1.2 1.6

How do I pass changed anchor params to above script?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale due to the lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Mps24-7uk commented 3 years ago

@ajinkya933 I tried to convert the generated models to TF servable model. It doesn't work for me, can you please help me out with this?