ValueError:不支持任何值。在keras中使用简单的自定义层训练网络

时间:2018-02-07 19:23:27

标签: keras keras-layer

我实现了一个非常简单的自定义图层。它只是将输入乘以权重。

当我尝试训练网络时,我得到ValueError: None values not supported.

我查看了None的输入和输出,但我找不到任何内容。 还试图在结果中添加偏见,但没有改变任何东西。 还尝试了不同的重量初始化器,但这没有任何效果。

当我构建模型并预测某些结果时,输出也没有任何None s

有人知道为什么训练会给出错误吗?

我正在使用Tensorflow 1.5和Keras 2.1.3

修改

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')

编辑2

该图层现在可用gist

我实际上想要计算周到的卷积,但它没有用,所以我试图返回temp(第53行),即使这样也行不通。

返回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.

0 个答案:

没有答案