labelme目标检测数据类型转换

1. labelme数据类型

LabelMe是一个开源的在线图像标注工具,旨在帮助用户创建和标记图像数据集。它提供了一个用户友好的界面,让用户可以直观地在图像上绘制标记框、多边形、线条等,以标识和注释图像中的对象或区域。
GitHub:https://github.com/wkentaro/labelme

labelme格式

经过labelme标注工具对图像中的目标进行标注之后,可以得到如下的标注json文件。在这里插入图片描述
在这里我们主要关注目标框的格式,其中shapes字段中包含所有的目标内容,每个目标框的位置信息可以通过points字段进行获取,是一个两行两列的二维数组,如同:

[
	[a,b],
	[c,d]
]

其中a,b代表左上角点位置,c,d表示右下角点位置,如下图所示。
在这里插入图片描述

目标框可视化

对于labelme格式的数据,可以直接使用labelme标注工具打开进行查看,同样这里也给出python的可视化代码,方便大家直接画图进行查看。


import numpy as np
import os
import cv2
import json

def display(img_path, bboxes, save_path,opencv=True):
    """_summary_

    Args:
        img_path (str): 图像路径
        bboxes (numpy): 二维数组,其中每一行表示一个目标框,顺序为(xmin, ymin, xmax, ymax)
        opencv (bool): 是否使用opencv
    """
    
    if opencv:
        color = (0, 0, 255)
        img_data = cv2.imread(img_path)
        for box in bboxes:
            xmin, ymin, xmax, ymax = np.array(box, dtype=np.int32)
            cv2.rectangle(img_data, (xmin, ymin), (xmax, ymax),color, 2)
        cv2.imwrite(save_path, img_data)
    else:
        from PIL import Image, ImageDraw
        color = (255, 0, 0)
        img_data = Image.open(img_path).convert("RGB")
        
        draw = ImageDraw.Draw(img_data)
        for box in bboxes:
            xmin, ymin, xmax, ymax = np.array(box, dtype=np.int32)
            draw.rectangle([xmin, ymin, xmax, ymax], outline=color)
        img_data.save(save_path)
        
        
def vis_labelme(img_root, json_root, save_root):
    """_summary_

    Args:
        img_root (str): 图像数据的主路径
        json_root (str): 标签数据的主路径
        save_root (str): 可视化图像保存路径
    """
    from pathlib import Path
    
    json_files = Path(json_root).glob("./*.json")
    
    for json_path in json_files:
        anno= json.load(open(str(json_path), "r", encoding="utf-8"))
        shapes = anno['shapes']
        
        name = json_path.stem
        
        img_path = Path(img_root) / f"{name}.jpg"
        if img_path.is_file():
            bboxes = list()
            for s in shapes:
                pts = s['points']
                x1, y1 = pts[0]
                x2, y2 = pts[1]
                bboxes.append([x1, y1, x2, y2])
            save_path = os.path.join(save_root, img_path.name)
            display(str(img_path), bboxes, save_path)
            

if __name__ == "__main__":
    img_root = "labelme"
    json_root = "labelme"
    save_root = "vis_labelme"
    vis_labelme(img_root, json_root, save_root)

2. 与yolo之间的转换

YOLO(You Only Look Once)是一种流行的目标检测算法,其特点是能够实时地识别图像中的目标物体。YOLO格式是指用于标注目标检测数据集的标签格式。

在YOLO格式中,每个图像的标签数据通常存储在一个单独的文本文件中,与图像文件具有相同的名称。

yolo格式

每个标签文件包含一行或多行文本,每行描述一个目标物体的位置和类别。每行的格式如下:

<class> <x_center> <y_center> <width> <height>
  • <class> 表示目标物体的类别,通常是一个整数。例如,如果数据集包含车辆、行人和自行车三个类别,可以用0表示车辆,1表示行人,2表示自行车。
  • <x_center><y_center> 是目标物体边界框的中心坐标,相对于图像的宽度和高度。这些值的范围是0到1之间,表示相对位置。
  • <width><height> 是目标物体边界框的宽度和高度,相对于图像的宽度和高度。同样,这些值的范围也是0到1之间

例如,假设我们有一个图像中包含一辆车的标签数据,车辆在图像中的位置为(100,200),宽度为50,高度为30。如果图像的宽度是500,高度是400,那么对应的YOLO格式标签数据将是:

0 0.25 0.5 0.1 0.075

使用YOLO格式的标签数据可以方便地与YOLO模型进行训练和推断,从而实现目标检测任务。

labelme转yolo

以下是labelme转换yolo格式的脚本,需要制定labelme和yolo数据集的主路径,此外还需要一个数据集类别的txt文件。

import os
import json
import shutil
import numpy as np
from pathlib import Path


def get_categories(cls_path):
    assert(os.path.exists(cls_path)), f"cannot find classes file"

    with open(cls_path) as f:
        data = f.readlines()
    name2idx = dict()
    for idx, cls in enumerate(data):
        name2idx[cls.strip()] = idx
    
    return name2idx

def labelme2yolo_single(label_file, cls2id):
    anno= json.load(open(label_file, "r", encoding="utf-8"))
    shapes = anno['shapes']
    w0, h0 = anno['imageWidth'], anno['imageHeight']
    image_path = os.path.basename(anno['imagePath'])
    labels = []
    for s in shapes:
        pts = s['points']
        x1, y1 = pts[0]
        x2, y2 = pts[1]
        x = (x1 + x2) / 2 / w0 
        y = (y1 + y2) / 2 / h0
        w  = abs(x2 - x1) / w0
        h  = abs(y2 - y1) / h0
        cid = cls2id[s['label']]        
        labels.append([cid, x, y, w, h])
    return labels, image_path
 
def labelme2yolo(labelme_dir, yolo_dir, cls_path):
    labelme_img_dir = Path(labelme_dir) 
    labelme_label_dir = Path(labelme_dir)
    
    
    yolo_img_dir = Path(yolo_dir) / "images/"
    yolo_label_dir = Path(yolo_dir) / 'labels/'

    if not yolo_img_dir.exists():
        yolo_img_dir.mkdir(parents=True, exist_ok=True)
    if not yolo_label_dir.exists():
        yolo_label_dir.mkdir(parents=True, exist_ok=True)
 
    json_files = labelme_label_dir.glob("./*.json")
    cls2id = get_categories(cls_path)
    for ijf, jf in enumerate(json_files):
        
        filename = jf.stem
        labels, image_path = labelme2yolo_single(jf, cls2id)
        # if len(labels) > 0:
        # np.savetxt(yolo_label_dir + filename + '.txt', labels)
        shutil.copy(str(labelme_img_dir / image_path), str(yolo_img_dir / image_path))
        txt_path = str(yolo_label_dir / f"{filename}.txt")
        with open(txt_path, 'w') as f:
            for cls, *xywhn in reversed(labels):
                line = (cls, *xywhn)
                f.write(('%g ' * len(line)).rstrip() % line + '\n')
        print(f" {ijf} {str(jf)}")
    print('Completed!')
    
if __name__ == '__main__':
    labelme_root = r'labelme'
    yolo_root = r'yolo'
    cls_path = "yolo/classes.txt"
    labelme2yolo(labelme_root, yolo_root, cls_path)

yolo转labelme

同样,有时候我们可以以labelme数据格式作为中间格式,然后把labelme格式转换为其他格式,或者我们需要对yolo目标检测算法的结果进行微调,因此,这里也提供了yolo转labelme的脚本。

import cv2
import os
import json
import shutil
import numpy as np
 
def get_categories(cls_path):
    assert(os.path.exists(cls_path)), f"cannot find classes file"

    with open(cls_path) as f:
        data = f.readlines()
    idx2name = dict()
    for idx, cls in enumerate(data):
        idx2name[idx] = cls.strip()
    
    return idx2name
 
def xyxy2labelme(labels, w, h, image_path, save_dir, id2cls):
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    label_dict = {}
    label_dict['version'] = '5.0.1'
    label_dict['flags'] = {}
    label_dict['imageData'] = None
    label_dict['imagePath'] = image_path
    label_dict['imageHeight'] = h
    label_dict['imageWidth'] = w
    label_dict['shapes'] = []
    for l in labels:
        tmp = {}
        tmp['label'] = id2cls[int(l[0])]
        tmp['points'] =[[l[1], l[2]], [l[3], l[4]]]
        tmp['group_id']= None
        tmp['shape_type'] = 'rectangle'
        tmp['flags'] = {}
        label_dict['shapes'].append(tmp)    
    fn = os.path.join(save_dir,image_path.rsplit('.', 1)[0]+'.json')
    with open(fn, 'w') as f:
        json.dump(label_dict, f, ensure_ascii=False, indent=2)
 
def yolo2labelme(yolo_dir, save_dir, cls_path):
    yolo_image_dir = os.path.join(yolo_dir, "images")
    yolo_label_dir = os.path.join(yolo_dir, "labels")
    id2cls = get_categories(cls_path)
    image_files = os.listdir(yolo_image_dir)
    for iimgf, imgf in enumerate(image_files):
        print(iimgf+1, '/', len(image_files), imgf)
        fn = imgf.rsplit('.', 1)[0]
        
        image = cv2.imread(os.path.join(yolo_image_dir, imgf))
        h,w = image.shape[:2]
        shutil.copyfile(os.path.join(yolo_image_dir, imgf), os.path.join(save_dir, imgf))
        if not os.path.exists(os.path.join(yolo_label_dir, fn + '.txt')):
            continue
        labels = np.loadtxt(os.path.join(yolo_label_dir, fn + '.txt')).reshape(-1, 5)
        if len(labels) < 1:
            pass
        else:
            labels[:,1::2] = w * labels[:, 1::2]
            labels[:,2::2] = h * labels[:, 2::2]
            labels_xyxy = np.zeros(labels.shape)
            labels_xyxy[:, 1] = np.clip(labels[:, 1] - labels[:, 3]/2, 0, w)
            labels_xyxy[:, 2] = np.clip(labels[:, 2] - labels[:, 4]/2, 0, h)
            labels_xyxy[:, 3] = np.clip(labels[:, 1] + labels[:, 3]/2, 0, w)
            labels_xyxy[:, 4] = np.clip(labels[:, 2] + labels[:, 4]/2, 0, h)
        xyxy2labelme(labels_xyxy, w, h, imgf, save_dir, id2cls)
    print('Completed!')
 
if __name__ == '__main__':
    yolo_dir = "yolo"
    save_dir = "labelme"
    cls_path = "yolo/classes.txt"
    yolo2labelme(yolo_dir, save_dir, cls_path)

可视化

与labelme可视化一样,只需要解析yolo格式的标签文件,然后传入到display函数中即可。


import numpy as np
import os
import cv2
from pathlib import Path
import copy


def display(img_path, bboxes, save_path,opencv=True):
    """_summary_

    Args:
        img_path (str): 图像路径
        bboxes (numpy): 二维数组,其中每一行表示一个目标框,顺序为(xmin, ymin, xmax, ymax)
        opencv (bool): 是否使用opencv
    """
    
    if opencv:
        color = (0, 0, 255)
        img_data = cv2.imread(img_path)
        for box in bboxes:
            xmin, ymin, xmax, ymax = np.array(box, dtype=np.int32)
            cv2.rectangle(img_data, (xmin, ymin), (xmax, ymax),color, 2)
        cv2.imwrite(save_path, img_data)
    else:
        from PIL import Image, ImageDraw
        color = (255, 0, 0)
        img_data = Image.open(img_path).convert("RGB")
        
        draw = ImageDraw.Draw(img_data)
        for box in bboxes:
            xmin, ymin, xmax, ymax = np.array(box, dtype=np.int32)
            draw.rectangle([xmin, ymin, xmax, ymax], outline=color)
        img_data.save(save_path)

def xywhn2xyxy(x, w=640, h=640, padw=0, padh=0):
    # Convert nx4 boxes from [x, y, w, h] normalized to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right
    y = copy.deepcopy(x)
    y[0] = w * (x[0] - x[2] / 2) + padw  # top left x
    y[1] = h * (x[1] - x[3] / 2) + padh  # top left y
    y[2] = w * (x[0] + x[2] / 2) + padw  # bottom right x
    y[3] = h * (x[1] + x[3] / 2) + padh  # bottom right y
    return y        
        
def vis_yolo(yolo_dir, save_root):
    """_summary_

    Args:
        yolo_dir (str): yolo数据集路径
        save_root (str): 图像保存路径
    """
    yolo_img_dir = Path(yolo_dir) / "images/"
    yolo_label_dir = Path(yolo_dir) / 'labels/'

    txt_files = yolo_label_dir.glob("./*.txt")
    for txt_path in txt_files:
        with open(txt_path, "r") as f:
            label_data = f.readlines()

        name = txt_path.stem
        img_path = yolo_img_dir / f"{name}.jpg"
        if img_path.is_file():
            img_data = cv2.imread(str(img_path))
            h0, w0, _ = img_data.shape
            bboxes = list()
            for bbox in label_data:
                bbox = bbox.split(" ")
                xywh = [float(x) for x in bbox[1:]]
                xyxy = xywhn2xyxy(xywh, w=w0, h=h0)
                bboxes.append(xyxy)
            save_path = os.path.join(save_root, img_path.name)
            display(str(img_path), bboxes, save_path)
            

if __name__ == "__main__":
    yolo_root = "yolo"
    save_root = "vis_yolo"
    vis_yolo(yolo_root, save_root)

3. 与coco之间的转换

COCO(Common Objects in Context)是一个常用的目标检测、语义分割和图像标注任务的数据集格式。COCO数据集是一个大规模的图像数据集,包含了多个类别的目标物体和对应的标注信息。

COCO数据集的标注信息以JSON格式存储,其中包含了图像的信息、目标物体的类别、边界框的位置、分割掩码等。

coco格式

COCO数据集的每个图像对应一个JSON文件,其中的主要字段包括:

  • “info”: 数据集的相关信息,如版本、作者等。
  • “licenses”: 数据集的许可证信息。
  • “images”: 图像的信息,包括图像ID、文件名、宽度、高度等。
  • “annotations”: 目标物体的标注信息,包括目标ID、类别ID、边界框位置、分割掩码等。
  • “categories”: 目标类别的信息,包括类别ID和类别名称。

具体而言,每个标注信息的格式如下:

{
    "id": <annotation_id>,
    "image_id": <image_id>,
    "category_id": <category_id>,
    "bbox": [x, y, width, height],
    "segmentation": <segmentation_data>,
    "area": <area>,
    "iscrowd": <iscrowd>
}
  • "id" 表示标注的唯一ID。
  • "image_id" 表示对应图像的ID。
  • "category_id" 表示目标物体所属的类别ID。
  • "bbox" 表示目标物体的边界框位置,由左上角顶点的坐标 (x, y) 和宽度、高度 (width, height) 组成。
  • "segmentation" 表示目标物体的分割掩码,可以是多边形或二进制掩码。
  • "area" 表示目标物体的面积。
  • "iscrowd" 表示目标物体是否是密集分布的群体。

COCO数据集提供了丰富的目标检测和分割任务所需的信息,使得研究者和开发者能够更好地进行算法的训练和评估。

labelme转coco

labelme和coco之间的转换脚本如下:

import os
import json
from tqdm import tqdm
from pathlib import Path
import shutil

def read_json(json_path):
    with open(json_path) as f:
        json_data = json.load(f)
        
    return json_data

def get_categories(cls_path):
    assert(os.path.exists(cls_path)), f"cannot find classes file"

    with open(cls_path) as f:
        data = f.readlines()
    res = list()
    name2idx = dict()
    for idx, cls in enumerate(data):
        res.append({"id":idx + 1, "name": cls.strip()})
        name2idx[cls.strip()] = idx + 1
    
    return res, name2idx

def get_image(json_data, image_id):
    image_dict = {}
    image_dict['height'] = json_data["imageHeight"]
    image_dict['width'] = json_data["imageWidth"]
    image_dict['id'] = image_id
    image_dict['file_name'] = json_data["imagePath"]
    return image_dict

def construct_annotation(img_id, ann_id, category_id, bbox, area, iscrowd=0):
    annotation = {}
    annotation['id'] = ann_id
    annotation['image_id'] = img_id
    annotation['category_id'] = category_id
    annotation['bbox'] = bbox
    annotation['area'] = area
    annotation['iscrowd'] = iscrowd
    annotation['segmentation'] = []
    
    return annotation

def get_annotation(objects, image_id, annotation_id, name2idx):
    
    annotation_list = []
    for item in objects:
        points = item["points"]
        # points = [round(x, 2) for x in points]      # [x1, y1, x2, y2]
        x1, y1 = points[0]
        x2, y2 = points[1]
        
        box_w = abs(x2 - x1)
        box_h = abs(y2 - y1)
        points = [x1, y1, box_w, box_h]
        tagtype = item["label"]   

        category_id = name2idx[tagtype]
        area = box_w * box_h   
                
        annotation_list.append(construct_annotation(image_id, annotation_id, category_id, points, area))
        annotation_id += 1
    return annotation_list, annotation_id

def save_coco_json(instance, save_path):
    import io
    with io.open(save_path, 'w', encoding="utf-8") as outfile:
        my_json_str = json.dumps(instance, ensure_ascii=False, indent=1)
        outfile.write(my_json_str)


def construct_coco(labelme_root, coco_img_root, coco_anno_root, cls_path):
    # 1. 构建COCO格式结构
    instance = {}
    instance['info'] = 'spytensor created'
    instance['license'] = ['license']
    # 2. 获取类别信息
    instance['categories'], name2idx =  get_categories(cls_path)

    images_all = []
    image_id = 1
    annotations_all = []
    annotation_id = 1
    json_files = Path(labelme_root).glob("./*.json")
    
    for json_path in tqdm(json_files):   
        
        json_data = read_json(json_path)
        img_name = json_data["imagePath"]
        objects = json_data['shapes']
        if not os.path.exists(os.path.join(labelme_root, img_name)): continue
        if len(objects)==0 :
            print(f"no object existed in {img_name}")
            # continue
        else:
            # 处理标注数据内容
            annotation_list, annotation_id = get_annotation(objects, image_id, annotation_id, name2idx)
            annotations_all.extend(annotation_list)
            
        img_dict = get_image(json_data, image_id)
        images_all.append(img_dict)
        image_id += 1
        
        shutil.copyfile(os.path.join(labelme_root, img_name), os.path.join(coco_img_root, img_name))
    
    instance['images'] = images_all
    instance['annotations'] = annotations_all
    save_coco_json(instance, coco_anno_root)

if __name__ == "__main__":
    labelme_root = "labelme"
    coco_img_root = "coco/train"
    coco_anno_path = "coco/annotations/train.json"
    cls_path  = "coco/classes.txt"
    construct_coco(labelme_root, coco_img_root, coco_anno_path, cls_path)

可视化

coco格式数据可视化需要安装pycocotools库,脚本需要指定coco数据集的图像位置和json位置,以及最后可视化结果保存位置。

from pycocotools.coco import COCO
from PIL import Image, ImageDraw
import os

def display(coco, img_id, img_root, save_root, cat_ids=None):
    """
    基于给定的img_id, 可视化其标注内容
    """
    # 获取images字段内容
    images = coco.loadImgs(ids=[img_id])[0]
    
    # 获取到annotation结构体
    annotation_id = coco.getAnnIds(imgIds=images['id'], catIds=cat_ids, iscrowd=None)
    # 加载对应的annotation结构体内容
    annotations = coco.loadAnns(annotation_id)
    print(annotations)
    file_path = os.path.join(img_root, images["file_name"])
    # print(file_path)
    img_data = Image.open(file_path).convert("RGB")

    draw = ImageDraw.Draw(img_data)
    for anno in annotations:
        bbox = anno["bbox"]
        x1, y1, box_w, box_h = bbox
        x2, y2 = x1 + box_w, y1 + box_h
        x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)

        draw.rectangle([x1,y1,x2,y2], outline=(255, 0,0 ))
    img_data.save(os.path.join(save_root, os.path.basename(images["file_name"])))

if __name__ == "__main__":
    annFile="coco/annotations/train.json"
    # 初始化标注数据的 COCO api 
    coco=COCO(annFile)
    # 获取COCO数据集所有的类别ID
    class_ids = coco.getCatIds()
    # 获取catIds对应的所有image_id
    imgIds = coco.getImgIds(catIds=class_ids )
    img_ids = imgIds
    for id in img_ids:
        display(coco, img_id=id, cat_ids=[1], img_root="coco/train", save_root="vis_coco/")

总结

本文中,主要介绍了labelme在目标检测任务中的用法,以及对应的数据格式。重点在于给出了labelme与常见目标检测数据格式yolo和coco之间相互转换的脚本,并提供各自的可视化脚本用于检查转换后格式是否正确。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/269483.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

孔夫子二手书采集

文章目录 项目演示软件采集单本数据网页搜索数据对比 使用场景概述部分核心逻辑Vb工程图数据导入与读取下拉框选择参数设置线程 使用方法下载软件授权导入文件预览处理后的数据 项目结构附件说明 项目演示 操作视频详见演示视频&#xff0c;以下为图文演示 软件采集单本数据 …

unity中使用protobuf工具将proto文件转为C#实体脚本

unity中使用protobuf工具将proto文件转为C#实体脚本 介绍优点缺点Protobuf 为什么比 XML 快得多&#xff1f;Protobuf的EncodingProtobuf封解包的过程通常编写一个Google Protocol Buffer应用需要以下几步&#xff1a; Protostuff是什么Protobuf工具总结 介绍 protobuf也就是G…

设计模式--适配器模式

实验8&#xff1a;适配器模式 本次实验属于模仿型实验&#xff0c;通过本次实验学生将掌握以下内容&#xff1a; 1、理解适配器模式的动机&#xff0c;掌握该模式的结构&#xff1b; 2、能够利用适配器模式解决实际问题。 [实验任务]&#xff1a;双向适配器 实现一个双向…

Java学习时间和日期

1 常用类 1.1 Date 表示日期 具体类 设置时间 1.2 Calendar 表示日历 抽象类 设置日历的设定日期 void set(int year,int month,int date); void set(int year,int month, int date, int hour, int minute,int second); void setTime(Date d); int get(int field)&#…

直播的内容多样性

直播&#xff0c;作为一种新兴的媒体形式&#xff0c;已经深入到我们生活的方方面面。其内容多样性是吸引观众的关键因素之一。以下是直播内容多样性的几个主要方面: 1.主题多样性:直播涵盖的主题非常广泛&#xff0c;包括但不限于娱乐、游戏、体育、教育、招聘、新闻、金融、…

VS2020使用MFC开发一个贪吃蛇游戏

背景&#xff1a; 贪吃蛇游戏 按照如下步骤实现:。初始化地图 。通过键盘控制蛇运动方向&#xff0c;注意重新设置运动方向操作。 。制造食物。 。让蛇移动&#xff0c;如果吃掉食物就重新生成一个食物&#xff0c;如果会死亡就break。用蛇的坐标将地图中的空格替换为 #和”将…

Druid源码阅读-DruidStatInterceptor实现

上次我们在druid-spring-boot-starter里面看到有一个DruidSpringAopConfiguration的配置类&#xff0c;然后引入了DruidStatInterceptor这样一个切面逻辑。今天我们就来看一下这个类的实现。 DruidStatInterceptor 这个类的包路径下入com.alibaba.druid.support.spring.stat。…

DC电源模块有哪些注意事项和使用技巧?

BOSHIDA DC电源模块有哪些注意事项和使用技巧&#xff1f; DC电源模块的注意事项和使用技巧包括以下几点&#xff1a; 1. 选择适当的电源模块&#xff1a;根据需要选择合适的电源模块&#xff0c;考虑电压、电流和功率等参数。确保模块能够满足所需的电力要求。 2. 输入电压范…

销售如何挖掘客户?有哪些方法?

在当今竞争激烈的市场环境中&#xff0c;客户资源的挖掘已经成为企业生存和发展的关键。销售人员需要掌握一定的技巧和方法&#xff0c;以有效地发掘潜在客户&#xff0c;提高销售业绩。以下分享一些挖掘客户的常用方法&#xff0c;帮助销售人员更好地开展业务。 一、了解客户需…

IP编址,IP地址介绍与子网划分方法

网络层位于数据链路层与传输层之间。网络层中包含了许多协议&#xff0c;其中最为重要的协议就是IP协议。网络层提供了IP路由功能。理解IP路由除了要熟悉IP协议的工作机制之外&#xff0c;还必须理解IP编址以及如何合理地使用IP地址来设计网络。 上层协议类型 以太网帧中的Typ…

Tailwind CSS 原子化开发初体验

Tailwind CSS 的工作原理是扫描所有 HTML 文件、JavaScript 组件以及任何模板中的 CSS 类&#xff08;class&#xff09;名&#xff0c;然后生成相应的样式代码并写入到一个静态 CSS 文件中。他快速、灵活、可靠&#xff0c;没有运行时负担。再也不用为了取一个 classname 类名…

GAMES101-LAB1

文章目录 一、问题总览二、作业参考2.1 get_projection_matrix()函数2.2 static bool insideTriangle()函数2.3 rasterize_triangle() 三、附件 一、问题总览 在屏幕上画出一个实心三角形&#xff0c;换言之&#xff0c;栅格化一个三角形实现并调用函数rasterize_triangle(con…

【MySQL基础】:超详细MySQL完整安装和配置教程

&#x1f3a5; 屿小夏 &#xff1a; 个人主页 &#x1f525;个人专栏 &#xff1a; MySQL从入门到进阶 &#x1f304; 莫道桑榆晚&#xff0c;为霞尚满天&#xff01; 文章目录 &#x1f4d1;前言一. MySQL数据库1.1 版本1.2 下载1.3 安装1.4 客户端连接 &#x1f324;️全篇总…

python使用selenium控制浏览器进行爬虫

这里以谷歌浏览器为例&#xff0c;需要安装一下chromedriver&#xff0c;其他浏览器也有相对应的driver&#xff0c;chromedriver下载地址&#xff1a;https://googlechromelabs.github.io/chrome-for-testing/ 然后是打开python环境安装一下依赖pip install selenium&#xf…

json-server实现数据Mock

json-server是一个node包&#xff0c;可以在不到30秒内获得零编码的完整的Mock服务实现步骤&#xff1a;1. 项目内安装json-server ---> npm i -D json-server2. 准备一个json文件 在根目录下&#xff08;src同级&#xff09;创建server文件夹&#xff0c;创建data.json文…

【数据结构】字符串匹配|BF算法|KMP算法|next数组的优化

字符串匹配算法是在实际工程中经常遇到的问题&#xff0c;也是各大公司笔试面试的常考题目&#xff0c;本文主要介绍BF算法&#xff08;最好想到的算法&#xff0c;也最好实现&#xff09;和KMP算法&#xff08;最经典的&#xff09; 一、BF算法 BF算法&#xff0c;即暴力(Bru…

[java] 转义字符控制台最常用快捷键

转义字符 1&#xff09;\t&#xff1a;一个制表位&#xff0c;实现对齐的功能 2&#xff09;\n&#xff1a;换行符 3) \\&#xff1a;一个\ 4&#xff09;\"&#xff1a;一个" 5) \&#xff1a;一个 6) \r&#xff1a;一个回车System.out.println(我亦无他AA\r唯…

Wordpress对接Lsky Pro 兰空图床插件

Wordpress对接Lsky Pro 兰空图床插件 wordpress不想存储图片到本地&#xff0c;访问慢&#xff0c;wordpress图片没有cdn想要使用图床&#xff0c;支持兰空自定义接口 安装教程—在wp后台选择插件zip—然后启用—设置自己图床API接口就ok了&#xff0c;文件全部解密&#xff0c…

pytorch 踩坑

pytorch 踩坑 在pytorch中&#xff0c;如果你定义了没用的组件&#xff0c;同样也会影响你的模型(我也不知道从哪里影响的)&#xff0c;看一个例子 def _make_layer(self, block, planes, blocks, stride1, dilateFalse):norm_layer self._norm_layer#downsample Noneprevio…

SQL变更评审常见问题分享

SQL变更评审分享 概述 SQL变更&#xff0c;是我们在开发迭代中不可避免的场景&#xff0c;SQL变更通常是指DDL和DML语句变更&#xff0c;这些sql会影响到数据库表结构或具体数据&#xff0c;变更时如果执行到存在问题的sql脚本&#xff0c;会对实际应用操作难以评估的损失&…
最新文章