Ich habe eine Merkmalskarte und einige koordinieren
ich so etwas wie unten
Ernte tun möchten, die Daten von Merkmalskarte durch die Koordinaten
Dann tun argmax
, concat
(oder stack
?)
Wie kann ich dies in Tensorflow tun?Griff Tensor in Schleife
# num_coor is Not fixed, but fixed is ok!
# it defined before run
num_coor = 4
feature_map = np.transpose(np.reshape(np.arange(100*100*3), (3, 100, 100)), [1, 2, 0])
x_coor = np.array([[0, 20, 40, 60],
[15, 35, 55, 75]]) # shape(?, num_coor)
y_coor = np.array([[0, 20, 40, 60],
[15, 35, 55, 75]]) # shape(?, num_coor)
crop = []
for batch in xrange(x_coor.shape[0]):
temp1 = []
for i in xrange(num_coor - 1):
temp2 = []
for j in xrange(num_coor - 1):
x1 = x_coor[batch, j]
y1 = y_coor[batch, i]
x2 = x_coor[batch, j + 1]
y2 = y_coor[batch, i + 1]
# slice by coordinate and len(slice_map) is depth
slice_map = [feature_map[x1:x2, y1:y2, c] for c in xrange(feature_map.shape[2])]
resmax = [np.amax(slice_map[c]) for c in xrange(len(slice_map))]
resmax = np.reshape(np.array(resmax), (1, 1, feature_map.shape[2]))
temp2.append(resmax)
temp1.append(np.vstack(temp2))
temp_arr = np.concatenate(temp1, axis=1)
crop.append(np.array(temp_arr))
crop = np.array(crop) # (2, 3, 3, 3)
Vier in x-Koordinate, y 9 Behälter bilden kann Ich mag so max Pool in jedem Fach und jeden Kanal tun, dass ich Pool Ergebnis zu bekommen, ist Form (2, 3, 3, 3) # (2, h, w, c)
in diesem Fall
ich glaube, ich tf.while_loop
können diese
zu tun, aber ich weiß nicht, wie externe Tensor zuzugreifen und geben das Ergebnis
habe ich eine kleine Test, scheint es greift nicht auf externe Tensor
i = tf.constant(0)
first_coor = x_coor[i, :]
while_cond = lambda i, _: tf.less(i, 5)
def body(i, the_coor):
# print every loop
i = i + 1
i = tf.Print(i, [i], 'i is :')
i = i + 0
# Never print!!
coor = x_coor
coor = tf.Print(coor, [coor], 'coor is :')
coor = coor + 0
# print every loop
the_coor = tf.Print(the_coor, [the_coor], 'the_coor is :')
the_coor = the_coor + 0
return i, the_coor
r = tf.while_loop(while_cond, body, [i, first_coor])
Sind Ihre Koordinaten innerhalb des Stapels gleich? Sie möchten nur Informationen aus der Feature-Map extrahieren? –
@AlexeyRomanov Entschuldigung für die Antwort spät. Nein, die Koordinaten sind bei jeder Charge unterschiedlich (dh 2), aber die Anzahl der Koordinaten ist fest (dh 4 Koordinaten in x- und y-Achse), und ja ich möchte Informationen aus der Feature-Map extrahieren – xxi