<jupyter_start><jupyter_text>second approach<jupyter_code>size_Y = 16 #feat map size
size_X = 16
rpn_stride = 8 # downsample size
scales = [2,4,8]
ratios = [0.5, 1, 2]
def anchor_gen(size_X, size_Y, rpn_stride, scales, ratios):
    scales, ratios = np.meshgrid(scales, ratios)
    scales, ratios = scales.flatten(), ratios.flatten()
    scalesY = scales * np.sqrt(ratios)
    scalesX = scales / np.sqrt(ratios)
    
    shiftX = np.arange(0, size_X) * rpn_stride
    shiftY = np.arange(0, size_Y) * rpn_stride
    shiftX, shiftY = np.meshgrid(shiftX, shiftY)
    print(shiftX.shape)
    centerX, anchorX = np.meshgrid(shiftX, scalesX)
    centerY, anchorY = np.meshgrid(shiftY, scalesY)
    print(centerY.shape) # (9, 256)
    print(anchorX.shape)
    anchor_center = np.stack([centerY, centerX], axis=2).reshape(-1,2)
    anchor_size = np.stack([anchorY, anchorX],axis=2).reshape(-1,2)
    print(anchor_size.shape)
    boxes = np.concatenate([anchor_center-0.5*anchor_size, anchor_center+0.5*anchor_size], axis=1)
    return boxes
plt.figure(figsize=(10,10))
img = np.ones((128,128, 3))
fig = plt.imshow(img)
axes = plt.gca()
anchors = anchor_gen(size_X, size_Y, rpn_stride, scales, ratios)
for i in range(anchors.shape[0]): 
    box = anchors[i]
    patch = axes.add_patch(patches.Rectangle((box[0], box[1]), box[2] - box[0], box[3] - box[1], edgecolor='r', facecolor='none'))<jupyter_output>(16, 16)
(9, 256)
(9, 256)
(2304, 2)
{'fraction_non_alphanumeric': 0.16083916083916083, 'fraction_numerical': 0.044755244755244755, 'mean_word_length': 4.482758620689655, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '586958', 'license': 'MIT', 'n_tokens_mistral': 612, 'n_tokens_neox': 570, 'n_words': 113, 'path': 'rpn_anchor.ipynb', 'repo_name': 'davidsonic/Faster-rcnn.pytorch', 'size': '1430'}