[英]Usage of argmax from tf.nn.max_pool_with_argmax tensorflow
[英]How to use tf.nn.max_pool_with_argmax correctly
目前我用張量流來玩一點,以便更好地理解機器學習張量流本身。 因此,我想想象張量流的方法(盡可能多)。 為了可視化max_pool,我加載了一個圖像並執行該方法。 之后我顯示了兩個:輸入和輸出圖像。
import tensorflow as tf
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread('lena.png')
image_tensor = tf.expand_dims(tf.Variable(image, dtype=tf.float32), 0)
#output, argmax = tf.nn.max_pool_with_argmax(image_tensor, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')
output = tf.nn.max_pool(image_tensor, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')
init = tf.initialize_all_variables()
session = tf.Session()
session.run(init)
output = session.run(output)
session.close()
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
plt.figure()
plt.imshow(image)
plt.show()
output = cv2.cvtColor(output[0], cv2.COLOR_RGB2BGR)
plt.figure()
plt.imshow(255-output)
plt.show()
一切正常,我得到這個輸出(如預期的那樣)
現在我想測試方法tf.nn.max_pool_with_argmax
以獲得池化操作的argmax。 但如果我取消注釋該行
output, argmax = tf.nn.max_pool_with_argmax(image_tensor, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')
Python崩潰了
tensorflow.python.framework.errors.InvalidArgumentError:沒有注冊OpKernel來支持Op'MaxPoolWithArgmax'這些attrs [[Node:pool1 = MaxPoolWithArgmaxT = DT_FLOAT,Targmax = DT_INT64,ksize = [1,2,2,1],padding =“相同”,步幅= [1,2,2,1]]]
我不知道哪個參數是錯誤的,因為每個參數都應該是正確的( tensorflow docs )......
有誰知道出了什么問題?
從看的實施 ,似乎在tf.nn.max_pool_with_argmax()
用於GPU時才實現。 如果您正在運行TensorFlow的僅CPU版本,那么您將收到"No OpKernel was registered to support Op 'MaxPoolWithArgmax' with these attrs ..."
。
(這似乎是一個可以改進文檔和錯誤消息的地方。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.