我试图将keras_contrib中的Densenet用于我自己的尺寸为(30k,2,96,96)
的数据。
无法将这种实现方式与我的形状数据一起使用?它给出以下错误和警告。
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, 96, 96, 2) 0
__________________________________________________________________________________________________
initial_conv2D (Conv2D) (None, 96, 96, 16) 288 input_1[0][0]
__________________________________________________________________________________________________
dense_0_0_bn (BatchNormalizatio (None, 96, 96, 16) 64 initial_conv2D[0][0]
__________________________________________________________________________________________________
activation_1 (Activation) (None, 96, 96, 16) 0 dense_0_0_bn[0][0]
__________________________________________________________________________________________________
dense_0_0_conv2D (Conv2D) (None, 96, 96, 4) 576 activation_1[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 96, 96, 20) 0 initial_conv2D[0][0]
dense_0_0_conv2D[0][0]
__________________________________________________________________________________________________
final_bn (BatchNormalization) (None, 96, 96, 20) 80 concatenate_1[0][0]
__________________________________________________________________________________________________
activation_2 (Activation) (None, 96, 96, 20) 0 final_bn[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 96, 96, 2) 42 activation_2[0][0]
==================================================================================================
Total params: 1,050
Trainable params: 978
Non-trainable params: 72
__________________________________________________________________________________________________
Finished compiling
/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras_preprocessing/image.py:1213: UserWarning: Expected input to be images (as Numpy array) following the data format convention "channels_last" (channels on axis 3), i.e. expected either 1, 3 or 4 channels on axis 3. However, it was passed an array with shape (39840, 96, 96, 2) (2 channels).
' channels).')
/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras_preprocessing/image.py:1437: UserWarning: NumpyArrayIterator is set to use the data format convention "channels_last" (channels on axis 3), i.e. expected either 1, 3, or 4 channels on axis 3. However, it was passed an array with shape (39840, 96, 96, 2) (2 channels).
str(self.x.shape[channels_axis]) + ' channels).')
Traceback (most recent call last):
File "keras_densenet.py", line 149, in <module>
fit_model(X_train,y_train,X_val,y_val)
File "keras_densenet.py", line 140, in fit_model
verbose=2)
File "/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras/engine/training.py", line 1415, in fit_generator
initial_epoch=initial_epoch)
File "/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras/engine/training_generator.py", line 140, in fit_generator
val_x, val_y, val_sample_weight)
File "/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras/engine/training.py", line 787, in _standardize_user_data
exception_prefix='target')
File "/home/arka/anaconda2/envs/hyperas/lib/python3.6/site-packages/keras/engine/training_utils.py", line 127, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking target: expected dense_1 to have 4 dimensions, but got array with shape (7440, 2)
这就是我在这里调用Densenet函数的方式。至少可以告诉我,是否可以通过Densenet功能使用两个通道输入,将有很大的帮助。
最佳答案
文档说,它应该有3个输入通道。 https://keras.io/applications/#densenet
您可以使用嵌入层,也可以使用具有常数值的尺寸标注广告。