keras - How to get Conv2D layer filter weights -
how weights of filters (like 32 ,64, etc.) of conv2d layer in keras after each epoch? mention that, because initial weights random after optimization change.
i checked this answer did not understand. please me find solution of getting weights of filter , after every epoch.
and 1 more question in keras documentation conv2d layer input shape (samples, channels, rows, cols). samples
mean? total number of inputs have (like in mnist data set 60.000 training images) or batch size (like 128 or other)?
samples = batch size = number of images in batch
keras use none
dimension, meaning can vary , don't have set it.
although dimension exists, when create layer, pass input_shape
without it:
conv2d(64,(3,3), input_shape=(channels,rows,cols)) #the standard (rows,cols,channels), depending on data_format
to have actions done after each epoch (or batch), can use lambdacallback, passing on_epoch_end
function:
#the function call def get_weights(epoch,logs): wsandbs = model.layers[indexoftheconvlayer].get_weights() #or model.get_layer("layername").get_weights() weights = wsandbs[0] biases = wsandbs[1] #do need them #you can see epoch , logs too: print("end of epoch: " + str(epoch)) instance #the callback keras.callbacks import lambdacallback mycallback = lambdacallback(on_epoch_end=get_weights)
pass callback training function:
model.fit(...,...,... , callbacks=[mycallback])
Comments
Post a Comment