Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

tensorflow - How to extract the output of an intermediate layer in Keras [for R]?

I am having trouble extracting the output of an intermediate layer in a Keras NN model. Although there is a ton of resource on this most of them are geared towards for python users. I have tried working towards the tutorial posted here and here. Essentially both of the tutorial says to recreate the original model and then somehow extract the intermediate layers by simply calling it. The issue I am having is model$input returns nothing in my code and I have no idea where layer_name is in a model. After playing around with this method I tried creating a new model to the layer I am interested in and put in the trained weights of the original model in order to get the intermediate layer output. However, I found myself at a lack of resource for R users on how to place weights into a new model. I would appreciate if anyone would help with walking through a concrete example on how to do either method or a better one. Here is my original model:

network <- keras_model_sequential() 
network %>% 
  layer_dropout(rate = 0.1) %>% 
  layer_dense(units = 64, activation = "relu", input_shape = length(training_data) ) %>%
  layer_dense(units = 8, activation = "sigmoid" ) %>%
  layer_dense(units = 64, activation = "relu" ) %>%
  layer_dense(units = length(training_data), activation = "softmax")

question from:https://stackoverflow.com/questions/66053383/how-to-extract-the-output-of-an-intermediate-layer-in-keras-for-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...