tensorflow keras conv1d:ValueError:len(dilation_rate)= 1但应为-1

时间:2018-10-01 11:48:21

标签: tensorflow keras convolution

我尝试使用tensorflow作为后端构建自定义Keras正则化。 执行以下代码会给我一个例外:

import tensorflow as tf
from tensorflow import keras    
inputs = keras.Input(shape=(10,))
x  = keras.backend.conv1d(inputs, tf.constant([-1,1]), padding = 'same', dilation_rate=None)


 x  = keras.backend.conv1d(inputs, tf.constant([-1,1]), padding = 'same', dilation_rate=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/arthur/miniconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/keras/backend.py", line 3775, in conv1d
    data_format=tf_data_format)
  File "/home/arthur/miniconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/nn_ops.py", line 779, in convolution
    data_format=data_format)
  File "/home/arthur/miniconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/nn_ops.py", line 842, in __init__
    num_spatial_dims, strides, dilation_rate)
  File "/home/arthur/miniconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/nn_ops.py", line 625, in _get_strides_and_dilation_rate
    (len(dilation_rate), num_spatial_dims))
ValueError: len(dilation_rate)=1 but should be -1

我不明白我在做什么错。

谢谢。

1 个答案:

答案 0 :(得分:0)

我认为问题出在tf.constant([-1,1])中。这是内核的地方,应具有input_length,in_channel,out_channel之类的尺寸。