input_image = Input(shape=(30, 30)) dropout1 = Dropout(0.25)(input_image) dense1 = Dense(4096, input_shape=(30, 30))(dropout1) bn1 = BatchNormalization(momentum=0.93, axis=-1)(dense1) dropout2 = Dropout(0.25)(bn1) dense2 = Dense(4096, activation='relu')(dropout2) bn2 = BatchNormalization(momentum=0.93, axis=-1)(dense2) dropout3 = Dropout(0.25)(bn2) dense3 = Dense(35, activation='relu')(dropout3) input_numeric = Input(shape=(30,30)) concat = concatenate((input_numeric.numpy(), dense3.numpy()), axis=1) 中报错'Tensor' object has no attribute 'numpy' 如何解决
时间: 2023-09-13 09:03:48 浏览: 136
Tensorflow中的dropout的使用方法
在代码中,`input_numeric`和`dense3`都是Tensor对象,而Tensor对象没有`numpy`属性。你需要使用`K.concatenate()`代替`concatenate()`,并将`input_numeric`和`dense3`作为参数传递给`K.concatenate()`。修改后的代码如下:
```
import keras.backend as K
input_image = Input(shape=(30, 30))
dropout1 = Dropout(0.25)(input_image)
dense1 = Dense(4096, input_shape=(30, 30))(dropout1)
bn1 = BatchNormalization(momentum=0.93, axis=-1)(dense1)
dropout2 = Dropout(0.25)(bn1)
dense2 = Dense(4096, activation='relu')(dropout2)
bn2 = BatchNormalization(momentum=0.93, axis=-1)(dense2)
dropout3 = Dropout(0.25)(bn2)
dense3 = Dense(35, activation='relu')(dropout3)
input_numeric = Input(shape=(30,30))
concat = K.concatenate([input_numeric, dense3], axis=2)
```
这样就不会出现上述报错了。
阅读全文