简体   繁体   English

输入与图层不兼容 - Tensorflow

[英]Input incompatible with layers - Tensorflow

I'm currently facing a problem with Tensorflow library that I couldn't resolve.我目前面临 Tensorflow 库的问题,我无法解决。 All solutions I've already found on stackoverflow didn't help me understanding the real problem.我已经在 stackoverflow 上找到的所有解决方案都没有帮助我理解真正的问题。

def build_model(dim_data, n_neurons):

model = tf.keras.Sequential(name="Reseau_de_neurones")

model.add(layers.Dense(units = n_neurons, input_shape=(3, 1), bias_initializer="glorot_uniform")) 
model.add(layers.ReLU())
model.add(layers.Dense(units = n_neurons, input_shape=(dim_data,), bias_initializer="glorot_uniform")) 
model.add(layers.ReLU())
model.add(layers.Dense(units = n_neurons, input_shape=(dim_data,),  bias_initializer="glorot_uniform")) 
model.add(layers.ReLU())
model.add(layers.Dense(units = n_neurons, input_shape=(dim_data,), bias_initializer="glorot_uniform")) 
model.add(layers.ReLU())
model.add(layers.Dense(units = dim_data - 1, bias_initializer="glorot_uniform")) 

return model

Then I build my NN:然后我构建我的神经网络:

model = build_model(dim_data=3, n_neurons=10)

I then define a training step:然后我定义一个训练步骤:

def train_step(model):

   with tf.GradientTape() as tape:
    pos = [0,0]
    controle_actuel = model(np.array([0,pos[0],pos[1]]))
    loss_value = loss
   gradients = tape.gradient(loss_value, model.trainable_variables)
   return loss_value, gradients

When I try this function, I get this error当我尝试这个 function 时,我得到了这个错误

input 0 of layer "dense_37" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (3,)

Could you please help me?请你帮助我好吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow Conv2D 层 input_shape 配置错误:ValueError: Input 0 of layer "sequential" is in compatible with the layer: - Tensorflow Conv2D layers input_shape configuration error: ValueError: Input 0 of layer "sequential" is incompatible with the layer: 输入形状总是与图层不兼容 - Input shapes always incompatible with layers Tensorflow 输入形状不兼容 - Tensorflow Input Shapes Incompatible Keras / Tensorflow输入到RNN层 - Keras/Tensorflow Input to RNN layers 输入层与 TensorFlow 2D CNN 不兼容 - Input Layer Incompatible with Tensorflow 2D CNN ValueError: TensorFlow2 Input 0 is in compatible with layer model - ValueError: TensorFlow2 Input 0 is incompatible with layer model TensorFlow ValueError:层顺序的输入0与层不兼容 - TensorFlow ValueError: Input 0 of layer sequential is incompatible with the layer Tensorflow 值错误:输入与层不兼容 - Tensorflow Value Error: Input is incompatible with the layer tensorflow GradientDescentOptimizer:运算输入和计算的输入梯度之间的形状不兼容 - tensorflow GradientDescentOptimizer: Incompatible shapes between op input and calculated input gradient 我尝试使用功能 API 在 tensorflow 2.x 中创建 model,但出现 LSTM 层不兼容错误 - I tried to create model in tensorflow 2.x using functional API, but got LSTM layers incompatible error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM