-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.m
83 lines (67 loc) · 2.69 KB
/
demo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
clc;clear;close all;
%% forward + backward test of mexSphericalConvolution.
%---------------------------------------------------------
% test data preparation
%---------------------------------------------------------
rng(100);
ptCloud = load('bathtub.mat');
points = ptCloud.bathtub;
batch_size = 16;
batchData = repmat(reshape(points,[1,size(points)]),[batch_size,1,1]);
%---------------------------------------------------------
% octree, spherical kernel and the network configuration
%---------------------------------------------------------
treeDepth = 6; binCapacity = 8;
Nfilt = 8*2*3+1; %[8,2,3] is the kernel size
f = 1/40;
featSize = [3 32 64 64 64 128 128];
[dataBatch, mapBatch] = getOctreeBatch(batchData, treeDepth, binCapacity);
net(treeDepth) = struct('input',[],'filter',[],'bias',[],'map',[],...
'derOutput',[],'derFilter',[],'derBias',[]);
net(1).input = dataBatch;
for k = 1:treeDepth
net(k).filter =f*randn(1,featSize(k),featSize(k+1),Nfilt,'single');
net(k).bias = f*randn(1,featSize(k+1),'single');
net(k).map = mapBatch{k};
end
net(end).derOutput = randn(1, 1, featSize(end), net(end).map(3,end)+1, 'single');
%---------------------------------------------------------
% forward propagation test
%---------------------------------------------------------
gpuDevice; % reset gpuDevice
fprintf('----begin of forward test----\n\n');
size(net(1).input)
for layer = 1:treeDepth
input = gpuArray(net(layer).input);
filter = gpuArray(net(layer).filter);
bias = gpuArray(net(layer).bias);
tic
output = mexSphericalConvolution(input, filter, bias, net(layer).map);
mexTime = toc;
if(layer<treeDepth)
net(layer+1).input = output;
end
size(output)
end
fprintf('\n----end of forward test----\n\n\n\n');
%---------------------------------------------------------
% backward propagation test
%---------------------------------------------------------
fprintf('-------begin of backward test-------\n\n');
size(net(end).derOutput)
for layer = treeDepth:-1:1
input = gpuArray(net(layer).input);
filter = gpuArray(net(layer).filter);
derOutput = gpuArray(net(layer).derOutput);
tic
[derInput, derFilter, derBias] = mexSphericalConvolution(input, ...
filter, ...
[], ...
net(layer).map, derOutput);
mexTime = toc;
if layer>1
net(layer-1).derOutput = derInput;
end
size(derInput)
end
fprintf('\n-------end of backward test-------\n');