Can output layers be taken during the training in real time with keras?

后端 未结 1 1290
谎友^
谎友^ 2021-01-25 00:53

I try to get output layers during the training. I am trying to make a 3d visualization of the model in real time and to make it interactive. I am using google colab with tensorf

相关标签:
1条回答
  • 2021-01-25 01:03

    If you read the source of the custom callbacks, here

    there is a property model for every custom callback we define.

    You can make use of the model object inside the functions you defined in your Cutomcallbacks.

    for example,

    def on_train_batch_end(self, batch, logs=None):
        #here you can get the model reference. 
        self.model.predict(dummy_data)
    

    The self.model is an instance of keras.models.Model and the corrresponding function can be called using it.

    More reference can be found here and here

    Please follow the comments below in order to get the answer.

    [EDIT 1]

    The code segment from the comments by the OP

    def on_train_batch_end(self, batch, logs=None): 
        for i in range(len(model_inception.layers)): 
            get_layer_output = K.function(inputs = self.model.layers[i].input, outputs = self.model.layers[i].output) 
            print('\n Training: output of the layer {} is {} ends at {}'.format(i, get_layer_output.outputs , datetime.datetime.now().time()))
    
    0 讨论(0)
提交回复
热议问题