Mesh-gpt(点处理、保存脚本,Transformer)

小结:

1、配置了学长的环境,并编写点处理(旋转、镜像)和保存(由内存numpy数组到shp文件)脚本。

2、初步阅读mesh-gpt论文,思考Transformer网络架构(翻译模型和补全模型的训练区别)

环境配置#

pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu118
image-20240830135620846
pip install git+https://github.com/peng0817-3dv/floorplan-reconsturtion-based-plane-triangle.git
image-20240830140108251
pip list
image-20240830140537015

安装缺少的库

pip install pytest
pip install matplotlib

1、尝试运行test/load_shp_test.py ,报错

image-20240830141430457

多种办法完美解决AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘_matplotlib.use('tkagg')-CSDN博客

添加

image-20240830141845964

成功运行test/load_shp_test.py ,并生成load_shp_test目录结果

image-20240830141932244

数据增强#

faces和edges存的是vertices的索引(face是三个点+置信度信息;edge是两个点+置信度信息),也就是说face和edge本身并不包含任何位置信息,有位置的是vertices的坐标。

数据结构

vertices = [(x1, y1), (x2, y2), ...]
vertices_confidence = [pv1, pv2, ...]

edges = [(1, 0), (15, 1), ...] #边的两端点序号
edges_confidence = [ev1, ev2, ...]
point_id_to_edges_id = { point1_id : [edge1_id,edge2_id,...], point2_id:[...] }

faces = [(15, 1, 0), (39, 60, 38), ...] # 边的三端点序号
faces_confidences = [ef1, ef2, ...]
faces_label = [-1, -1, ...]

image-20240831114117795

所以生成旋转/翻转的数据(数据增强)实际上是对点集vertices的处理

原始点集

image-20240830193251325

在加载点的函数get_vertices_data中对点进行90度旋转

在二维空间中,绕原点逆时针旋转一个角度θ的变换可以用以下公式表示:

新的x' = x * cos(θ) - y * sin(θ)
新的y' = x * sin(θ) + y * cos(θ)

对于90度的旋转(θ = 90° 或 π/2 弧度),cos(π/2) = 0 且 sin(π/2) = 1,所以变换公式简化为:

新的x' = -y
新的y' = x

image-20240830202655128

结果(左侧为原始的,右侧为旋转90度)

image-20240830203613806

image-20240830203349162

image-20240830203400637

image-20240830203414315

image-20240830203426694

封装函数

定义rotate_vertices对点进行旋转,旋转角度(90 / 180 / 270)

定义mirror_vertices对点进行镜像,镜像轴(x / y)

def rotate_vertices(vertices, angle):
    """
    对点进行旋转
    :param vertices:
    :param angle: 旋转角度(90 / 180 / 270)
    :return:
    """
    if angle == 90:
        rotated_vertices = [(-y, x) for x, y in vertices]
    elif angle == 180:
        rotated_vertices = [(-x, -y) for x, y in vertices]
    elif angle == 270:
        rotated_vertices = [(y, -x) for x, y in vertices]

    return rotated_vertices

def mirror_vertices(vertices, axis):
    """
    对点进行镜像
    :param vertices:
    :param axis: 镜像轴(x / y)
    :return:
    """
    if axis == 'x':
        mirrored_vertices = [(x, -y) for x, y in vertices]
    elif axis == 'y':
        mirrored_vertices = [(-x, y) for x, y in vertices]
    return mirrored_vertices

只需要加载点后备份并进行vertices变换便可得到增强的数据

image-20240830210737717

疑问:点的置信度、边的置信度和面的置信度是什么意思,后者是否可以由前者得到

比如一条边有两个点,一个面有三个边(三个点),边/面的置信度是怎么算的?和点的置信度有什么关联?

image-20240830212023852

数据保存#

编写保存脚本save_shp.py,实现从gpu中的数据obj_datas保存回shp文件

  • 运行save_shp.py/的test,实现加载数据到obj_datas并保存成shp文件

  • 运行load_shp.py, 将保存后的shp再次可视化

结果相同

image-20240831185212390

论文#

mesh-gpt论文

Transformer的翻译模型和补全模型

对于补全模型

微信(GPT和Bert的预训练)

mesh—gpt、cad(generate)

编码器:他是谁

Transformer:整个场景表达了怎样的语义,(他是否满足这个语义,他在这个语义场景中扮演什么)

long long ago, .....

Next

Transformer-GPT原理

Mesh-GPT demo

posted @   Sherioc  阅读(44)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
主题色彩