Keras LSTM尝试创建模型架构时出现多个错误 [英] Keras LSTM multiple errors from trying to create model architecture

查看:75
本文介绍了Keras LSTM尝试创建模型架构时出现多个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我今天早些时候发布的重复问题,在另一个问题中,我使用的是Keras的旧版本.我已经升级到Keras 2.0.0,但仍然遇到很多错误,这些错误是我自己无法解决的,因此我将问题逐字地重新发布.

This is a duplicate Question that i posted earlier today, in the other question i was using an old version of Keras. I've upgraded to Keras 2.0.0 and still was getting a lot of errors that i can't figure out on my own so i'm reposting the question mostly verbatim.

我试图了解如何使用keras进行供应链预测,并且不断收到我无法在其他地方找到帮助的错误.我曾尝试做类似的教程.太阳黑子预测教程,污染多变量教程等,但我仍然不了解input_shape参数的工作方式或如何组织我的数据以使其被喀拉拉河接受.

I am trying to understand how to use keras for supply chain forecasting and i keep getting errors that i can't find help for elsewhere. I've tried to do similar tutorials; sunspot forecasting tutorial, pollution multivariate tutorial etc but i'm still not understanding how the input_shape argument works or how to organize my data to get it to be accepted by keras.

我的数据集是一个单一的时间序列,描述了我们每月销售的产品数量.我采用了一个单一的时间序列(107个月),并将其转换为30行,77列的数据集.我从中创建了一个训练集和测试集.

My dataset is a single time series describing the number of products we sold every month. I took that single time series, 107 months, and turned it into a 30 row, 77 column data set. I created a training set and test set from that.

在命令提示符下:

Successfully uninstalled Keras-1.2.0
Successfully installed keras-2.0.0

Python Version: 3.5.4

这是我得到的代码和相应的错误.

Here's the code and respective errors i'm getting.

model = Sequential()
model.add(LSTM(input_shape=(77, 1), output_dim = 10))

跟踪

C:\Python35\lib\site-packages\keras\backend\tensorflow_backend.py in concatenate(tensors, axis)
   1219         A tensor.
-> 1220     """
   1221     zero = _to_tensor(0., x.dtype.base_dtype)

AttributeError: module 'tensorflow' has no attribute 'concat_v2'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-42-ee393fff874d> in <module>()
      1 model = Sequential()
----> 2 model.add(LSTM(input_shape=(77, 1), output_dim = 10))
      3 #model.add(Dense(10, activation = 'relu'))
      4 #model.add(Dense(1, activation = 'softmax'))

C:\Python35\lib\site-packages\keras\models.py in add(self, layer)
    292                         '`Sequential.from_config(config)`?')
    293     return layer_module.deserialize(config, custom_objects=custom_objects)
--> 294 
    295 
    296 def model_from_yaml(yaml_string, custom_objects=None):

C:\Python35\lib\site-packages\keras\engine\topology.py in create_input_layer(self, batch_input_shape, input_dtype, name)
    396 
    397             # Check ndim.
--> 398             if spec.ndim is not None:
    399                 if K.ndim(x) != spec.ndim:
    400                     raise ValueError('Input ' + str(input_index) +

C:\Python35\lib\site-packages\keras\engine\topology.py in __call__(self, x, mask)
    541             # Handle automatic shape inference (only useful for Theano).
    542             input_shape = _collect_input_shape(inputs)
--> 543 
    544             # Actually call the layer, collecting output(s), mask(s), and shape(s).
    545             output = self.call(inputs, **kwargs)

C:\Python35\lib\site-packages\keras\layers\recurrent.py in build(self, input_shape)
    761             constants.append(dp_mask)
    762         else:
--> 763             constants.append([K.cast_to_floatx(1.) for _ in range(3)])
    764 
    765         if 0 < self.recurrent_dropout < 1:

C:\Python35\lib\site-packages\keras\backend\tensorflow_backend.py in concatenate(tensors, axis)
   1220     """
   1221     zero = _to_tensor(0., x.dtype.base_dtype)
-> 1222     inf = _to_tensor(np.inf, x.dtype.base_dtype)
   1223     x = tf.clip_by_value(x, zero, inf)
   1224     return tf.sqrt(x)

C:\Python35\lib\site-packages\tensorflow\python\ops\array_ops.py in concat(values, axis, name)
   1041       ops.convert_to_tensor(axis,
   1042                             name="concat_dim",
-> 1043                             dtype=dtypes.int32).get_shape(
   1044                             ).assert_is_compatible_with(tensor_shape.scalar())
   1045       return identity(values[0], name=scope)

C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py in convert_to_tensor(value, dtype, name, preferred_dtype)
    674       name=name,
    675       preferred_dtype=preferred_dtype,
--> 676       as_ref=False)
    677 
    678 

C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype)
    739 
    740         if ret is None:
--> 741           ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
    742 
    743         if ret is NotImplemented:

C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
    111                                          as_ref=False):
    112   _ = as_ref
--> 113   return constant(v, dtype=dtype, name=name)
    114 
    115 

C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py in constant(value, dtype, shape, name, verify_shape)
    100   tensor_value = attr_value_pb2.AttrValue()
    101   tensor_value.tensor.CopyFrom(
--> 102       tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
    103   dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)
    104   const_tensor = g.create_op(

C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
    372       nparray = np.empty(shape, dtype=np_dt)
    373     else:
--> 374       _AssertCompatible(values, dtype)
    375       nparray = np.array(values, dtype=np_dt)
    376       # check to them.

C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py in _AssertCompatible(values, dtype)
    300     else:
    301       raise TypeError("Expected %s, got %s of type '%s' instead." %
--> 302                       (dtype.name, repr(mismatch), type(mismatch).__name__))
    303 
    304 

TypeError: Expected int32, got <tf.Variable 'lstm_7_W_i:0' shape=(1, 10) dtype=float32_ref> of type 'Variable' instead.

推荐答案

我认为问题在于TF版本. Keras和TF之间的版本兼容性是任何人都可能遇到的问题,因为TF API在短时间内会发生很大变化.

I think that the problem goes around TF version. Version compatibility between Keras and TF is a problem that probably anyone has faced, as TF API changes a lot in a small period of time.

我认为对于Keras 2.2.X,您需要TF版本> 1.10.X

I think that for Keras 2.2.X you need a TF version > 1.10.X

尝试更新它,看看问题是否已解决!

Try updating it and see if the problem is fixed!

这篇关于Keras LSTM尝试创建模型架构时出现多个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆