'ValueError: The two structures don't have the same sequence length

Recently I tried to convert mask rcnn in this repository from tensorflow 1 to tensorflow 2.

After re-writing the codes and when I run sample "shape" and execute code

model.train(dataset_train, dataset_val, learning_rate=config.LEARNING_RATE, epochs=1, layers='heads')

I got this ValueError

(ValueError: The two structures don't have the same sequence length. Input structure has length 0, while shallow structure has length 14.)

and don't know how to fix it.

I noticed that the output of this model has 14 elements in model.build() in model.py.

I uploaded my project to this repo. The whole structure is the same as the original repo above, I just separated different parts of this model into different files and review them two times to check typing problems. I cannot certainly say this problem is not caused by typing problem which I cannot find any currently.

Below is the whole error info:

Traceback (most recent call last):

File "/Users/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 1, in
runfile('/Users/PycharmProjects/Mask-Dence-Cap-R-CNN/Project/samples/test.py', wdir='/Users/PycharmProjects/Mask-Dence-Cap-R-CNN/Project/samples')

File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script

File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)

File "/Users/PycharmProjects/Mask-Dence-Cap-R-CNN/Project/samples/test.py", line 260, in
layers='heads')

File "/Users/PycharmProjects/Mask-Dence-Cap-R-CNN/Project/model.py", line 585, in train
use_multiprocessing=True,

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 108, in _method_wrapper
return method(self, *args, **kwargs)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 1098, in fit
tmp_logs = train_function(iterator)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 780, in call
result = self._call(*args, **kwds)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 823, in _call
self._initialize(args, kwds, add_initializers_to=initializers)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 697, in _initialize
*args, **kwds))

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 2855, in _get_concrete_function_internal_garbage_collected
graph_function, _, _ = self._maybe_define_function(args, kwargs)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 3213, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 3075, in _create_graph_function
capture_by_value=self._capture_by_value),

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py", line 600, in wrapped_fn
return weak_wrapped_fn().wrapped(*args, **kwds)

File "/Users/.local/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py", line 973, in wrapper
raise e.ag_error_metadata.to_exception(e)


ValueError: in user code:

/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:806 train_function *
return step_function(self, iterator)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:796 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))

/Users/.local/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:1211 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2652 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:3012 _call_for_each_replica
return fn(*args, **kwargs)

/Users.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:789 run_step **
outputs = model.train_step(data)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:759 train_step
self.compiled_metrics.update_state(y, y_pred, sample_weight)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:388 update_state
self.build(y_pred, y_true)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:319 build
self._metrics, y_true, y_pred)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1139 map_structure_up_to
**kwargs)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1221 map_structure_with_tuple_paths_up_to
expand_composites=expand_composites)

/Users/.local/lib/python3.6/site-packages/tensorflow/python/util/nest.py:854 assert_shallow_structure
input_length=len(input_tree), shallow_length=len(shallow_tree)))

ValueError: The two structures don't have the same sequence length. Input structure has length 0, while shallow structure has length 14.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source