当训练模型在重新加载用于评估的时候出现少了一个module前缀,这个问题通常是由于训练的时候采用了数据并行操作,而评估模型的时候却没有用到。因此,只需要在训练代码中补充:
net = nn.DataParallel(net)#加在模型定义完成之后
torch.stack((a, b, c), dim=0)#将a、b、c进行拼接,假设abc的维度为CxHxW。
#dim=0时,将他们整体直接进行拼接,得到的维度为NxCxHXW,N为拼接元素的个数,这里N=3
def my_collate(batch):
inputs, labels = list(zip(*batch))#重新组合batch数据,返回元组列表
#这里可以添加处理函数,如
inputs = ntorch.stack(inputs)
labels = torch.stack(labels)
return inputs, labels
def select_device(device='', batch_size=0, newline=True):
# device = 'cpu' or '0' or '0,1,2,3'
s = f'YOLOv5 {git_describe() or file_update_date()} torch {torch.__version__} ' # string
device = str(device).strip().lower().replace('cuda:', '') # to string, 'cuda:0' to '0'
cpu = device == 'cpu'
if cpu:
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
elif device: # non-cpu device requested
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable - must be before assert is_available()
assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(',', '')), \
f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)"
cuda = not cpu and torch.cuda.is_available()
if cuda:
devices = device.split(',') if device else '0' # range(torch.cuda.device_count()) # i.e. 0,1,6,7
n = len(devices) # device count
if n > 1 and batch_size > 0: # check batch_size is divisible by device_count
assert batch_size % n == 0, f'batch-size {batch_size} not multiple of GPU count {n}'
space = ' ' * (len(s) + 1)
for i, d in enumerate(devices):
p = torch.cuda.get_device_properties(i)
s += f"{'' if i == 0 else space}CUDA:{d} ({p.name}, {p.total_memory / (1 << 20):.0f}MiB)\n" # bytes to MB
else:
s += 'CPU\n'
if not newline:
s = s.rstrip()
# LOGGER.info(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe
return torch.device('cuda:0' if cuda else 'cpu')
import warnings
warnings.filterwarnings("ignore")
请参考:https://blog.csdn.net/suiyingy/article/details/124688161。
python三维点云从基础到深度学习_Coding的叶子的博客-CSDN博客_3d点云 python从三维基础知识到深度学习,将按照以下目录持续进行更新。更新完成的部分可以在三维点云专栏中查看。https://blog.csdn.net/suiyingy/category_11740467.htmlhttps://blog.csdn.net/suiyingy/category_11740467.html1、点云格式介绍(已完成)常见点云存储方式有pcd、ply、bin、txt文件。open3d读写pcd和plhttps://blog.csdn.net/suiyingy/article/details/124017716更多三维、二维感知算法和金融量化分析算法请关注“乐乐感知学堂”微信公众号,并将持续进行更新。