Reputation: 173
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.
Upvotes: 1
Views: 358
Reputation: 19312
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)
Upvotes: 1