Answers:
我会使用功能界面。
像这样:
from keras.layers import Activation, Input, Dense
from keras.models import Model
from keras.layers.merge import Concatenate
input_ = Input(shape=input_shape)
x = input_
x1 = Dense(4, x)
x2 = Dense(4, x)
x3 = Dense(4, x)
x1 = Activation('softmax')(x1)
x2 = Activation('softmax')(x2)
x3 = Activation('softmax')(x3)
x = Concatenate([x1, x2, x3])
model = Model(inputs=input_, outputs=x)categorical_accuracy和predict_classes方法的使用可能需要更多的思考。。。
                    可以只实现自己的softmax函数。您可以将张量分割为多个部分,然后分别为每个部分计算softmax并连接张量部分:
def custom_softmax(t):
    sh = K.shape(t)
    partial_sm = []
    for i in range(sh[1] // 4):
        partial_sm.append(K.softmax(t[:, i*4:(i+1)*4]))
    return K.concatenate(partial_sm)concatenate 不带轴参数的连接通过最后一个轴连接(在本例中为axis = 1)。
然后,您可以将此激活功能包括在隐藏层中或将其添加到图形中。
Dense(activation=custom_activation)要么
model.add(Activation(custom_activation))您还需要定义一个新的成本函数。