FgSegNet_v2 icon indicating copy to clipboard operation
FgSegNet_v2 copied to clipboard

unable to load the model after adding instance_normalization

Open prb2307 opened this issue 5 years ago • 3 comments

@lim-anggun I have read your previous comment on adding the instance_nornalization.py .But I am still getting the error I have added this line of code as mentioned by you. from FgSegNet.instance_normalization import InstanceNormalization model = load_model(mdl_path, custom_objects={'MyUpSampling2D': MyUpSampling2D, 'InstanceNormalization': InstanceNormalization})

Error :

`-----------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-69f03b7b76fd> in <module>
      4 mdl_path = 'FgSegNet_M/CDnet/models50/baseline/mdl_pedestrians.h5'
      5 from FgSegNet.instance_normalization import InstanceNormalization
----> 6 model = load_model(mdl_path, custom_objects={'MyUpSampling2D': MyUpSampling2D, 'InstanceNormalization': InstanceNormalization})
      7 #from FgSegNet_v2_module.py import loss2, acc2
      8 #model = load_model(mdl_path, custom_objects={'MyUpSampling2D': MyUpSampling2D, 'InstanceNormalization': InstanceNormalization})

~/anaconda3/envs/p3/lib/python3.6/site-packages/keras/models.py in load_model(filepath, custom_objects, compile)
    262                       metrics=metrics,
    263                       loss_weights=loss_weights,
--> 264                       sample_weight_mode=sample_weight_mode)
    265 
    266         # Set optimizer weights.

~/anaconda3/envs/p3/lib/python3.6/site-packages/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, **kwargs)
    679             loss_functions = [losses.get(l) for l in loss]
    680         else:
--> 681             loss_function = losses.get(loss)
    682             loss_functions = [loss_function for _ in range(len(self.outputs))]
    683         self.loss_functions = loss_functions

~/anaconda3/envs/p3/lib/python3.6/site-packages/keras/losses.py in get(identifier)
    100     if isinstance(identifier, six.string_types):
    101         identifier = str(identifier)
--> 102         return deserialize(identifier)
    103     elif callable(identifier):
    104         return identifier

~/anaconda3/envs/p3/lib/python3.6/site-packages/keras/losses.py in deserialize(name, custom_objects)
     92                                     module_objects=globals(),
     93                                     custom_objects=custom_objects,
---> 94                                     printable_module_name='loss function')
     95 
     96 

~/anaconda3/envs/p3/lib/python3.6/site-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    157             if fn is None:
    158                 raise ValueError('Unknown ' + printable_module_name +
--> 159                                  ':' + function_name)
    160         return fn
    161     else:

ValueError: Unknown loss function:loss

I would appreciate your advice on this. Thank you.

prb2307 avatar Apr 04 '19 02:04 prb2307

Hi @prashant-bansod , You may find this Jupyter Notebook helpful.

You need to add extra parameters to the load_model function as follows:

from instance_normalization import InstanceNormalization
from my_upsampling_2d import MyUpSampling2D
from FgSegNet_v2_module import loss, acc, loss2, acc2

model = load_model(model_path, custom_objects={'MyUpSampling2D': MyUpSampling2D, 'InstanceNormalization': InstanceNormalization, 'loss':loss, 'acc':acc, 'loss2':loss2, 'acc2':acc2})

lim-anggun avatar Apr 05 '19 06:04 lim-anggun

@lim-anggun Thank you very much. I made the required corrections. Thanks a ton for your reply. I had one more question, I tried the pedestrian model but the silhouettes I got are noisy. Does the background has an effect on the extracted silhouettes?

What do you think would be the best approach to extract human silhouettes?

prb2307 avatar Apr 05 '19 07:04 prb2307

thanks a lot for your great work, but how to make my own data like the CDnet2014? and how to train it?

Tomingz avatar Jul 09 '19 10:07 Tomingz