看板 Python 關於我們 聯絡資訊
大家我是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嗎 感謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 4.30.124.170 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1543192772.A.084.html ※ 編輯: chinsun (4.30.124.170), 11/26/2018 08:40:50 ※ 編輯: chinsun (4.30.124.170), 11/26/2018 08:41:53 ※ 編輯: chinsun (4.30.124.170), 11/26/2018 08:43:07
jackwang01: 有點久沒用了,搜尋一下Keras get layer input之類的 11/26 10:06
jackwang01: 就 答案了 11/26 10:06