问题描述
我正在尝试使用 Densenet 来自keras_contrib,用于我自己的数据,尺寸为(30k,2,96,96)
.
I am trying to use the Densenet from the keras_contrib for my own data with dimensions (30k,2,96,96)
.
是否可以对我的形状数据使用此实现?它给出以下错误和警告.
Is it not possible to use this implementation with my data of the shape? It gives following error and warning.
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功能使用两个通道输入,这将是一个很大的帮助.
This is how I am calling the Densenet function here. At least can tell me if this is possible to use two channel inputs with this Densenet function, will be a great help.
推荐答案
文档说,它应该恰好具有3个输入通道. https://keras.io/applications/#densenet 您可以使用嵌入层,也可以使用具有恒定值的尺寸标注广告(我猜是这样).
The documentation says, it should have exactly 3 inputs channels. https://keras.io/applications/#densenetYou could use an embedding layer or maybe ad a dimension with constant values I guess.
这篇关于来自keras_contrib的Densenet问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!