3

我正在尝试在调制https://github.com/radioML/examples/blob/master/modulation_recognition/RML2016.10a_VTCNN2_example.ipynb上执行此示例笔记本

执行此操作后

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D , Reshape , ZeroPadding2D,BatchNormalization
from tensorflow.keras.callbacks import EarlyStopping


model = Sequential()

model.add(Reshape([1]+in_shp, input_shape=in_shp))

model.add(ZeroPadding2D((0, 2), data_format="channels_first"))
model.add(Conv2D(256, (1,3), data_format="channels_first"))
model.add(Dropout(0.5))

model.add(ZeroPadding2D((0, 1), data_format="channels_first"))
model.add(Conv2D(80, (2 ,3), data_format="channels_first" , activation="relu"))

model.add(Dropout(0.5))

model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))

model.add(Dense(len(classes) , activation='softmax'))
model.add(Activation('softmax'))
model.add(Reshape([len(classes)]))

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

我明白了

Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
reshape_7 (Reshape)          (None, 1, 2, 128)         0         
_________________________________________________________________
zero_padding2d_8 (ZeroPaddin (None, 1, 2, 132)         0         
_________________________________________________________________
conv2d_8 (Conv2D)            (None, 256, 2, 130)       1024      
_________________________________________________________________
dropout_10 (Dropout)         (None, 256, 2, 130)       0         
_________________________________________________________________
zero_padding2d_9 (ZeroPaddin (None, 256, 2, 132)       0         
_________________________________________________________________
conv2d_9 (Conv2D)            (None, 80, 1, 130)        122960    
_________________________________________________________________
dropout_11 (Dropout)         (None, 80, 1, 130)        0         
_________________________________________________________________
flatten_3 (Flatten)          (None, 10400)             0         
_________________________________________________________________
dense_6 (Dense)              (None, 256)               2662656   
_________________________________________________________________
dropout_12 (Dropout)         (None, 256)               0         
_________________________________________________________________
dense_7 (Dense)              (None, 11)                2827      
_________________________________________________________________
activation_3 (Activation)    (None, 11)                0         
_________________________________________________________________
reshape_8 (Reshape)          (None, 11)                0         
=================================================================
Total params: 2,789,467
Trainable params: 2,789,467
Non-trainable params: 0
_________________________________________________________________

然后当我运行这个

model_fit(model, X_train, Y_train, test_idx)

我收到此错误

**InvalidArgumentError:  Conv2DCustomBackpropInputOp only supports NHWC.**
     [[node Conv2DBackpropInput (defined at <ipython-input-17-9cd1191bc59a>:3) ]] [Op:__inference_distributed_function_3032]

Function call stack:
distributed_function

当我在其他机器上运行相同的代码时,它可以工作。所以我卸载了 anaconda、Keras、TensorFlow 并重新安装了所有东西。

inp_shp = [2, 128]
X_train.shape = (110000, 2, 128)
4

1 回答 1

1

NHWC 代表Num_samples x Height x Width x Channels

你有,但如果你有灰度图像并且如果它们是 RGB 图像X_train.shape = (110000, 2, 128),你应该传递给模型的应该是这种形状。你也应该改变。X_train.shape = (110000, 2, 128, 1)X_train.shape = (110000, 2, 128, 3)inp_shape

于 2020-03-06T01:20:17.833 回答