从完全连接的层输出的多维分类

时间:2017-04-10 16:13:16

标签: python classification keras

我似乎在定义输出图层时遇到了一些问题..

train_data_1 = np.random.randint(100,size=(100,splits,45,5,3))
test_data_1 = np.random.randint(100,size=(10,splits,45,5,3))
labels_train_data =np.random.randint(145,size=(100,15))
labels_test_data =np.random.randint(145,size=(10,15))

list_of_input = [Input(shape = (45,5,3)) for i in range(splits)]
list_of_conv_output = []
list_of_max_out = []
for i in range(splits):
    list_of_conv_output.append(Conv2D(filters = 32 , kernel_size = (3,3))(list_of_input[i]))
    list_of_max_out.append((MaxPooling2D(pool_size=(43,3))(list_of_conv_output[i])))

merge = keras.layers.concatenate(list_of_max_out)

dense1 = Dense(units = 1000, activation = 'relu',    name = "dense_1")(merge)
dense2 = Dense(units = 1000, activation = 'relu',    name = "dense_2")(dense1)
dense3 = Dense(units = (15,145) , activation = 'softmax', name = "dense_3")(dense2)

输出图层应为长度为15的数组,其中包含145个标签池中的标签列表(15个标签)。为什么我无法将我的图层设置为输出(15,145)是输出向量的长度,以及可能的类的数量。

错误:

Traceback (most recent call last):
  File "test_model.py", line 30, in <module>
    dense3 = Dense(units = (15,145) , activation = 'softmax', name = "dense_3")(dense2)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 528, in __call__
    self.build(input_shapes[0])
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 827, in build
    constraint=self.kernel_constraint)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 364, in add_weight
    weight = K.variable(initializer(shape), dtype=K.floatx(), name=name)
  File "/usr/local/lib/python2.7/dist-packages/keras/initializers.py", line 197, in __call__
    scale /= max(1., float(fan_in + fan_out) / 2)
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

0 个答案:

没有答案