Hi all.

I would like to create a custom loss function that uses a as of the calculation. More specifically R1; I just need the mean of the feature across the batch/set, and include that in a calculation for my custom loss.

So if I have 1000 features, in in my custom loss I would like to be able to know the mean value of feature #10, in the batch/set that was used to give y_pred. I know I can use wrappers to pass custom , but passing a vector of all instances of feature #10 is pointless, because I don’t know which subset of have been used in that batch/set.

I found this example on Stack Overflow which seems quite close to what I’m after, but I don’t fully understand how to make it work for my situation, partially because my layout seems have a slightly different style.

Stack overflow thread:
https://stackoverflow.com/questions/46464549/keras-custom-loss-function-accessing-current-input-pattern

Snippet of my code/model:

model = Sequential()
model.add(Dense(80, kernel_initializer='uniform',input_dim=NCOMPONENTS))
model.add(Dropout(0.2))
model.add(Activation('selu'))
model.add(BatchNormalization())

model.add(Dense(40, kernel_initializer='uniform'))
model.add(Dropout(0.2))
model.add(Activation('selu'))
model.add(BatchNormalization())

model.add(Dense(10, kernel_initializer='uniform'))
model.add(Dropout(0.2))
model.add(Activation('selu'))
model.add(BatchNormalization())

model.add(Dense(2, kernel_initializer='uniform'))
model.add(Activation('softmax'))

adam = optimizers.Adam(lr=0.000005, beta_1=0.9, beta_2=0.999, decay=0.0)

model.compile(loss='binary_crossentropy', optimizer=adam, metrics=[ single_class_precision(1)])

history = model.fit(X_train, Y_train, epochs=25000, batch_size=512, verbose=1,  shuffle=True, 
validation_split=0.3,class_weight={0:1, 1:2.5},callbacks=callbacks_list)

Any help would be appreciated.



Source link
thanks you RSS link
( https://www.reddit.com/r//comments/8gziht/p_keras__feature_indices_from_custom/)

LEAVE A REPLY

Please enter your comment!
Please enter your name here