pytorch中padding=kernel_size//2

39 篇文章 0 订阅
20 篇文章 0 订阅
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import open3d as o3d import numpy as np import torch import torch.nn.functional as F import matplotlib.pyplot as plt # 读取点云文件 pcd = o3d.io.read_point_cloud(r"E:\BISHE\pcd\neuvsnap_0418_154523.pcd") def gaussian_filter(input, kernel_size=3, sigma=0.5): # Create a 1D Gaussian kernel kernel = np.exp(-np.square(np.arange(-kernel_size // 2 + 1, kernel_size // 2 + 1)) / (2 * np.square(sigma))) kernel = torch.FloatTensor(kernel).unsqueeze(0).unsqueeze(0) # Normalize the kernel kernel = kernel / kernel.sum() # Apply the filter using conv2d padding = kernel_size // 2 filtered = F.conv2d(input.unsqueeze(0), kernel, padding=padding, groups=input.size(1)) return filtered.squeeze(0) # 将点云转换为 PyTorch 张量 points = np.asarray(pcd.points) points = torch.from_numpy(points).float() # 使用简单的高斯滤波器进行去噪 points = gaussian_filter(points, kernel_size=3, sigma=0.5) # 将点云转换回 numpy 数组并可视化 points_np = points.numpy() pcd_processed = o3d.geometry.PointCloud() pcd_processed.points = o3d.utility.Vector3dVector(points_np) o3d.visualization.draw_geometries([pcd_processed]) # 计算点云体积并打印结果 volume = 0 for i in range(points_np.shape[0]): volume += points_np[i, 0] * points_np[i, 1] * points_np[i, 2] print("Volume:", volume) # 将点云和体积测量结果导出 o3d.io.write_point_cloud("example_processed.pcd", pcd_processed) with open("volume.txt", "w") as f: f.write(str(volume))运行后报错Traceback (most recent call last): File "E:/BISHE/Pointnet2/main.py", line 30, in <module> points = gaussian_filter(points, kernel_size=3, sigma=0.5) File "E:/BISHE/Pointnet2/main.py", line 21, in gaussian_filter filtered = F.conv2d(input.unsqueeze(0), kernel, padding=padding, groups=input.size(1)) RuntimeError: expected stride to be a single integer value or a list of 1 values to match the convolution dimensions, but got stride=[1, 1]
05-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值