问题
I've implemented a very simple custom layer. It just multiplies the input by a weight.
When I try to train the network I get ValueError: None values not supported.
I checked my input and output for Nones but I couldn't find anything.
Also tried to add bias to the result but didn't change anything.
Also tried different weight initializers but this didn't have any effect.
When I just build the model and predict some results it works, also the output doesn't have any Nones
Has anyone an idea why training gives the error?
I'm using Tensorflow 1.5 and Keras 2.1.3
Edit
def call(self, x, mask=None):
#shape of x = (batch_size, n, em_dim)
return K.dot(x, self.W)
def build(self, input_shape):
self.em_dim = input_shape[2]
self.W = self.add_weight(shape=(self.em_dim, self.em_dim), dtype=K.floatx(), name='weight', trainable=True, initializer='uniform')
Edit 2
The layer is now available as gist.
I actually want to compute attentive convolution but it didn't work so I tried to return temp (line 53) and even that doesn't work.
Traceback of the error returning temp:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1668, in <module>
main()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1662, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1072, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/simons/dev/workspaces/germEval/Bachelorarbeit_GermEval2017/TestOutputs.py", line 123, in <module>
test_attentive_conv()
File "/Users/simons/dev/workspaces/germEval/Bachelorarbeit_GermEval2017/TestOutputs.py", line 104, in test_attentive_conv
model.fit([x], [y])
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/keras/engine/training.py", line 1646, in fit
self._make_train_function()
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/keras/engine/training.py", line 970, in _make_train_function
loss=self.total_loss)
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/keras/optimizers.py", line 174, in get_updates
v = self.momentum * m - lr * g # velocity
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 775, in _run_op
return getattr(ops.Tensor, operator)(a._AsTensor(), *args)
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 898, in binary_op_wrapper
y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 932, in convert_to_tensor
as_ref=False)
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 233, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 212, in constant
value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/Users/simons/anaconda/envs/absa-3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 401, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.
来源:https://stackoverflow.com/questions/48671745/valueerror-none-values-not-supported-training-network-with-simple-custom-layer