[問題] tensorflow的activation function問題

作者: chinsun   2018-11-26 08:39:30
大家我是python和machine learning 新手
如果我想要直接用keras中的relu和softmax函數
而不是在layer中的話該怎麼做呢
以下是我的訓練model
model = keras.Sequential([
keras.layers.Flatten(input_shape=(14,14)),
keras.layers.Dense(196, activation=tf.nn.relu),
keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(new_train_images, train_labels, epochs=5)
predictions = model.predict(new_test_images)
weights0 = model.layers[1].get_weights()
再來是我的問題
xx = keras.activations.softmax(
keras.activations.relu(
np.dot(np.array(fnew_test_images),np.array(weights0[0]))+
np.reshape(weights0[1],[1,196])))
fnew_test_images是new_test_images flatten後的結果,是10000個196*1的array
我希望xx能夠使用從model裡第一層的weights,經過relu運算
樣式能和fnew_test_images一樣
總而言之想取出最後一層的input
但現在xx的印出結果是
<tf.Tensor 'Relu_5:0' shape=(10000, 196) dtype=float32>
請問有什麼方法可以修正
或者有方式可以讓我從model裡直接取出input嗎
感謝!
作者: jackwang01 (艾斯比那)   2018-11-26 10:06:00
有點久沒用了,搜尋一下Keras get layer input之類的就 答案了

Links booklink

Contact Us: admin [ a t ] ucptt.com