question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSD7 saving and loading weights error

See original GitHub issue

Thanks for making this available, I particularly appreciate the easy to use data generation augmentation facilities for scaling, cropping, resizing, etc.

I’ve just followed the ssd7_training jupyter notebook for setting up a fast-training SSD, and after completing a training run, I simply try to save the model weights and then reload them:

>>> model.save('trained-model.h5')
>>> model2 = load_model('trained-model.h5', custom_objects={'AnchorBoxes':AnchorBoxes, 
                                                            'compute_loss':ssd_loss.compute_loss})

But, model.load_weights does work.

I get the following error message when trying to load:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/josh.robinson/anaconda3/lib/python3.6/site-packages/keras/models.py", line 274, in load_model
    sample_weight_mode=sample_weight_mode)
  File "/home/josh.robinson/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 830, in compile
    sample_weight, mask)
  File "/home/josh.robinson/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 429, in weighted
    score_array = fn(y_true, y_pred)
  File "/home/josh.robinson/ssd_keras-master/keras_loss_function/keras_ssd_loss.py", line 125, in compute_loss
    self.neg_pos_ratio = tf.constant(self.neg_pos_ratio)
  File "/home/josh.robinson/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 102, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/home/josh.robinson/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 374, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/home/josh.robinson/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 299, in _AssertCompatible
    raise TypeError("List of Tensors when single Tensor expected")
TypeError: List of Tensors when single Tensor expected

Any ideas?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mke21commented, Jun 15, 2018

It happens when you load the model for a second time. K.clear_session() doesn’t seem to work with me. Restarting the kernel gives you another chance.

0reactions
mraduldubeycommented, Dec 5, 2019

@mke21 @hgasimov What if you have to load two models at a time ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in loading the model with load_weights in Keras
You are saving the weights, not the whole model. A Model is more than just the weights, including architecture, losses, metrics and etc....
Read more >
Save and load a model using a distribution strategy
This tutorial demonstrates how you can save and load models in a SavedModel format with tf.distribute.Strategy during or after training.
Read more >
Save and Load a Model with TensorFlow's Keras API
We can verify that the loaded model has the same architecture and weights as the saved model by calling summary() and get_weights ()...
Read more >
Saving and Loading Tensorflow Model Results in Keras Error
To save the weights, I use the following function appended with my model file path above it. # Create a path for the...
Read more >
Towards Fire Identification Model in Satellite Images Using ...
... is a crucial problem to resolve with High Performance Computing (HPC) ... computational load, useful to be deployed on embedded systems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found