Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

Convert keras SSD model to IR

Morishige__Akihito
646 Views

I tried SSD by original data in keras. And I would like to change
trained model (.hdf5) to tensorflow model at first step to work this model
in open VINO.
But I can't convert keras model due to the follow problem.

ValueError: Invalid layer: Normalize

■keras_to_tensorflow
https://github.com/amir-abdi/keras_to_tensorflow

・Windows
・keras2.0.0

ssd.py in ssd_keras includes normalize layer. I think it is cause of
the problem. But I don't know how to change or revise this.
Could you tell me the good way to avoid this error ?
or could you tell me the way to change directly to IR model if there are any ?

-------------ssd.py------------------------------------------------

    # Last Pool
    net['pool6'] = GlobalAveragePooling2D(name='pool6')(net['conv8_2'])
    # Prediction from conv4_3
    net['conv4_3_norm'] = Normalize(20, name='conv4_3_norm')(net['conv4_3'])
    num_priors = 3
    x = Conv2D(num_priors * 4, (3, 3), padding='same',
                      name='conv4_3_norm_mbox_loc')(net['conv4_3_norm'])
    net['conv4_3_norm_mbox_loc'] = x
    flatten = Flatten(name='conv4_3_norm_mbox_loc_flat')
    net['conv4_3_norm_mbox_loc_flat'] = flatten(net['conv4_3_norm_mbox_loc'])
    name = 'conv4_3_norm_mbox_conf'
    if num_classes != 21:
        name += '_{}'.format(num_classes)
    x = Conv2D(num_priors * num_classes, (3, 3), padding='same',
                      name=name)(net['conv4_3_norm'])
    net['conv4_3_norm_mbox_conf'] = x
    flatten = Flatten(name='conv4_3_norm_mbox_conf_flat')
    net['conv4_3_norm_mbox_conf_flat'] = flatten(net['conv4_3_norm_mbox_conf'])
    priorbox = PriorBox(img_size, 30.0, aspect_ratios=[2],
                        variances=[0.1, 0.1, 0.2, 0.2],
                        name='conv4_3_norm_mbox_priorbox')
    net['conv4_3_norm_mbox_priorbox'] = priorbox(net['conv4_3_norm'])

---------------------------------------------------------------------

0 Kudos
9 Replies
Hyodo__Katsuya
Innovator
646 Views
@Morishige, Akihito Is it possible to share the model file (.hdf5) you generated with us?
0 Kudos
Morishige__Akihito
646 Views

I uploaded the file, this is for share. So train data is very small, but the model architecture is the same.

 

0 Kudos
Hyodo__Katsuya
Innovator
646 Views
@Morishige, Akihito Thank you. Did you try the following? https://github.com/rykov8/ssd_keras/issues/83
0 Kudos
Morishige__Akihito
646 Views

Thanks. I tried follows.

https://github.com/rykov8/ssd_keras/issues/83

Error is not occured at Normalize layer, but it has still a problem at PriorBox layer.

TypeError: __init__() missing 2 required positional arguments: 'img_size' and 'min_size'

0 Kudos
Hyodo__Katsuya
Innovator
646 Views
Is not it just that the number of parameters does not match?
0 Kudos
Morishige__Akihito
646 Views

Yes, that is.

At ssd.py I think the parameters are set, so the model includes these information. 

I don't know where I should set. (My understanding for SSD isn't enough.)

0 Kudos
Hyodo__Katsuya
Innovator
646 Views
@Morishige, Akihito I understood. I will try it when I have time. Please tell me the URL of the repository you used when generating the model.
0 Kudos
Morishige__Akihito
646 Views

I appericiate your support. I uploaded the code.

Trained data is in the checkpoints folder, it is the file can't convert to IR.

 You use train.py when you use. This code is worked under keras2.

I'm sorry I can't share the original data, so its data is the test data. But code is the same.

 

0 Kudos
Olivero__Alberto
Beginner
646 Views

Hyodo, Katsuya wrote:

@Morishige, Akihito

Thank you.
Did you try the following?
https://github.com/rykov8/ssd_keras/issues/83

Hi, I'm also interested to keep working the conversion from keras to TF. I used the following line of code as for your comment but still do not work. May you elaborate your answer more ?

model = keras.models.load_model(input_model_path, custom_objects={'Normalize': Normalize, 'PriorBox': PriorBox})

0 Kudos
Reply