<jupyter_start><jupyter_text>9.4 锚框 1. 通常会在输入图像中采样大量的区域，然后判断这些区域中是否包含我们感兴趣的目标，并调整区域边缘从而更准确地预测目标的真实边界框（ground-truth bounding box）2. 以每个像素为中心生成多个大小和宽高比（aspect ratio）不同的边界框。这些边界框被称为锚框（anchor box）<jupyter_code>%matplotlib inline
from PIL import Image
import numpy as np
import math
import torch

import sys
sys.path.append("..") 
import d2lzh_pytorch.utils as d2l<jupyter_output><empty_output><jupyter_text>9.4.1 生成多个锚框 1. 设输入图像高为$h$，宽为$w$,分别以图像的每个像素为中心生成不同形状的锚框2. 设大小为$s \in (0, 1]$且宽高比$r > 0$,此时锚框的宽和高分别为$ws\sqrt{r}$和$hs/\sqrt{r}$        - 此时锚框的面积为$hws$,设其宽和高分别为$x$,$y$,则$xy = kws$,$x/y = r$        3. 设一组大小$s_1, \cdots, s_n$和一组宽高比$r_1, \cdots, r_m$,(如果使用所有的大小和宽高比组合,那么共有$whnm$)4. 通常只对包含$s_1$或者$r_1$的大小与宽高比的组合感兴趣,共$m + n - 1$个,此时共生成$wh(m + n - 1)$个锚框$$(s_1, r_1),(s_1, r_2),\cdots,(s_1, r_m),(s_2, r_1),(s_3, r_1),\cdots,(s_n, r_1)$$<jupyter_code>d2l.set_figsize()
img = Image.open('../img/catdog.jpg')
w, h = img.size
print("w = %d, h = %d" %(w, h)) # w = 728, h = 561
def MultiBoxPrior(feature_map, sizes=[0.75, 0.5, 0.25], ratios=[1, 2, 0.5]):
    """
    anchor表示为(xmin, ymin, xmax, ymax)
    
    Args:
        feature_map: torch tensor, Shape: [N, C, H, W]
        sizes: List of sizes (0~1) of generated MultiBoxPriores
        ratios: List of aspect ratios (non-negative) of generated MultiBoxPriores. 
    Returns:
        anchors of shape (1, num_anchors, 4). 由于batch里每个都一样, 所以第一维为1
    """
    paris = [] # pair of (size, sqrt(ration))
    for r in ratios:
        paris.append([sizes[0], math.sqrt(r)])
    for s in sizes[1:]:
        paris.append([s, math.sqrt(ratios[0])])
    
    paris = np.array(paris)
    
    ss1 = paris[:, 0] * paris[:, 1] # size * sqrt(ration)
    ss2 = paris[:, 0] / paris[:, 1] # size / sqrt(ration)
    
    base_anchors = np.stack([-ss1, -ss2, ss1, ss2], axis=1) / 2
    
    h, w = feature_map.shape[-2:]
    shifts_x = np.arange(0, w) / w
    shifts_y = np.arange(0, h) / h
    shift_x, shift_y = np.meshgrid(shifts_x, shifts_y) # 网格化
    shift_x = shift_x.reshape(-1)
    shift_y = shift_y.reshape(-1)
    shifts = np.stack((shift_x, shift_y, shift_x, shift_y), axis=1)
    
    anchors = shifts.reshape((-1, 1, 4)) + base_anchors.reshape((1, -1, 4))
    
    return torch.tensor(anchors, dtype=torch.float32).view(1, -1, 4)

X = torch.Tensor(1, 3, h, w) # 构造输入函数
Y = MultiBoxPrior(X, sizes=[0.75, 0.5, 0.25], ratios=[1, 2, 0.5])
Y.shape # torch.Size([1, 2042040, 4])<jupyter_output><empty_output><jupyter_text>1. 此时锚框变量$Y$的形状(1, 锚框数量, 4)2. 将锚框变量$Y$的形状变为（图像高，图像宽，以相同像素为中心的锚框个数，4）后,就可以通过指定像素位置来获取所有以该像素为中心的锚框了<jupyter_code># 以（250，250）为中心的第一个锚框
boxes = Y.reshape((h, w, 5, 4))
# 其中x和y轴的坐标值分别已除以图像的宽和高，因此值域均为0和1之间
boxes[250, 250, 0, :]<jupyter_output><empty_output><jupyter_text>> size和ratio分别为0.75和1, 则(归一化后的)宽高均为0.75, 所以输出是正确的（0.75 = 0.7184 + 0.0316 = 0.8206 - 0.0706）<jupyter_code>def show_bboxes(axes, bboxes, labels=None, colors=None):
    def _make_list(obj, default_values=None):
        if obj is None:
            obj = default_values
        elif not isinstance(obj, (list, tuple)):
            obj = [obj]
        return obj
    
    labels = _make_list(labels)
    colors = _make_list(colors, ['b', 'g', 'r', 'm', 'c'])
    
    for i, bbox in enumerate(bboxes):
        color = colors[i%len(colors)]
        rect = d2l.bbox_to_rect(bbox.detach().cpu().numpy(), color)
        axes.add_patch(rect)
        if labels and len(labels) > i:
            text_color = 'k' if color == 'w' else 'w'
            axes.text(rect.xy[0], rect.xy[1], labels[i],
                     va='center', ha='center', fontsize=6,
                     color=text_color, bbox=dict(facecolor=color, lw=0))
d2l.set_figsize()
fig = d2l.plt.imshow(img)
bbox_scale = torch.tensor([[w, h, w, h]], dtype=torch.float32)
show_bboxes(fig.axes, boxes[250, 250, :, :] * bbox_scale, 
           ['s=0.75, r=1', 's=0.75, r=2', 's=0.55, r=0.5', 's=0.5, r=1', 's=0.25, r=1'])<jupyter_output><empty_output><jupyter_text>9.4.2 交并比 1. 衡量锚框和真实边界框之间的相似度,Jaccard系数（Jaccard index）可以衡量两个集合的相似度2. 给定$\mathcal{A}$和$\mathcal{B}$,则Jaccard系数是二者交集大小除以二者并集大小:$$J(\mathcal{A}, \mathcal{B}) = \frac{\left|\mathcal{A} \cap \mathcal{B}\right|}{\left|\mathcal{A} \cup \mathcal{B}\right|}$$3. 可以将边界框内的像素区域看成是像素的集合,以用两个边界框的像素集合的Jaccard系数衡量这两个边界框的相似度,4. 通常将Jaccard系数称为交并比（Intersection over Union，IoU）,即两个边界框相交面积与相并面积之比，取值范围$[0, 1]$ ![交并比](img/9.4_iou.svg)<jupyter_code># 参考https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Object-Detection/blob/master/utils.py#L356
def compute_intersection(set_1, set_2):
    """
    计算anchor之间的交集
    Args:
        set_1: a tensor of dimensions(n1, 4), anchor 表示成(xmin, ymin, xmax, ymax)
        set_2: a tensor of dimensions(n2, 4), anchor 表示成(xmin, ymin, xmax, ymax)
    Returns:
        intersection of each of the boxes in set 1 with respect to each of the boxes in set 2, shape:(n1, n2)
    """
    # unsqueeze(i) 表示将第i维设置为1
    lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), set_2[:, :2].unsqueeze(0)) # (n1, n2, 2)
    upper_bounds = torch.min(set_1[:, 2:].unsqueeze(1), set_2[:, 2:].unsqueeze(0)) # (n1, n2, 2)
    # torch.clamp(input, min, max, out=None) → Tensor
    # 将输入input张量每个元素的夹紧到区间 [min,max]，超过这个区间,则用区间端点代替
    intersection_dims = torch.clamp(upper_bounds - lower_bounds, min=0) # (n1, n2, 2)
    return intersection_dims[:, :, 0] * intersection_dims[:, :, 1] # (n1, n2)

def compute_jaccard(set_1, set_2):
    """
    计算anchor之间的交集
    Args:
        set_1: a tensor of dimensions(n1, 4), anchor 表示成(xmin, ymin, xmax, ymax)
        set_2: a tensor of dimensions(n2, 4), anchor 表示成(xmin, ymin, xmax, ymax)
    Returns:
        Jaccard Overlap of each of the boxes in set 1 with respect to each of the boxes in set 2, shape: (n1, n2)
    """
    intersection = compute_intersection(set_1, set_2)
    
    areas_set_1 = (set_1[:, 2] - set_1[:, 0]) * (set_1[:, 3] - set_1[:, 1])
    areas_set_2 = (set_2[:, 2] - set_2[:, 0]) * (set_2[:, 3] - set_2[:, 1])
    
    union = areas_set_1.unsqueeze(1) + areas_set_2.unsqueeze(0) - intersection # (n1, n2)
    return intersection / union<jupyter_output><empty_output><jupyter_text>9.4.3 标注训练集的锚框 1. 为了训练目标检测模型，我们需要为每个锚框标注两类标签    - 锚框的类别    - 真实边界框相对锚框的偏移量，简称偏移量（offset）2. 目标检测：    1. 先生成多个锚框，然后为每个锚框预测类别以及偏移量    2. 根据预测的偏移量调整锚框位置从而得到预测边界框    3. 最后筛选需要输出的预测边界框3. 在训练集中:    1. 每个图像已标注了真实边界框的位置以及所类别    2. 生成锚框之后,依据与锚框相似的【真实边界框的位置】和类别信息为锚框标注4. 如何为锚框分配与其相似的真实边界框    1. 设图像中锚框分别为$A_1, A_2, \cdots, A_{n_a}$,真实边界框为$B_1, B_2, \cdots, B_{n_b}$,且$n_a \geq b_b$    2. 定义矩阵$\boldsymbol{X} \in \mathbb{R}^{n_a \times n_b}$,其中$\boldsymbol{X}[i][j] = x_{ij}$为锚框$A_i$和$B_j$的交并比    3. 找出矩阵$\boldsymbol{X}$中最大元素,行列索引分别为$i_{1}$,$j_{1}$,即为锚框$A_{i_1}$分配真实边界$B_{j_1}$,此时这两者在所有的“锚框—真实边界框”的配对中相似度最高    4. 将$\boldsymbol{X}$中第$x_1$行和$j_1$列所有元素丢弃,然后找出矩阵中剩余的最大元素,重复上面步骤    5. 最后有$n_b$列数据被丢弃,此时已为$n_b$个锚框各分配了一个真实边界框    6. 此时还剩下$n_a - n_b$个锚框,遍历,给定其中的锚框$A_i$,根据矩阵的第$i$行找到与之交并比最大的真实边界框$B_{j}$,且大于设定的阈值,才分配 1. 先找出最大值$x_{23}$,将为锚框$A_2$分配真实边界框$B_3$,然后丢弃第2行和第3列所有元素2. 找出剩余阴影部分最大元素$x_{71}$,将为锚框$A_7$分配真实边界框$B_1$,然后丢弃第7行和第1列所有元素3. 找出剩余阴影部分最大元素$x_{54}$,将为锚框$A_5$分配真实边界框$B_4$,然后丢弃第5行和第4列所有元素4. 找出剩余阴影部分最大元素$x_{92}$,将为锚框$A_9$分配真实边界框$B_2$,遍历除$A_2,A_5,A_7,A_9$以外剩余的锚框,并根据阈值判断是否分配 ![为锚框分配真实边界框](img/9.4_anchor-label.svg) 5. 如果一个锚框$A$被分配了真实边界框$B$,那么将锚框$A$的类别设为$B$的类别6. 根据两者中心坐标$(x_a, y_a),(x_b, y_b)$的相对位置以及两个框的相对大小为锚框$A$标注偏移量,宽高为$(w_a, h_a),(w_b, h_b)$,则$$\big(  \frac{\frac{x_b - x_a}{w_a} - \mu_x}{\sigma_x}, \frac{\frac{y_b - y_a}{h_a} - \mu_y}{\sigma_y} , \frac{\log{\frac{w_b}{w_a}} - \mu_w}{\sigma_w}  , \frac{\log{\frac{h_b}{h_a}} - \mu_h}{\sigma_h} \big)$$常数的默认值为$\mu_x=\mu_y=\mu_w=\mu_h=0,\sigma_x=\sigma_y=0.1,\sigma_w=\sigma_h=0.2$7. 如果一个锚框没有被分配真实边界框,将该锚框的类别设为背景,即负类锚框<jupyter_code># 第一个元素为类别（0为狗，1为猫），剩余4个元素分别为左上角的x和y轴坐标以及右下角的x和y轴坐标（值域在0到1之间）
bbox_scale = torch.tensor((w, h, w, h), dtype=torch.float32)
# 真实边界
ground_truth = torch.tensor([[0, 0.1, 0.08, 0.52, 0.92], [1, 0.55, 0.2, 0.9, 0.88]])

# 锚框
anchors = torch.tensor([[0, 0.1, 0.2, 0.3], [0.15, 0.2, 0.4, 0.4],
                    [0.63, 0.05, 0.88, 0.98], [0.66, 0.45, 0.8, 0.8],
                    [0.57, 0.3, 0.92, 0.9]])

fig = d2l.plt.imshow(img)
show_bboxes(fig.axes, ground_truth[:, 1:] * bbox_scale, ['dog', 'cat'], 'k')
show_bboxes(fig.axes, anchors * bbox_scale, ['0', '1', '2', '3', '4'])
# 为锚框标注类别和偏移量,将背景类别设为0，并令从零开始的目标类别的整数索引自加1（1为狗，2为猫）

def assign_anchor(bb, anchor, jaccard_threshold=0.5):
    """
    为每个anchor分配真实的bb, anchor表示成归一化(xmin, ymin, xmax, ymax)
    Args:
        bb: 真实边界框(bounding box), shape:（nb, 4）
        anchor: 待分配的anchor, shape:（na, 4）
        jaccard_threshold: 预先设定的阈值
    Returns:
        assigned_idx: shape: (na, ), 每个anchor分配的真实bb对应的索引, 若未分配任何bb则为-1
    """
    na = anchor.shape[0] # 锚框的数量
    nb = bb.shape[0]  #  真实边界的数量
    
    jaccard = compute_jaccard(anchor, bb).detach().cpu().numpy()  # shape (na, nb)
    assigned_idx = np.ones(na) * -1  # 初始全为-1
    # 先为每个bb分配一个anchor（此时不要求满足jaccard_threshold）
    jaccard_cp = jaccard.copy()
    for j in range(nb):
        i = np.argmax(jaccard_cp[:, j])
        assigned_idx[i] = j
        jaccard_cp[i, :] = float('-inf') # 相当于丢弃这一行
    
    # 处理还未被分配的anchor, 要求满足jaccard_threshold
    for i in range(na):
        if assigned_idx[i] == -1:
            j = np.argmax(jaccard[i, :])
            if jaccard[i, j] >= jaccard_threshold:
                assigned_idx[i] == j
    
    return torch.tensor(assigned_idx, dtype=torch.long)

def xy_to_cxcy(xy):
    """
    将(x_min, y_min, x_max, y_max)形式的anchor转换成(center_x, center_y, w, h)形式的
    Args:
        xy: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4)
    Returns: 
        bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4)
    """
    return torch.cat([(xy[:, 2:] + xy[:, :2]) / 2 , # c_x, c_y
                     xy[:, 2:] - xy[:, :2]], 1)

def MultiBoxTarget(anchor, label):
    """
    anchor表示成归一化(xmin, ymin, xmax, ymax).
    Args:
        anchor: torch tensor, 输入的锚框, 一般是通过MultiBoxPrior生成, shape:（1，锚框总数，4）
        label: 真实标签, shape为(bn, 每张图片最多的真实锚框数, 5)
               第二维中，如果给定图片没有这么多锚框, 可以先用-1填充空白, 最后一维中的元素为[类别标签, 四个坐标值]
    Returns:
        列表, [bbox_offset, bbox_mask, cls_labels]
        bbox_offset: 每个锚框的标注偏移量，形状为(bn，锚框总数*4)
        bbox_mask: 形状同bbox_offset, 每个锚框的掩码, 一一对应上面的偏移量, 负类锚框(背景)对应的掩码均为0, 正类锚框的掩码均为1
        cls_labels: 每个锚框的标注类别, 其中0表示为背景, 形状为(bn，锚框总数)
    """
    assert len(anchor.shape) == 3 and len(label.shape) == 3
    bn = label.shape[0] 
    def MultiBoxTarget_one(anc, lab, eps=1e-6):
        """
        MultiBoxTarget函数的辅助函数, 处理batch中的一个
        Args:
            anc: shape of (锚框总数, 4)
            lab: shape of (真实锚框数, 5), 5代表[类别标签, 四个坐标值]
            eps: 一个极小值, 防止log0
        Returns:
            offset: (锚框总数*4, )
            bbox_mask: (锚框总数*4, ), 0代表背景, 1代表非背景
            cls_labels: (锚框总数, 4), 0代表背景
        """
        an = anc.shape[0]
        assigned_idx = assign_anchor(lab[:, 1:], anc) # (锚框总数,)
        bbox_mask = ((assigned_idx >= 0).float().unsqueeze(-1)).repeat(1, 4) # (锚框总数, 4)
        
        cls_labels = torch.zeros(an, dtype=torch.long) # 0表示背景
        assigned_bb = torch.zeros((an, 4), dtype=torch.float32) # 所有anchor对应的bb坐标
        for i in range(an):
            bb_idx = assigned_idx[i]
            if bb_idx >= 0:  # 即非背景
                cls_labels[i] = lab[bb_idx, 0].long().item() + 1
                assigned_bb[i, :] = lab[bb_idx, 1:]
                
        center_anc = xy_to_cxcy(anc) # (center_x, center_y, w, h)
        center_assigned_bb = xy_to_cxcy(assigned_bb)
        
        offset_xy = 10.0 * (center_assigned_bb[:, :2] - center_anc[:, :2]) / center_anc[:, 2:]
        offset_wh = 5.0 * torch.log(eps + center_assigned_bb[:, 2:] / center_anc[:, 2:])
        offset = torch.cat([offset_xy, offset_wh], dim=1) * bbox_mask  # (锚框总数, 4)
        return offset.view(-1), bbox_mask.view(-1), cls_labels

    batch_offset = []
    batch_mask = []
    batch_cls_labels = []
    for b in range(bn):
        offset, bbox_mask, cls_labels = MultiBoxTarget_one(anchor[0, :, :], label[b, :, :])
        
        batch_offset.append(offset)
        batch_mask.append(bbox_mask)
        batch_cls_labels.append(cls_labels)
    
    bbox_offset = torch.stack(batch_offset)
    bbox_mask = torch.stack(batch_mask)
    cls_labels = torch.stack(batch_cls_labels)
    
    return [bbox_offset, bbox_mask, cls_labels]
labels = MultiBoxTarget(anchors.unsqueeze(dim=0), ground_truth.unsqueeze(dim=0))
labels[2]
labels[1]
labels[0]<jupyter_output><empty_output><jupyter_text>9.4.4 输出预测边界框<jupyter_code>anchors = torch.tensor([[0.1, 0.08, 0.52, 0.92], [0.08, 0.2, 0.56, 0.95],
                        [0.15, 0.3, 0.62, 0.91], [0.55, 0.2, 0.9, 0.88]])
offset_preds = torch.tensor([0.0] * (4 * len(anchors)))
cls_probs = torch.tensor([[0., 0., 0., 0.,],  # 背景的预测概率
                          [0.9, 0.8, 0.7, 0.1],  # 狗的预测概率
                          [0.1, 0.2, 0.3, 0.9]])  # 猫的预测概率
fig = d2l.plt.imshow(img)
show_bboxes(fig.axes, anchors * bbox_scale,
            ['dog=0.9', 'dog=0.8', 'dog=0.7', 'cat=0.9'])
from collections import namedtuple

Pred_BB_Info = namedtuple('Pred_BB_Info', ['index', 'class_id', 'confidence', 'xyxy'])

def non_max_suppresion(bb_info_list,  nms_threshold=0.5):
    """
    非极大抑制处理预测的边界框
    Args:
        bb_info_list: Pred_BB_Info的列表, 包含预测类别、置信度等信息
        nms_threshold: 阈值
    Returns:
        output: Pred_BB_Info的列表, 只保留过滤后的边界框信息
    """
    output = []
    # 据置信度从高到低排序
    sorted_bb_info_list = sorted(bb_info_list, key=lambda x : x.confidence, reverse=True)
    
    while(len(sorted_bb_info_list)) != 0:
        best = sorted_bb_info_list.pop(0)
        output.append(best)
        
        if len(sorted_bb_info_list) == 0:
            break
            
        bb_xyxy = []
        for bb in sorted_bb_info_list:
            bb_xyxy.append(bb.xyxy)
            
        iou = compute_jaccard(
            torch.tensor([best.xyxy]),
            torch.tensor(bb_xyxy))[0]  # shape: (len(sorted_bb_info_list), )
        
#         # shape: (len(sorted_bb_info_list), )
#         iou = compute_jaccard(
#             torch.tensor([best.xyxy]), torch.tensor(bb_xyxy))[0] 


        n = len(sorted_bb_info_list)
        
        sorted_bb_info_list = [sorted_bb_info_list[i] for i in range(n) if iou[i] <= nms_threshold]
    return output


def MultiBoxDetection(cls_prob, loc_pred, anchor, nms_threshold=0.5):
    
    """
    anchor表示成归一化(xmin, ymin, xmax, ymax).
    Args:
        cls_prob: 经过softmax后得到的各个锚框的预测概率, shape:(bn, 预测总类别数+1, 锚框个数)
        loc_pred: 预测的各个锚框的偏移量, shape:(bn, 锚框个数*4)
        anchor: MultiBoxPrior输出的默认锚框, shape: (1, 锚框个数, 4)
        nms_threshold: 非极大抑制中的阈值
    Returns:
        所有锚框的信息, shape: (bn, 锚框个数, 6)
        每个锚框信息由[class_id, confidence, xmin, ymin, xmax, ymax]表示
        class_id=-1 表示背景或在非极大值抑制中被移除了
    """
    assert len(cls_prob.shape) == 3 and len(loc_pred.shape) == 2 and len(anchor.shape) == 3
    bn = cls_prob.shape[0]
    
    def MultiBoxDetection_one(c_p, l_p, anc, nms_threshold=0.5):
        """
        MultiBoxDetection的辅助函数, 处理batch中的一个
        Args:
            c_p: (预测总类别数+1, 锚框个数)
            l_p: (锚框个数*4, )
            anc: (锚框个数, 4)
            nms_threshold: 非极大抑制中的阈值
        Return:
            output: (锚框个数, 6)
        """
        pred_bb_num = c_p.shape[1]
        anc = (anc + l_p.view(pred_bb_num, 4)).detach().cpu().numpy() # 加上偏移量
        
        confidence, class_id = torch.max(c_p, 0)
        confidence = confidence.detach().cpu().numpy()
        class_id = class_id.detach().cpu().numpy()
        
        pred_bb_info = [Pred_BB_Info(
            index=1,
            class_id=class_id[i] - 1,  # 正类label从0开始
            confidence=confidence[i],
            xyxy=[*anc[i]]) # xyxy是个列表
            for i in range(pred_bb_num)
            ]
        
        # 正类的index
        obj_bb_idx = [bb.index for bb in non_max_suppresion(pred_bb_info, nms_threshold)]
        
        output = []
        
        for bb in pred_bb_info:
            output.append([
                (bb.class_id if bb.index in obj_bb_idx else -1.0),
                bb.confidence,
                *bb.xyxy
            ])
            
        return torch.tensor(output) # shape: (锚框个数, 6)
    
    batch_output = []
    for b in range(bn):
        batch_output.append(MultiBoxDetection_one(cls_prob[b], loc_pred[b], anchor[0], nms_threshold))
    
    return torch.stack(batch_output)
output = MultiBoxDetection(
    cls_probs.unsqueeze(dim=0), offset_preds.unsqueeze(dim=0),
    anchors.unsqueeze(dim=0), nms_threshold=0.5
)
output
fig = d2l.plt.imshow(img)
for i in output[0].detach().cpu().numpy():
    if i[0] == -1:
        continue
    label = ('dog=', 'cat=')[int(i[0])] + str(i[1])
    show_bboxes(fig.axes, [torch.tensor(i[2:]) * bbox_scale], label)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16237836547071816, 'fraction_numerical': 0.038624559727777445, 'mean_word_length': 3.006696962449175, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 35, 'https://': 1, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '40133', 'license': 'MIT', 'n_tokens_mistral': 8651, 'n_tokens_neox': 8830, 'n_words': 1233, 'path': 'dl/dive-into-dl/chapter09_computer-version/9.04_anchor.ipynb', 'repo_name': 'tangchunbo/machine-learning', 'size': '16751'}