mask-rcnn Interpretation (a): clip_boxes_graph

This part of the mask-rcnn clip_boxes_graph () function is used. Firstly, the code used to solve the basic function, and then run the code, which details are as follows: 
Code as follows:
tensorflow TF AS Import 
Import numpy AS NP
Import Random
Sess = tf.Session ()
window = [0.0,0.0,1.0,1.0]

box_rand np.array = ([round (random.random (),. 1) for I in Range ( 32)]). reshape (( 8,4)) # randomly generated number between [0, 1] to simulate the box coordinate
box_rand = box_rand.astype (np.float32)
Print ( 'Show box_rand =', box_rand) # the analog display Box

wind_split = tf.split (window,. 4)
wind_sp = sess.run (wind_split)
Print ( 'wind_split =', wind_sp) # split view where the divided
print (np.array (wind_split) .shape) # Print dimension
y1, x1, y2, x2 = tf.split (box_rand, 4, axis = 1) # denotes a second dimension extending divided into four tensor
y = sess.run (y1) # display the first divided content, other similar tone
Print ( 'Show value = Y1', Y)


DEF clip_boxes_graph (Boxes, window):
"" "
Boxes: [N, (Y1, X1, Y2,X2)]
window: [. 4] The form in Y1, X1, Y2, X2
"" "
# Split
Wy1, WX1, wy2, WX2 = tf.split (window,. 4)
Y1, X1, Y2, X2 = tf.split (Boxes, . 4, Axis =. 1)
# the Clip
# y1 in an example, requires wy1 <y1 <wy2, similar to the rest, which corresponds to x1 / y1 / x2 / y2 in the range [0,1] closed interval
y1 = tf.maximum ( tf.minimum (Y1, wy2), Wy1)
X1 = tf.maximum (tf.minimum (X1, WX2), WX1)
Y2 = tf.maximum (tf.minimum (Y2, wy2), Wy1)
X2 = tf.maximum (tf.minimum (X2, WX2), WX1)
Clipped tf.concat = ([Y1, X1, Y2, X2], Axis =. 1, name = "clipped_boxes")
clipped.set_shape ((clipped.shape [0], . 4))
return Clipped

Clip = clip_boxes_graph (box_rand, window)
Clip = sess.run (Clip)
Print ( 'Show Clipped function value =',clip)
print ( 'show function value shape clipped =', clip.shape)

results as follows:

show box_rand= [[0. 0.5 0.1 0.7]
[0.3 0.5 0.6 0.2]
[0.1 0.6 0.6 0.6]
[0.8 0.8 0.9 0.6]
[0.5 0.1 0.8 0.3]
[0.2 0.2 0.1 0.7]
[1. 0.3 1. 0.2]
[0.1 0.8 0. 0.1]]
wind_split= [array([0.], dtype=float32), array([0.], dtype=float32), array([1.], dtype=float32), array([1.], dtype=float32)]
(4,)
show value y1= [[0. ]
[0.3]
[0.1]
[0.8]
[0.5]
[0.2]
[1. ]
[0.1]]
show function value clipped= [[0. 0.5 0.1 0.7]
[0.3 0.5 0.6 0.2]
[0.1 0.6 0.6 0.6]
[0.8 0.8 0.9 0.6]
[0.5 0.1 0.8 0.3]
[0.2 0.2 0.1 0.7]
[1. 0.3 1. 0.2]
[0.1 0.8 0. 0.1]]
show function value shape clipped= (8, 4)

 






Guess you like

Origin www.cnblogs.com/tangjunjun/p/11963362.html