def read_fn(model, filename): BLOCK_SIZE = 3.0 BLOCK_STRIDE = 1.5 SAMPLE_STRIDE = 0.1 RESAMPLE_RATIO_LOW = 0.8 RESAMPLE_RATIO_HIGH = 1.0 NEIGHBOR_RADIUS = 0.2 MIN_POINT_NUM = 2048 points, labels = read_room_pkl(filename) # [n,6],[n,1] if model == 'train': xyzs, rgbs, covars, lbls = sample_block(points, labels, SAMPLE_STRIDE, BLOCK_SIZE, BLOCK_STRIDE, min_pn=MIN_POINT_NUM, use_rescale=True, use_flip=True, use_rotate=False) xyzs, rgbs, covars, lbls, nidxs, nidxs_lens, nidxs_bgs, cidxs, block_bgs, block_lens = \ normalize_block(xyzs,rgbs,covars,lbls,neighbor_radius=NEIGHBOR_RADIUS,resample=True,jitter_color=True, resample_low=RESAMPLE_RATIO_LOW,resample_high=RESAMPLE_RATIO_HIGH) else: xyzs, rgbs, covars, lbls = sample_block(points, labels, SAMPLE_STRIDE, BLOCK_SIZE, BLOCK_SIZE, min_pn=MIN_POINT_NUM / 2) xyzs, rgbs, covars, lbls, nidxs, nidxs_lens, nidxs_bgs, cidxs, block_bgs, block_lens = \ normalize_block(xyzs,rgbs,covars,lbls,neighbor_radius=NEIGHBOR_RADIUS) return xyzs, rgbs, covars, lbls, nidxs, nidxs_lens, nidxs_bgs, cidxs, block_bgs, block_lens
def test_time(): from draw_util import output_points, get_class_colors from sklearn.cluster import KMeans colors = get_class_colors() train_list, test_list = get_block_train_test_split() random.shuffle(train_list) train_list = ['data/S3DIS/room_block_10_10/' + fn for fn in train_list] # filename=train_list[0] filename = 'data/S3DIS/room_block_10_10/49_Area_1_office_8.pkl' points, labels = read_room_pkl(filename) # [n,6],[n,1] for i in xrange(10): t = time.time() xyzs, rgbs, covars, lbls = sample_block(points, labels, 0.1, 3.0, 1.5, min_pn=2048, use_rescale=True, use_flip=True, use_rotate=True) print 'sample block cost {} s '.format(time.time() - t) t = time.time() xyzs, rgbs, covars, lbls, nidxs, nidxs_lens, nidxs_bgs, cidxs=\ normalize_block(xyzs,rgbs,covars,lbls,0.2,True,0.8,1.0,True,2.5) print 'normalize cost {} s '.format(time.time() - t)
def test_normalize(): from draw_util import output_points, get_class_colors from sklearn.cluster import KMeans colors = get_class_colors() train_list, test_list = get_block_train_test_split() random.shuffle(train_list) train_list = ['data/S3DIS/room_block_10_10/' + fn for fn in train_list] # filename=train_list[0] filename = 'data/S3DIS/room_block_10_10/49_Area_1_office_8.pkl' points, labels = read_room_pkl(filename) # [n,6],[n,1] begin = time.time() xyzs, rgbs, covars, lbls = sample_block(points, labels, SAMPLE_STRIDE, BLOCK_SIZE, BLOCK_STRIDE, min_pn=2048, use_rescale=True, use_flip=True, use_rotate=True) print 'sample_block cost {} s'.format(time.time() - begin) # for j in xrange(len(xyzs)): # print np.min(xyzs[j],axis=0),np.max(xyzs[j],axis=0) # print np.min(rgbs[j],axis=0),np.max(rgbs[j],axis=0) # print xyzs[j].shape,lbls[j].shape # output_points('test_result/label_init{}.txt'.format(j),xyzs[j],colors[lbls[j].flatten(),:]) # output_points('test_result/lrgbs_init{}.txt'.format(j),xyzs[j],rgbs[j]) xyzs, rgbs, covars, lbls, nidxs, nidxs_lens, nidxs_bgs, cidxs=\ normalize_block(xyzs,rgbs,covars,lbls,0.2,True,0.8,1.0,True,2.5) for j in xrange(len(xyzs)): print xyzs[j].shape, rgbs[j].shape, covars[j].shape, lbls[ j].shape, nidxs[j].shape, nidxs_lens[j].shape, nidxs_bgs[ j].shape, cidxs[j].shape print np.min(xyzs[j], axis=0), np.max(xyzs[j], axis=0) print np.min(rgbs[j], axis=0), np.max(rgbs[j], axis=0) print 'avg nn size: {}'.format(len(nidxs[j]) / float(len(xyzs[j]))) # print xyzs[j].shape,lbls[j].shape output_points('test_result/label{}.txt'.format(j), xyzs[j], colors[lbls[j].flatten(), :]) output_points('test_result/lrgbs{}.txt'.format(j), xyzs[j], np.asarray(rgbs[j] * 128 + 127, np.int32)) for j in xrange(len(xyzs[0])): output_points( 'test_result/nn{}.txt'.format(j), xyzs[0][nidxs[0][nidxs_bgs[0][j]:nidxs_bgs[0][j] + nidxs_lens[0][j]], :])
def test_sample(): from draw_util import output_points, get_class_colors from sklearn.cluster import KMeans colors = get_class_colors() train_list, test_list = get_block_train_test_split() random.shuffle(train_list) train_list = ['data/S3DIS/room_block_10_10/' + fn for fn in train_list] filename = train_list[0] # filename='data/S3DIS/room_block_10_10/58_Area_2_auditorium_2.pkl' points, labels = read_room_pkl(filename) # [n,6],[n,1] print np.min(points, axis=0) begin = time.time() xyzs, rgbs, covars, lbls = sample_block(points, labels, 0.075, 1.5, 1.5, min_pn=2048 / 2) #use_rescale=True,use_flip=True,use_rotate=True) print 'sample_block cost {} s'.format(time.time() - begin) print np.min(np.concatenate(xyzs, axis=0), axis=0) kc = np.random.randint(0, 255, [5, 3]) for j in xrange(len(xyzs)): # print xyzs[j].shape,lbls[j].shape output_points('test_result/label{}.txt'.format(j), xyzs[j], colors[lbls[j].flatten(), :]) output_points('test_result/lrgbs{}.txt'.format(j), xyzs[j], rgbs[j]) kmeans = KMeans(5) preds = kmeans.fit_predict(np.concatenate(covars, axis=0)) output_points('test_result/kmeans.txt', np.concatenate(xyzs, axis=0), kc[preds.flatten(), :]) pt_num = [len(xyz) for xyz in xyzs] print 'avg pt num: {}'.format(np.mean(pt_num))
def read_fn_hierarchy(model, filename, presample=True, use_rotate=False, nr1=0.1, nr2=0.4, nr3=1.0, vc1=0.2, vc2=0.5, sstride=0.075, bsize=3.0, bstride=1.5, min_pn=1024, resample_ratio_low=0.8, resample_ratio_high=1.0, covar_ds_stride=0.03, covar_nn_size=0.1, max_pt_num=10240): if filename.endswith('.pkl'): points, labels = read_room_pkl(filename) # [n,6],[n,1] else: points, labels = read_room_h5(filename) # [n,6],[n,1] if model == 'train': if presample: xyzs, rgbs, covars, lbls = sample_block_v2( points, labels, sstride, bsize, bstride, min_pn=min_pn, use_rescale=True, use_flip=True, use_rotate=use_rotate, covar_nn_size=covar_nn_size) else: xyzs, rgbs, covars, lbls = sample_block( points, labels, sstride, bsize, bstride, min_pn=min_pn, use_rescale=True, use_flip=True, use_rotate=use_rotate, covar_ds_stride=covar_ds_stride, covar_nn_size=covar_nn_size) cxyzs, dxyzs, rgbs, covars, lbls, vlens, vlens_bgs, vcidxs, cidxs, nidxs, nidxs_bgs, nidxs_lens, block_mins = \ normalize_block_hierarchy(xyzs,rgbs,covars,lbls,bsize=bsize,nr1=nr1,nr2=nr2,nr3=nr3,vc1=vc1,vc2=vc2, resample=True,jitter_color=True, resample_low=resample_ratio_low,resample_high=resample_ratio_high, max_pt_num=max_pt_num) else: if presample: xyzs, rgbs, covars, lbls = sample_block_v2( points, labels, sstride, bsize, bsize, min_pn=min_pn / 2, covar_nn_size=covar_nn_size) else: xyzs, rgbs, covars, lbls = sample_block( points, labels, sstride, bsize, bsize, min_pn=min_pn / 2, covar_ds_stride=covar_ds_stride, covar_nn_size=covar_nn_size) cxyzs, dxyzs, rgbs, covars, lbls, vlens, vlens_bgs, vcidxs, cidxs, nidxs, nidxs_bgs, nidxs_lens, block_mins = \ normalize_block_hierarchy(xyzs,rgbs,covars,lbls,bsize=bsize,nr1=nr1,nr2=nr2,nr3=nr3,vc1=vc1,vc2=vc2, max_pt_num=max_pt_num) return cxyzs, dxyzs, rgbs, covars, lbls, vlens, vlens_bgs, vcidxs, cidxs, nidxs, nidxs_bgs, nidxs_lens, block_mins