Hi all.

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

So if I have 00 , 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 indices 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 Keras 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.(Dense(80, kernel_initializer='uniform',input_dim=NCOMPONENTS))
model.(Dropout(0.2))
model.(Activation('selu'))
model.(BatchNormalization())

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

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

model.(Dense(2, kernel_initializer='uniform'))
model.(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