[問題] tensorflow的activation function問題

看板Python作者時間6年前 (2018/11/26 08:39), 6年前編輯推噓0(002)
留言2則, 1人參與, 6年前最新討論串1/1
大家我是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

11/26 10:06, 6年前 , 1F
有點久沒用了,搜尋一下Keras get layer input之類的
11/26 10:06, 1F

11/26 10:06, 6年前 , 2F
就 答案了
11/26 10:06, 2F
文章代碼(AID): #1R-q3424 (Python)
文章代碼(AID): #1R-q3424 (Python)