larsklein

keras batchnorm weights problem

Jul 8th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.12 KB | None | 0 0
  1. ---------------------------------------------------------------------------
  2. InvalidArgumentError                      Traceback (most recent call last)
  3. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
  4.     670           graph_def_version, node_def_str, input_shapes, input_tensors,
  5. --> 671           input_tensors_as_shapes, status)
  6.     672   except errors.InvalidArgumentError as err:
  7.  
  8. /usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
  9.      65             try:
  10. ---> 66                 next(self.gen)
  11.      67             except StopIteration:
  12.  
  13. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status()
  14.     465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
  15. --> 466           pywrap_tensorflow.TF_GetCode(status))
  16.     467   finally:
  17.  
  18. InvalidArgumentError: Shapes must be equal rank, but are 1 and 0 for 'batch_normalization_3/Assign' (op: 'Assign') with input shapes: [16], [].
  19.  
  20. During handling of the above exception, another exception occurred:
  21.  
  22. ValueError                                Traceback (most recent call last)
  23. <ipython-input-8-51a83b4ec6c0> in <module>()
  24.      17     elif type(old_layer) == BatchNormalization:
  25.      18         bn_layer = BatchNormalization(weights=weights)
  26. ---> 19         prev_layer = bn_layer(prev_layer)
  27.  
  28. /usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs)
  29.     574                 # Load weights that were specified at layer instantiation.
  30.     575                 if self._initial_weights is not None:
  31. --> 576                     self.set_weights(self._initial_weights)
  32.     577
  33.     578             # Raise exceptions in case the input is not compatible
  34.  
  35. /usr/local/lib/python3.5/dist-packages/keras/engine/topology.py in set_weights(self, weights)
  36.    1190                                  'provided weight shape ' + str(w.shape))
  37.    1191             weight_value_tuples.append((p, w))
  38. -> 1192         K.batch_set_value(weight_value_tuples)
  39.    1193
  40.    1194     def get_weights(self):
  41.  
  42. /usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py in batch_set_value(tuples)
  43.    2182                 assign_placeholder = tf.placeholder(tf_dtype,
  44.    2183                                                     shape=value.shape)
  45. -> 2184                 assign_op = x.assign(assign_placeholder)
  46.    2185                 x._assign_placeholder = assign_placeholder
  47.    2186                 x._assign_op = assign_op
  48.  
  49. /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variables.py in assign(self, value, use_locking)
  50.     510       the assignment has completed.
  51.     511     """
  52. --> 512     return state_ops.assign(self._variable, value, use_locking=use_locking)
  53.    513
  54.    514   def assign_add(self, delta, use_locking=False):
  55.  
  56. /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/state_ops.py in assign(ref, value, validate_shape, use_locking, name)
  57.    268     return gen_state_ops.assign(
  58.    269         ref, value, use_locking=use_locking, name=name,
  59. --> 270         validate_shape=validate_shape)
  60.    271   return ref.assign(value, name=name)
  61.  
  62. /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_state_ops.py in assign(ref, value, validate_shape, use_locking, name)
  63.     45   result = _op_def_lib.apply_op("Assign", ref=ref, value=value,
  64.     46                                 validate_shape=validate_shape,
  65. ---> 47                                 use_locking=use_locking, name=name)
  66.     48   return result
  67.     49
  68.  
  69. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
  70.    766         op = g.create_op(op_type_name, inputs, output_types, name=scope,
  71.    767                          input_types=input_types, attrs=attr_protos,
  72. --> 768                          op_def=op_def)
  73.    769         if output_structure:
  74.    770           outputs = op.outputs
  75.  
  76. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device)
  77.   2336                     original_op=self._default_original_op, op_def=op_def)
  78.   2337     if compute_shapes:
  79. -> 2338       set_shapes_for_outputs(ret)
  80.   2339     self._add_op(ret)
  81.   2340     self._record_op_seen_by_control_dependencies(ret)
  82.  
  83. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in set_shapes_for_outputs(op)
  84.   1717       shape_func = _call_cpp_shape_fn_and_require_op
  85.   1718
  86. -> 1719   shapes = shape_func(op)
  87.   1720   if shapes is None:
  88.   1721     raise RuntimeError(
  89.  
  90. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in call_with_requiring(op)
  91.   1667
  92.   1668   def call_with_requiring(op):
  93. -> 1669     return call_cpp_shape_fn(op, require_shape_fn=True)
  94.   1670
  95.   1671   _call_cpp_shape_fn_and_require_op = call_with_requiring
  96.  
  97. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in call_cpp_shape_fn(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
  98.    608     res = _call_cpp_shape_fn_impl(op, input_tensors_needed,
  99.    609                                   input_tensors_as_shapes_needed,
  100. --> 610                                   debug_python_shape_fn, require_shape_fn)
  101.    611     if not isinstance(res, dict):
  102.    612       # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op).
  103.  
  104. /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
  105.    674       missing_shape_fn = True
  106.    675     else:
  107. --> 676       raise ValueError(err.message)
  108.    677
  109.    678   if missing_shape_fn:
  110.  
  111. ValueError: Shapes must be equal rank, but are 1 and 0 for 'batch_normalization_3/Assign' (op: 'Assign') with input shapes: [16], [].
Add Comment
Please, Sign In to add comment