crlz182 / Netvlad-Keras

This is a Keras implementation of the Netvlad network for visual place recognition.
22 stars 6 forks source link

model.save TypeError: Not JSON Serializable: ? #3

Closed mazatov closed 2 years ago

mazatov commented 2 years ago

I attached NetVlad layer to my model and I get an error when I try to save it. My guess is it's because the model is partially in Keras and partially in Tensorflow. Wonder if you had any issues with that?

Traceback (most recent call last):
  File "train_model_i3dnetvladclr.py", line 994, in <module>
    train_model()
  File "train_model_i3dnetvladclr.py", line 735, in train_model
    i3d_rgb_full.save('1.hdf5')
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/keras/engine/network.py", line 1152, in save
    save_model(self, filepath, overwrite, include_optimizer)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/keras/engine/saving.py", line 449, in save_wrapper
    save_function(obj, filepath, overwrite, *args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/keras/engine/saving.py", line 541, in save_model
    _serialize_model(model, h5dict, include_optimizer)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/keras/engine/saving.py", line 130, in _serialize_model
    model_config = json.dumps(model_config, default=get_json_type)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/keras/engine/saving.py", line 120, in get_json_type
    raise TypeError('Not JSON Serializable: %s' % (obj,))
TypeError: Not JSON Serializable: ?
terminate called without an active exception
Aborted (core dumped)
mazatov commented 2 years ago

Never mind, found the problem. I had a Reshape layer right before NetVlad that was causing this issue for some reason.