| 25 | _LAYER_UIDS = {} |
| 26 | |
| 27 | def project(img_feat, x, y, dim): |
| 28 | x1 = tf.floor(x) |
| 29 | x2 = tf.minimum(tf.ceil(x), tf.cast(tf.shape(img_feat)[0], tf.float32) - 1) |
| 30 | y1 = tf.floor(y) |
| 31 | y2 = tf.minimum(tf.ceil(y), tf.cast(tf.shape(img_feat)[1], tf.float32) - 1) |
| 32 | Q11 = tf.gather_nd(img_feat, tf.stack([tf.cast(x1,tf.int32), tf.cast(y1,tf.int32)],1)) |
| 33 | Q12 = tf.gather_nd(img_feat, tf.stack([tf.cast(x1,tf.int32), tf.cast(y2,tf.int32)],1)) |
| 34 | Q21 = tf.gather_nd(img_feat, tf.stack([tf.cast(x2,tf.int32), tf.cast(y1,tf.int32)],1)) |
| 35 | Q22 = tf.gather_nd(img_feat, tf.stack([tf.cast(x2,tf.int32), tf.cast(y2,tf.int32)],1)) |
| 36 | |
| 37 | weights = tf.multiply(tf.subtract(x2,x), tf.subtract(y2,y)) |
| 38 | Q11 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q11) |
| 39 | |
| 40 | weights = tf.multiply(tf.subtract(x,x1), tf.subtract(y2,y)) |
| 41 | Q21 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q21) |
| 42 | |
| 43 | weights = tf.multiply(tf.subtract(x2,x), tf.subtract(y,y1)) |
| 44 | Q12 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q12) |
| 45 | |
| 46 | weights = tf.multiply(tf.subtract(x,x1), tf.subtract(y,y1)) |
| 47 | Q22 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q22) |
| 48 | |
| 49 | outputs = tf.add_n([Q11, Q21, Q12, Q22]) |
| 50 | return outputs |
| 51 | |
| 52 | def get_layer_uid(layer_name=''): |
| 53 | """Helper function, assigns unique layer IDs.""" |