Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to load the model after adding instance_normalization #10

Open
prb2307 opened this issue Apr 4, 2019 · 3 comments
Open

unable to load the model after adding instance_normalization #10

prb2307 opened this issue Apr 4, 2019 · 3 comments

Comments

@prb2307
Copy link

prb2307 commented Apr 4, 2019

@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.

@lim-anggun
Copy link
Owner

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})

@prb2307
Copy link
Author

prb2307 commented Apr 5, 2019

@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?

@Tomingz
Copy link

Tomingz commented Jul 9, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants