keras,无效的预测大小

巴图汉·MERTAN

我在喀拉拉邦很新,我已经用输入和输出的(100,8)大小训练了它,我想用1 * 8的预测数据来输出1 * 8。例如输入我输入1 * 8。代码返回,1 * 8输出数据。

这是我的代码:

from tensorflow import keras
import numpy as np
import tensorflow as tf

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation 
import keras
from keras.layers import Input, Dense
accuracy = tf.keras.metrics.CategoricalAccuracy()
import numpy as np

xs=np.ones((100,8))
ys=np.ones((100,8))

for i in range(100):
    xs[i]*=np.random.randint(30, size=8)  
    ys[i]=xs[i]*2

xs=xs.reshape(1,100,8)   
ys=ys.reshape(1,100,8)   
# model = tf.keras.Sequential([layers.Dense(units=1, input_shape=[2,4])])
model = Sequential() 
model.add(Dense(10,input_shape=[100,8])) 


model.add(Activation('relu'))
model.add(Dropout(0.15))
model.add(Dense(10)) 
model.add(Activation('relu')) 
# model.add(Dropout(0.5))
model.add(Dense(8)) 

model.compile(optimizer='adam', loss='mean_squared_error',metrics=['accuracy'] )

model.fit(xs, ys, epochs=1000, batch_size=100)

p= np.array([[1,3,4,5,9,2,3,4]]).reshape(1,1,8)

print(model.predict(p))

马克·塞里亚尼

您无需在数据的第一个位置添加一个维度。对于2D网络,您只需向模型中提供以下格式的数据即可:(n_sample,n_features)

这里是完整的例子

xs=np.ones((100,8))
ys=np.ones((100,8))

for i in range(100):
    xs[i]*=np.random.randint(30, size=8)  
    ys[i]=xs[i]*2

xs=xs.reshape(100,8)   
ys=ys.reshape(100,8)   

model = Sequential() 
model.add(Dense(10,input_shape=(8,))) 
model.add(Activation('relu'))
model.add(Dropout(0.15))
model.add(Dense(10)) 
model.add(Activation('relu')) 
model.add(Dense(8)) 

model.compile(optimizer='adam', loss='mean_squared_error')

model.fit(xs, ys, epochs=10, batch_size=100)

p = np.array([[1,3,4,5,9,2,3,4]]) # (1, 8)

pred = model.predict(p)

print(pred)
print(pred.shape) # (1, 8)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

tensorflow keras无法在预测阶段退出(设置学习阶段无效)

来自分类Dev

为什么预测需要Keras中的批量大小?

来自分类Dev

Keras预测新形象

来自分类Dev

覆盖 keras 预测功能

来自分类Dev

Keras中的预测流输出

来自分类Dev

Keras在Multiprosses Pool中预测

来自分类Dev

Tensorflow和Keras预测阈值

来自分类Dev

MLP Keras预测的循环程序

来自分类Dev

Keras LSTM随序列预测

来自分类Dev

使用当前无效的输入数据进行预测

来自分类Dev

Keras FFT层无效

来自分类Dev

Keras:体重分享无效

来自分类Dev

realloc()无效的旧大小

来自分类Dev

Java无效的数组大小

来自分类Dev

glEnableVertexArrayAttrib抛出无效大小

来自分类Dev

C ++向量的大小无效

来自分类Dev

Keras / Tensorflow预测:数组形状错误

来自分类Dev

在keras序列数据做预测与RNN

来自分类Dev

Keras CNN可以预测多个类别吗?

来自分类Dev

Keras模型预测相同类别

来自分类Dev

Keras预测精度与拟合结果不匹配

来自分类Dev

Keras的输出顺序预测_生成器

来自分类Dev

Keras预测精度与训练精度不匹配

来自分类Dev

在 Keras 中预测和评估指标

来自分类Dev

使用 keras 进行时间序列预测

来自分类Dev

Keras - 使用 LSTM 进行模式预测

来自分类Dev

使用 Keras 使用 LSTM 进行预测

来自分类Dev

在 keras 中预测单个文档的文档类

来自分类Dev

Keras 预测每次都返回相同的结果