QBoard » Artificial Intelligence & ML » AI and ML - Tensorflow » Keras, OOM getting the output of intermediate layer?

Keras, OOM getting the output of intermediate layer?

  • There are 2 ways to get the output of an intermediate area, as posted here on this forum:
    https://www.cluzters.ai/forums/topic/353/keras-how-to-get-the-output-of-each-layer?c=1597

    You don't need (or want) both of these, either works:
    
    get_layer_output = K.function([model.layers[0].input], [model.layers[1].output])
    layer_output = get_layer_output([inputData.x_train])[0]
    ​
    or
    tmp_model = Model(model.layers[0].input, model.layers[1].output)
    tmp_output = tmp_model.predict(x_train)[0]​

    This works well for a smaller model, but I always get OOM if my model is too large.  

    Is there an easy way to free the GPU memory of the original model before creating tmp_model or calling get_layer_output?  I can save my weights to a text file and create another program in another session, but it seems like there should be an easier way.
      September 6, 2022 5:12 AM IST
    0