代码拉取完成,页面将自动刷新
import numpy as np
from pathlib import Path
import time
import torch
import torch.nn as nn
from data import data_loaders
from model import RandLANet
from utils.ply import read_ply, write_ply
t0 = time.time()
path = Path('datasets') / 's3dis' / 'subsampled' / 'test'
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
print('Loading data...')
loader, _ = data_loaders(path)
print('Loading model...')
d_in = 6
num_classes = 14
model = RandLANet(d_in, num_classes, 16, 4, device)
model.load_state_dict(torch.load('runs/2020-04-11_17:03/checkpoint_10.pth')['model_state_dict'])
model.eval()
points, labels = next(iter(loader))
print('Predicting labels...')
with torch.no_grad():
points = points.to(device)
labels = labels.to(device)
scores = model(points)
predictions = torch.max(scores, dim=-2).indices
accuracy = (predictions == labels).float().mean() # TODO: compute mIoU usw.
print('Accuracy:', accuracy.item())
predictions = predictions.cpu().numpy()
print('Writing results...')
np.savetxt('output.txt', predictions, fmt='%d', delimiter='\n')
t1 = time.time()
# write point cloud with classes
print('Assigning labels to the point cloud...')
cloud = points.squeeze(0)[:,:3]
write_ply('MiniDijon9.ply', [cloud, predictions], ['x', 'y', 'z', 'class'])
print('Done. Time elapsed: {:.1f}s'.format(t1-t0))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。