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

model.load_weight(path, by_name=True) throws error for Xception model #25

Closed
AnishShah opened this issue Nov 26, 2016 · 2 comments
Closed

Comments

@AnishShah
Copy link

I was trying to use Xception model for fine-tuning and came across this error.

How to reproduce this error?

  1. In xception.py file, just change model.load_weights(weights_path) to model.load_weights(weights_path, by_name=True) and run. You will get the following traceback.
Traceback (most recent call last):
  File "xception.py", line 227, in <module>
    model = Xception(include_top=True, weights='imagenet')
  File "xception.py", line 212, in Xception
    model.load_weights(weights_path, by_name=True)
  File "/home/anish/env/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/engine/topology.py", line 2498, in load_weights
    self.load_weights_from_hdf5_group_by_name(f)
  File "/home/anish/env/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/engine/topology.py", line 2633, in load_weights_from_hdf5_group_by_name
    K.batch_set_value(weight_value_tuples)
  File "/home/anish/env/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/backend/tensorflow_backend.py", line 990, in batch_set_value
    assign_op = x.assign(assign_placeholder)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/ops/variables.py", line 555, in assign
    return state_ops.assign(self._variable, value, use_locking=use_locking)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_state_ops.py", line 47, in assign
    use_locking=use_locking, name=name)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op
    op_def=op_def)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2261, in create_op
    set_shapes_for_outputs(ret)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1636, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1570, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/home/anish/env/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 643, in call_cpp_shape_fn
    raise ValueError(err.message)
ValueError: Dimension 0 in both shapes must be equal, but are 1 and 3 for 'Assign' (op: 'Assign') with input shapes: [1,1,64,128], [3,3,3,32].

Workaround:

base_model = Xception(include_top=True, weights='imagenet')
model = Model(input=base_model.input, output=<fine-tune model>)

@yshean
Copy link

yshean commented Mar 30, 2017

For me it is solved by setting K.set_image_data_format('channels_last'), since the problem was that the channel axis was mixed up. But it might not work for your case.

@guilhermeh2m
Copy link

guilhermeh2m commented Jul 19, 2018

It works for me

@AnishShah AnishShah closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
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