>>> scales = [32, 64, 128, 256, 512] >>> ratios = [0.5,1,2] >>> np.meshgrid(np.array(scales), np.array(ratios)) [ array([ [ 32, 64, 128, 256, 512], [ 32, 64, 128, 256, 512], [ 32, 64, 128, 256, 512] ]), array([ [0.5, 0.5, 0.5, 0.5, 0.5], [1. , 1. , 1. , 1. , 1. ], [2. , 2. , 2. , 2. , 2. ] ]) ] >>> np.meshgrid(np.array(ratios), np.array(scales)) [array([[0.5, 1. , 2. ], [0.5, 1. , 2. ], [0.5, 1. , 2. ], [0.5, 1. , 2. ], [0.5, 1. , 2. ]]), array([[ 32, 32, 32], [ 64, 64, 64], [128, 128, 128], [256, 256, 256], [512, 512, 512]])] >>> scales = scales.flatten() >>> ratios = ratios.flatten() >>> heights = scales / np.sqrt(ratios) >>> widths = scales * np.sqrt(ratios) >>> heights array([ 45.254834 , 90.50966799, 181.01933598, 362.03867197, 724.07734394, 32. , 64. , 128. , 256. , 512. , 22.627417 , 45.254834 , 90.50966799, 181.01933598, 362.03867197]) >>> widths array([ 22.627417 , 45.254834 , 90.50966799, 181.01933598, 362.03867197, 32. , 64. , 128. , 256. , 512. , 45.254834 , 90.50966799, 181.01933598, 362.03867197, 724.07734394]) >>> heights.shape, widths.shape ((15,), (15,)) >>> anchor_stride=1 >>> shape=[1024,2048] >>> feature_strides = [4, 8, 16, 32, 64] >>> feature_stride = feature_strides[2] >>> shifts_x = np.arange(0, shape[1], anchor_stride) * feature_stride >>> shifts_y = np.arange(0, shape[0], anchor_stride) * feature_stride >>> shifts_x array([ 0, 16, 32, ..., 32720, 32736, 32752]) >>> shifts_y array([ 0, 16, 32, ..., 16336, 16352, 16368]) >>> len(shifts_x), len(shifts_y) 2048,1024 >>> shifts_x, shifts_y = np.meshgrid(shifts_x, shifts_y) >>> shifts_y array([[ 0, 0, 0, ..., 0, 0, 0], [ 16, 16, 16, ..., 16, 16, 16], [ 32, 32, 32, ..., 32, 32, 32], ..., [16336, 16336, 16336, ..., 16336, 16336, 16336], [16352, 16352, 16352, ..., 16352, 16352, 16352], [16368, 16368, 16368, ..., 16368, 16368, 16368]]) >>> shifts_x array([[ 0, 16, 32, ..., 32720, 32736, 32752], [ 0, 16, 32, ..., 32720, 32736, 32752], [ 0, 16, 32, ..., 32720, 32736, 32752], ..., [ 0, 16, 32, ..., 32720, 32736, 32752], [ 0, 16, 32, ..., 32720, 32736, 32752], [ 0, 16, 32, ..., 32720, 32736, 32752]]) >>> shifts_x.shape, shifts_y.shape ((1024, 2048), (1024, 2048)) >>> box_widths, box_centers_x = np.meshgrid(widths, shifts_x) >>> box_heights, box_centers_y = np.meshgrid(heights, shifts_y) >>> box_heights array([[ 45.254834 , 90.50966799, 181.01933598, ..., 90.50966799, 181.01933598, 362.03867197], [ 45.254834 , 90.50966799, 181.01933598, ..., 90.50966799, 181.01933598, 362.03867197], [ 45.254834 , 90.50966799, 181.01933598, ..., 90.50966799, 181.01933598, 362.03867197], ..., [ 45.254834 , 90.50966799, 181.01933598, ..., 90.50966799, 181.01933598, 362.03867197], [ 45.254834 , 90.50966799, 181.01933598, ..., 90.50966799, 181.01933598, 362.03867197], [ 45.254834 , 90.50966799, 181.01933598, ..., 90.50966799, 181.01933598, 362.03867197]]) >>> box_centers_y array([[ 0, 0, 0, ..., 0, 0, 0], [ 0, 0, 0, ..., 0, 0, 0], [ 0, 0, 0, ..., 0, 0, 0], ..., [16368, 16368, 16368, ..., 16368, 16368, 16368], [16368, 16368, 16368, ..., 16368, 16368, 16368], [16368, 16368, 16368, ..., 16368, 16368, 16368]]) >>> box_centers_x array([[ 0, 0, 0, ..., 0, 0, 0], [ 16, 16, 16, ..., 16, 16, 16], [ 32, 32, 32, ..., 32, 32, 32], ..., [32720, 32720, 32720, ..., 32720, 32720, 32720], [32736, 32736, 32736, ..., 32736, 32736, 32736], [32752, 32752, 32752, ..., 32752, 32752, 32752]]) >>> box_widths array([[ 22.627417 , 45.254834 , 90.50966799, ..., 181.01933598, 362.03867197, 724.07734394], [ 22.627417 , 45.254834 , 90.50966799, ..., 181.01933598, 362.03867197, 724.07734394], [ 22.627417 , 45.254834 , 90.50966799, ..., 181.01933598, 362.03867197, 724.07734394], ..., [ 22.627417 , 45.254834 , 90.50966799, ..., 181.01933598, 362.03867197, 724.07734394], [ 22.627417 , 45.254834 , 90.50966799, ..., 181.01933598, 362.03867197, 724.07734394], [ 22.627417 , 45.254834 , 90.50966799, ..., 181.01933598, 362.03867197, 724.07734394]]) 3867197,>>> box_widths.shape, box_centers_x.shape, box_heights.shape , box_centers_y.shape ((2097152, 15), (2097152, 15), (2097152, 15), (2097152, 15)) >>> box_centers array([[ 0, 0], [ 0, 0], [ 0, 0], ..., [16368, 32752], [16368, 32752], [16368, 32752]]) >>> box_sizes array([[ 45.254834 , 22.627417 ], [ 90.50966799, 45.254834 ], [181.01933598, 90.50966799], ..., [ 90.50966799, 181.01933598], [181.01933598, 362.03867197], [362.03867197, 724.07734394]]) >>> len(box_centers),len(box_sizes) (31457280, 31457280) >>> box_centers.shape, box_sizes.shape ((31457280, 2), (31457280, 2)) >>> boxes = np.concatenate([box_centers - 0.5 * box_sizes, ... box_centers + 0.5 * box_sizes], axis=1) >>> boxes array([[-2.26274170e+01, -1.13137085e+01, 2.26274170e+01, 1.13137085e+01], [-4.52548340e+01, -2.26274170e+01, 4.52548340e+01, 2.26274170e+01], [-9.05096680e+01, -4.52548340e+01, 9.05096680e+01, 4.52548340e+01], ..., [ 1.63227452e+04, 3.26614903e+04, 1.64132548e+04, 3.28425097e+04], [ 1.62774903e+04, 3.25709807e+04, 1.64585097e+04, 3.29330193e+04], [ 1.61869807e+04, 3.23899613e+04, 1.65490193e+04, 3.31140387e+04]]) >>> boxes.shape (31457280, 4)
|