在this方法的基础上,尝试建立具有连续变量和范畴变量的神经网络模型。
连续占位符以下列形式显示:
x = tf.placeholder(tf.float32, [None,num_steps, input_size], name="input_x")`
And the categorical data placeholder is in this form:
store, v_store = len(np.unique(data_df.Store.values)), 50
z_store = tf.placeholder(tf.int32, [None, num_steps], name='Store')
emb_store = tf.Variable(
tf.random_uniform((store, v_store), -r_range, r_range),
name="store"
)
embed_store = tf.nn.embedding_lookup(emb_store, z_store)最后,我将分类占位符和连续占位符连接在一起。
inputs_with_embed = tf.concat([x, embed_store], axis=2, name="inputs_with_embed")这是我把张量向量乘以最后一层的地方。
val = tf.transpose(val, [1, 0, 2])
last = tf.gather(val, int(val.get_shape()[0]) - 1, name="lstm_state")
ws = tf.Variable(tf.truncated_normal([lstm_size, input_size]), name="w")
bias = tf.Variable(tf.constant(0.1, shape=[input_size]), name="b")编辑:所有的tensorflow图形代码运行良好。但是,当我执行会话代码时,我得到了以下错误:
InvalidArgumentError (see above for traceback): Incompatible shapes: [50,4] vs. [50,7,1]
[[Node: sub = Sub[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](add, _arg_input_y_0_4)]]还有我的预测部分。
loss = tf.reduce_mean(tf.square(pred - y), name="loss_mse_train")编辑端
有人能告诉我我在哪里犯的错误吗?
谢谢!
发布于 2019-03-02 07:33:06
正如我所说的,如果您想为每个时间步骤提供一个预测值,则应该将ws更改为[lstm_size, 7],将bias更改为[7]。
ws = tf.Variable(tf.truncated_normal([lstm_size, 7]), name="w")
bias = tf.Variable(tf.constant(0.1, shape=[7]), name="b")
# need to change shape when pred=(?,7) and y=(?,7,1)
loss = tf.reduce_mean(tf.square(pred - tf.squeeze(y)), name="loss_mse_train")https://stackoverflow.com/questions/54955614
复制相似问题