|
1 |
| -function boxes = distributionFocalLoss(boxes) |
| 1 | +function boxes = distributionFocalLoss(boxesInp) |
2 | 2 | % Distribution Focal Loss Module
|
3 | 3 |
|
4 |
| -sz = size(boxes); |
| 4 | +sz = size(boxesInp); |
5 | 5 | c1=16; % pre-specified
|
6 | 6 |
|
7 | 7 | % compute batch. channel and anchors
|
|
14 | 14 | anchors = sz(2);
|
15 | 15 |
|
16 | 16 | % Reshape Operation
|
17 |
| -boxes = permute(boxes,[2,1,3,4]); % 1 d qual like python |
18 |
| -boxes = reshape(boxes,anchors,c1,4,batch); |
19 |
| -boxes = permute(boxes,[2,1,3,4]); |
| 17 | +boxesInp = permute(boxesInp,[2,1,3,4]); |
| 18 | +boxesReshaped = reshape(boxesInp,anchors,c1,4,batch); |
| 19 | +boxesMapped = permute(boxesReshaped,[2,1,3,4]); |
20 | 20 |
|
21 | 21 | % Transpose Operation
|
22 |
| -boxes = permute(boxes,[3,2,1,4]); |
| 22 | +boxesTrans = permute(boxesMapped,[3,2,1,4]); |
| 23 | +boxesTrans = extractdata(boxesTrans); |
23 | 24 |
|
24 | 25 | % softmax along the channel dimension
|
25 |
| -boxes = softmax(dlarray(boxes,'SSC')); % produces a diff of 10^-3 |
26 |
| -boxes = extractdata(boxes); |
| 26 | +boxesMax = softmax(dlarray(boxesTrans,'SSC')); |
| 27 | +boxesMax = extractdata(boxesMax); |
27 | 28 |
|
28 | 29 | % 1-d conv operation
|
29 | 30 | % Define weights
|
30 | 31 | weights = [0:c1-1];
|
31 |
| -m = size(boxes,1); |
32 |
| -n = size(boxes,2); |
| 32 | +m = size(boxesMax,1); |
| 33 | +n = size(boxesMax,2); |
33 | 34 | weights = reshape(repmat(weights,m*n,1),m,n,[]);
|
34 | 35 | % Conv operation
|
35 |
| -boxes = boxes .* weights; |
36 |
| -boxes = sum(boxes,3); % diff of 10^-2 because of above diff |
| 36 | +boxesConv = boxesMax .* weights; |
| 37 | +boxesTotal = sum(boxesConv,3); |
37 | 38 |
|
38 | 39 | % Reshape Operation
|
39 |
| -boxes = permute(boxes,[2,1,3,4]); |
40 |
| -boxes = reshape(boxes,anchors,4,batch); |
41 |
| -boxes = permute(boxes,[2,1,3,4]); |
| 40 | +boxesTmp = permute(boxesTotal,[2,1,3,4]); |
| 41 | +boxesTmpReshaped = reshape(boxesTmp,anchors,4,batch); |
| 42 | +boxes = permute(boxesTmpReshaped,[2,1,3,4]); |
42 | 43 |
|
43 | 44 | end
|
44 |
| - |
45 |
| - |
46 |
| - |
47 |
| - |
48 |
| - |
49 |
| - |
50 |
| - |
51 |
| - |
52 |
| - |
53 |
| - |
54 |
| - |
55 |
| - |
56 |
| - |
0 commit comments