- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试根据从 DataFrame 获取的数据训练 LSTM 网络。
这是代码:
x_lstm=x.to_numpy().reshape(1,x.shape[0],x.shape[1])
model = keras.models.Sequential([
keras.layers.LSTM(x.shape[1], return_sequences=True, input_shape=(x_lstm.shape[1],x_lstm.shape[2])),
keras.layers.LSTM(NORMAL_LAYER_SIZE, return_sequences=True),
keras.layers.LSTM(NORMAL_LAYER_SIZE),
keras.layers.Dense(y.shape[1])
])
optimizer=keras.optimizers.Adadelta()
model.compile(loss="mse", optimizer=optimizer)
for i in range(150):
history = model.fit(x_lstm, y)
save_model(model,'tmp.rnn')
ValueError: Data cardinality is ambiguous:
x sizes: 1
y sizes: 99
Please provide data which shares the same first dimension.
model = keras.models.Sequential([
keras.layers.LSTM(x.shape[1], return_sequences=True, input_shape=x_lstm.shape),
keras.layers.LSTM(NORMAL_LAYER_SIZE, return_sequences=True),
keras.layers.LSTM(NORMAL_LAYER_SIZE),
keras.layers.Dense(y.shape[1])
])
Input 0 of layer lstm_9 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: [None, 1, 99, 1200]
(99, 1200)
(99 个项目,每个项目有 1200 个特征,这只是一个更大的数据集的样本),y 的形状是
(99, 1)
最佳答案
如 Error
建议,First Dimension
的 X
和 y
是不同的。 First Dimension
表示 Batch Size
它应该是一样的。
请确保Y
还有shape
, (1, something)
.
我可以使用下面显示的代码重现您的错误:
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM
import tensorflow as tf
import numpy as np
# define sequences
sequences = [
[1, 2, 3, 4],
[1, 2, 3],
[1]
]
# pad sequence
padded = pad_sequences(sequences)
X = np.expand_dims(padded, axis = 0)
print(X.shape) # (1, 3, 4)
y = np.array([1,0,1])
#y = y.reshape(1,-1)
print(y.shape) # (3,)
model = Sequential()
model.add(LSTM(4, return_sequences=False, input_shape=(None, X.shape[2])))
model.add(Dense(1, activation='sigmoid'))
model.compile (
loss='mean_squared_error',
optimizer=tf.keras.optimizers.Adam(0.001))
model.fit(x = X, y = y)
Print
声明,
Shape of X is (1, 3, 4)
Shape of y is (3,)
y = y.reshape(1,-1)
,这使得
First Dimension
(
Batch_Size
) 等于 (
1
)
X
和
y
.
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM
import tensorflow as tf
import numpy as np
# define sequences
sequences = [
[1, 2, 3, 4],
[1, 2, 3],
[1]
]
# pad sequence
padded = pad_sequences(sequences)
X = np.expand_dims(padded, axis = 0)
print('Shape of X is ', X.shape) # (1, 3, 4)
y = np.array([1,0,1])
y = y.reshape(1,-1)
print('Shape of y is', y.shape) # (1, 3)
model = Sequential()
model.add(LSTM(4, return_sequences=False, input_shape=(None, X.shape[2])))
model.add(Dense(1, activation='sigmoid'))
model.compile (
loss='mean_squared_error',
optimizer=tf.keras.optimizers.Adam(0.001))
model.fit(x = X, y = y)
Shape of X is (1, 3, 4)
Shape of y is (1, 3)
1/1 [==============================] - 0s 1ms/step - loss: 0.2588
<tensorflow.python.keras.callbacks.History at 0x7f5b0d78f4a8>
关于python - 值错误 : Data cardinality is ambiguous,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62253289/
有人知道我该如何解决这个问题? CREATE OR REPLACE FUNCTION PRDLIB.COUNTER( sROWS INT) RETURNS TABLE ( ROW_ID INT) LA
我不太明白这个“不兼容的类型”错误(Delphi XE2) function TWaveBase.GetHandle: THandle; begin if HandleNeeded then be
我必须将 Cardinal 打包和解包为四个单字节字段(在 Delphi 2010 中)。 我正在对大图像的所有像素执行此操作,因此我需要速度快! 谁能告诉我如何编写这两个函数? (const 和 o
我这里有一个程序,它在 Delphi 3 中运行良好,我在 Turbo Delphi 2006 上编译并测试了它,发现了一个问题。问题是这样的:我使用“基数”数据类型作为某些内容的索引。它在 Delp
我正在尝试根据从 DataFrame 获取的数据训练 LSTM 网络。 这是代码: x_lstm=x.to_numpy().reshape(1,x.shape[0],x.shape[1]) model
我现在正在致力于将 Visual Basic 代码采用到 Delphi 代码中。 我有: // prepare query with oleClipboardFormat do be
如何读取和/或指定实体-关系-模型(Chen-Notation)的三元关系中的基数(最小/最大)? 例如:一位负责人与他的相关员工一起参观了多项资质。现在,我想知道如何在 Min-Max-Notati
本文整理了Java中com.ohmdb.filestore.ZonesImpl.cardinality()方法的一些代码示例,展示了ZonesImpl.cardinality()的具体用法。这些代码示
我目前正在学习计算机工程,我记得一个叫做信息系统导论类(class)的教授说,两个以 1:1 基数相关的类(class)是没有意义的。 例如:我有 Client类和 Telephone类(class)
我正在尝试创建一个具有多个输入分支的 keras 模型,但 keras 不喜欢输入具有不同的大小。 这是一个最小的例子: import numpy as np from tensorflow impo
我正在使用 d3 开发一个新项目,创建一个显示从 0 到 10 的分数的图表。数据如下所示: var data = [ {axis: 'People', value: getRandomSco
我的 df 看起来像这样,其中“O”是一年中的序数日期。 Close O Date 1950-01-03 16.66 3 1950-01-04 16.
您能否描述一下:术语“基数”与数据建模中的“关系”有何不同? 最佳答案 它们是完全不同的概念(有点像问算术中“加法”和“零”有什么区别),因此除了简单地建议查找它们的定义外,很难解释任何“差异”。 关
请帮助我进行回归测试,并确定以下代码在哪些 Delphi 版本中失败。 编辑: 我知道有一个编译器提示;事实上,在我继承的一个项目中发现它以某种方式关闭了编译器提示(我看到很多人这样做,因为他们认为编
program UInt32ToVariant; uses Vcl.Dialogs, System.SysUtils, System.Variants; var ui32Val: Cardin
我正在尝试在我的应用程序中实现 Songbird.js 文件。我可以看到 cardinal.continue 方法不会单独在 IE11 中触发。我收到以下错误。 我在框架级别本身收到以下错误。 SCR
Common Lisp 提供了可爱的 ~r 指令来打印基数英文数字。例如: (format nil "~r" 27) -> "twenty-seven" lisp 是否提供相反的指令(或某些库函数),
我在我的数据库中创建了一个外键关系,这样我就可以在这种情况下将另一个表作为属性访问 House.Area 现在,如果我创建一个 House 对象并将 Area 设为 null,我会在 SubmitCh
我有一个学院的数据库。它的结构有三个表:- 第一个是学科硕士。该表可能有 20 多行。 CREATE TABLE `SUBJECTS` ( `ID_SB` tinyint(4) NOT NULL
在Delphi中,LongInt和Integer、LongWord和Cardinal有什么区别? 有时我会发现DWORD的用法,它是什么? 它们在所有版本的 Delphi 中都是一致的吗?我应该坚持哪
我是一名优秀的程序员,十分优秀!