<jupyter_start><jupyter_text>Location heatmap<jupyter_code>fig, ax = plt.subplots(figsize=(6,6))
ax.hist2d(data[1], data[2], bins=[70,70], cmap='plasma')
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.savefig("plots/location_heatmap.pdf", dpi=300)<jupyter_output><empty_output><jupyter_text>Location heatmap without traffic cones<jupyter_code>fig, ax = plt.subplots(figsize=(6,6))
mask = data[0] == 1.0
ax.hist2d(data[1][mask], data[2][mask], bins=[70,70], cmap='plasma')
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.savefig("plots/location_heatmap_cars.pdf", dpi=300)
plt.hist(data[])
plt.hist(data[4])
plt.hist(data[5])
aligned_width = (data[8] - data[7]) * 100
aligned_height = (data[10] - data[9]) * 100
plt.hist(aligned_width)
plt.hist(aligned_height)
grid_cell_size = 0.125 # one cell = 12.5 cm
levels = [
    {"level": 2,
    "aspect_ratios": [0.5, 1.0, 2.0],
    "anchor_size": 2.0,
    "num_scales": 2},
    {"level": 3,
    "aspect_ratios": [0.5, 1.0, 2.0],
    "anchor_size": 2.0,
    "num_scales": 2},
    {"level": 4,
    "aspect_ratios": [0.5, 1.0, 2.0],
    "anchor_size": 2.0,
    "num_scales": 2},
    {"level": 5,
    "aspect_ratios": [0.5, 1.0, 2.0],
    "anchor_size": 2.0,
    "num_scales": 2}
]

colors_anchors = ['gray', 'black', 'gray', 'black', 'gray']
linestyle_anchors = ['-', ':', '-', ':', '-']
iou_factor = 0.5
def make_anchors(levels):
    anchors = []
    for level in levels:
        anchors_level = []
        for scale in range(level["num_scales"]):
            for aspect_ratio in level["aspect_ratios"]:
                stride = 2**level["level"]
                intermidiate_scale = 2**(scale / float(level["num_scales"]))
                base_anchor_size = level["anchor_size"] * stride * intermidiate_scale
                aspect_x = aspect_ratio**0.5
                aspect_y = aspect_ratio**-0.5
                anchor_size_x = base_anchor_size * aspect_x
                anchor_size_y = base_anchor_size * aspect_y

                anchors_level.append([anchor_size_x * grid_cell_size, anchor_size_y * grid_cell_size])
        anchors.append(anchors_level)

    return anchors
anchors = make_anchors(levels)
fig, ax = plt.subplots(figsize=(16,8))

for label in range(num_classes):
    mask = (data[0] == float(label + 1))
    ax.scatter(x=aligned_width[mask], y=aligned_height[mask], marker=",", s=1, label=label_map[label]["name"])

ax.legend(markerscale=12)
    
for i, level_anchors in enumerate(anchors):
    color = colors_anchors[i]
    for anchor in level_anchors:
        circle1 = matplotlib.patches.Ellipse((anchor[0], anchor[1]), width=anchor[0] * iou_factor * 2.0, height=anchor[1] * iou_factor * 2.0, color=color, fill=False, linestyle=linestyle_anchors[i])
        ax.add_artist(circle1)
        
plt.savefig("plots/aligned_anchors.pdf")<jupyter_output><empty_output><jupyter_text>Now let's look only at specific FPN levels<jupyter_code>def plot_fpn_level_anchors(level: int, limits):
    fig, ax = plt.subplots(figsize=(8,8))

    for label in range(num_classes):
        mask = (data[0] == float(label + 1))
        ax.scatter(x=aligned_width[mask], y=aligned_height[mask], marker=",", s=2, label=label_map[label]["name"])

    ax.legend(markerscale=6, loc='upper right')

    i = level - 2
    level_anchors = anchors[i]
    color = "black"
    for anchor in level_anchors:
        circle1 = matplotlib.patches.Ellipse((anchor[0], anchor[1]), width=anchor[0] * iou_factor * 2.0, height=anchor[1] * iou_factor * 2.0, color=color, fill=False)
        ax.add_artist(circle1)

    ax.set_xlim(limits)
    ax.set_xlabel("width in m")
    ax.set_ylim(limits)
    ax.set_ylabel("height in m")

    plt.savefig(f"plots/fpn{level}.pdf", dpi=500)<jupyter_output><empty_output><jupyter_text>FPN 2<jupyter_code>plot_fpn_level_anchors(2, [0.0, 5.0])<jupyter_output><empty_output><jupyter_text>FPN 3<jupyter_code>plot_fpn_level_anchors(3, [0.0, 7.5])<jupyter_output><empty_output><jupyter_text>FPN 4<jupyter_code>plot_fpn_level_anchors(4, [1.0, 14.5])<jupyter_output><empty_output><jupyter_text>FPN 5<jupyter_code>plot_fpn_level_anchors(5, [2.0, 30.0])<jupyter_output><empty_output><jupyter_text>Box size heatmap<jupyter_code>fig, ax = plt.subplots(figsize=(8,8))
ax.hist2d(aligned_width, aligned_height, bins=100, cmap='plasma', density=True)
ax.set_xlabel("width")
ax.set_ylabel("height")
fig, ax = plt.subplots(figsize=(8,8))
ax.hist2d(aligned_width, aligned_height, bins=100, cmap='plasma', range=[[2.5,20.0],[2.5,20.0]])
ax.set_xlabel("width")
ax.set_ylabel("height")<jupyter_output><empty_output><jupyter_text>3D view with angle<jupyter_code>width_scaled = data[3] * 800 * 0.125
height_scaled = data[4] * 800 * 0.125
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')

for label in range(num_classes):
    mask = (data[0] == float(label + 1))
    ax.scatter(width_scaled[mask], height_scaled[mask], data[5][mask], marker=",", s=1, label=label_map[label]["name"])

ax.legend(markerscale=6, loc='upper right')

ax.set_xlabel('width')
ax.set_ylabel('height')
ax.set_zlabel('cos')

plt.savefig("plots/3d_anchors.pdf", dpi=500)
plt.show()<jupyter_output><empty_output><jupyter_text>Only cars, trucks & busses<jupyter_code>fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='3d')

for label in [0, 4, 6]:
    mask = (data[0] == float(label + 1))
    ax.scatter(width_scaled[mask], height_scaled[mask], data[5][mask], marker=",", s=1, label=label_map[label]["name"])

ax.legend(markerscale=6, loc='upper right')

ax.set_xlabel('width')
ax.set_ylabel('height')
ax.set_zlabel('cos')
plt.savefig("plots/3d_filtered.pdf", dpi=500)

plt.show()<jupyter_output><empty_output><jupyter_text>Rotated anchor matching<jupyter_code>levels = [
    {"level": 2,
    "aspect_ratios": [1.0, 0.3],
    "anchor_size": 1.7,
    "num_scales": 2},
    {"level": 3,
    "aspect_ratios": [1.0, 0.4],
    "anchor_size": 2.0,
    "num_scales": 2},
    {"level": 4,
    "aspect_ratios": [1.0, 0.3],
    "anchor_size": 2.0,
    "num_scales": 2},
    {"level": 5,
    "aspect_ratios": [0.25],
    "anchor_size": 1.5,
    "num_scales": 1}
]
anchors = make_anchors(levels)
fig, ax = plt.subplots(figsize=(16,8))

for label in range(num_classes):
    mask = (data[0] == float(label + 1))
    ax.scatter(x=data[4][mask] * 800 * 0.125, y=data[3][mask] * 800 * 0.125, marker=",", s=1, label=label_map[label]["name"])

ax.legend(markerscale=12)
ax.set_xlabel("height in m")
ax.set_ylabel("width in m")
    
for i, level_anchors in enumerate(anchors):
    color = colors_anchors[i]
    for anchor in level_anchors:
        circle1 = matplotlib.patches.Ellipse((anchor[1], anchor[0]), width=anchor[1] * iou_factor * 2.0, height=anchor[0] * iou_factor * 2.0, color=color, fill=False, linestyle=linestyle_anchors[i])
        ax.add_artist(circle1)
        
plt.savefig("plots/rotated_anchors.pdf")
fig, ax = plt.subplots(figsize=(16,8))

for label in range(num_classes):
    mask = (data[0] == float(label + 1))
    ax.scatter(x=data[3][mask] * 800 * 0.125, y=data[5][mask], marker=",", s=1, label=label_map[label]["name"])

ax.legend(markerscale=12)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17918831624771803, 'fraction_numerical': 0.04423536020221879, 'mean_word_length': 4.738920225624496, 'pattern_counts': {'":': 32, '<': 45, '<?xml version=': 0, '>': 45, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '194858', 'license': 'Apache-2.0', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2865, 'n_words': 459, 'path': 'tfrecords.ipynb', 'repo_name': 'fellhorn/rotated_box_encoding_analysis', 'size': '7121'}