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
178 views
in Technique[技术] by (71.8m points)

python - how to pass a layer into two layers in parallel at the same time in TensorFlow

I have implemented a neural network in Keras, but for some reasons, I need to implement the network in TensorFlow. My problem is that I need to pass h1 into two layers in parallel. I have searched a lot to pass a layer into two layers at the same time but I cannot find the correct way. The Keras code is as below:

  x = keras.layers.Input(shape=(input_dim))
  hp_units1 = hp.Int('units', min_value=1, max_value=15, step=1)
  h1 = keras.layers.Dense(hp_units1, activation = 'sigmoid', name='dense_1')(x)
  t = keras.layers.Dense(1, activation='sigmoid', name='time_prediction')(h1)
  decoded = keras.layers.Dense(input_dim, activation='linear', name='decoded_mean')(h1)

Thus, I need to pass h1 to t and decoded at the same time.

question from:https://stackoverflow.com/questions/65944621/how-to-pass-a-layer-into-two-layers-in-parallel-at-the-same-time-in-tensorflow

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

1 Reply

0 votes
by (71.8m points)

Just import keras from tensorflow 2. The same syntax is available in tensorflow 2 -

from tensorflow import keras

x = keras.layers.Input(shape=(input_dim))
hp_units1 = hp.Int('units', min_value=1, max_value=15, step=1)
h1 = keras.layers.Dense(hp_units1, activation = 'sigmoid', name='dense_1')(x)
t = keras.layers.Dense(1, activation='sigmoid', name='time_prediction')(h1)
decoded = keras.layers.Dense(input_dim, activation='linear', name='decoded_mean')(h1)

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

...