我遇到了這個用于調整神經網路拓撲的代碼。但是,我不確定如何在不展平輸入的情況下實體化第一層。
我的輸入是這樣的:

具有 M 個特征(行)和 N 個樣本(列)。
如何創建第一個(輸入)層?
# Initialize sequential API and start building model.
model = keras.Sequential()
model.add(keras.layers.Flatten(input_shape=(28,28)))
# Tune the number of hidden layers and units in each.
# Number of hidden layers: 1 - 5
# Number of Units: 32 - 512 with stepsize of 32
for i in range(1, hp.Int("num_layers", 2, 6)):
model.add(
keras.layers.Dense(
units=hp.Int("units_" str(i), min_value=32, max_value=512, step=32),
activation="relu")
)
# Tune dropout layer with values from 0 - 0.3 with stepsize of 0.1.
model.add(keras.layers.Dropout(hp.Float("dropout_" str(i), 0, 0.3, step=0.1)))
# Add output layer.
model.add(keras.layers.Dense(units=10, activation="softmax"))
我知道 Keras 通常將第一個隱藏層與輸入層一起實體化,但我不知道如何在這個框架中做到這一點。下面是一次實體化輸入 第一個隱藏層的代碼。
model.add(Dense(100, input_shape=(CpG_num,), kernel_initializer='normal', activation='relu')
uj5u.com熱心網友回復:
如果您有多個輸入并想要設定輸入形狀,假設您有一個包含 m-> 行、n-> 列的資料框...然后只需執行此操作...
m = no_of_rows #1000
n = no_of_columns #10
no_of_layers = 64
#we will not write m because m will be taken as a batch here.
_input = tf.keras.layers.Input(shape=(n))
dense = tf.keras.layers.Dense(no_of_layers)(_input)
output = tf.keras.backend.function(_input , dense)
#Now, I can see that it is working or not...!
x = np.random.randn(1000 , 10)
print(output(x).shape)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/531226.html
