Skip to content

Commit 2a2656e

Browse files
committed
Fixed NaN, no more NaN checks
1 parent 50834cc commit 2a2656e

File tree

11 files changed

+249099
-213632
lines changed

11 files changed

+249099
-213632
lines changed

C++/svm-out.xml

Lines changed: 124535 additions & 106799 deletions
Large diffs are not rendered by default.

Unity/Assets/SVM Detector/Editor/BakeSV.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ void OnGUI()
2626
{
2727
GUILayout.Label("Bake Support Vectors", EditorStyles.boldLabel);
2828
EditorGUILayout.BeginHorizontal();
29-
source = (TextAsset) EditorGUILayout.ObjectField("SVM Output (.yaml):", source, typeof(TextAsset), false);
29+
source = (TextAsset) EditorGUILayout.ObjectField("SVM Output (.xml):", source, typeof(TextAsset), false);
3030
EditorGUILayout.EndHorizontal();
3131

3232
if (GUILayout.Button("Bake!")) {
3333

3434
if (source == null)
35-
ShowNotification(new GUIContent("Select the .yaml output file"));
35+
ShowNotification(new GUIContent("Select the .xml output file"));
3636
else
3737
OnGenerateTexture();
3838
}

Unity/Assets/SVM Detector/Scene/SVM Scene.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ MonoBehaviour:
560560
m_Name:
561561
m_EditorClassIdentifier:
562562
launchedFromSDKPipeline: 0
563-
completedSDKPipeline: 0
563+
completedSDKPipeline: 1
564564
blueprintId:
565565
contentType: 0
566566
assetBundleUnityVersion:

Unity/Assets/SVM Detector/Shaders/svm.shader

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,6 @@
414414
float fb = f16tof32(b[x]) / s;
415415
col[x] = f32tof16(fa) << 16 | f32tof16(fb);
416416
}
417-
418-
// if (px.x == 15 && px.y == 23)
419-
// {
420-
// buffer[0] = float4(f16tof32(col.z >> 16), f16tof32(col.z),
421-
// f16tof32(col.w >> 16), f16tof32(col.w));
422-
// }
423417
}
424418
else if (lcFloor == 4 && insideArea(txCam2Bin, px))
425419
{
@@ -576,6 +570,7 @@
576570
float gamma = _SV.Load(uint3(798, 799, 0)).x;
577571
float dist[8];
578572
for (uint k = 0; k < 8; k++) {
573+
dist[k] = 0.0;
579574
for (uint l = 0; l < 196; l++) {
580575
// Extract HOG features from input
581576
float hogs[8];
@@ -587,7 +582,6 @@
587582
}
588583
}
589584
dist[k] = exp(dist[k] * -gamma);
590-
dist[k] = isnan(dist[k]) ? 0.01 : dist[k];
591585
}
592586
[unroll]
593587
for (uint x = 0; x < 4; x++) {
@@ -615,7 +609,6 @@
615609
}
616610
}
617611
dist[k] = exp(dist[k] * -gamma);
618-
dist[k] = isnan(dist[k]) ? 0.01 : dist[k];
619612
}
620613

621614
[unroll]
@@ -642,7 +635,6 @@
642635
}
643636
}
644637
dist[k] = exp(dist[k] * -gamma);
645-
dist[k] = isnan(dist[k]) ? 0.01 : dist[k];
646638
}
647639

648640
[unroll]
@@ -655,13 +647,15 @@
655647
px -= txPredict1.xy;
656648
uint vidx[SV_NUM];
657649
float dist[SV_NUM];
650+
658651
for (uint k = 0; k < SV_NUM; k++) {
659652
vidx[k] = (uint)floor(_SV.Load(uint3(k, 798, 0)).x);
660653
// index
661654
uint l = (k % 8) / 2;
662655
// shift value
663-
uint s = (1 - ((k % 8) % 2)) * 16;
664-
uint2 pos = txUnroll1.xy + px + (k / 8) * uint2(14, 0);
656+
uint s = ((k % 8) % 2) == 0 ? 16 : 0;
657+
uint2 pos = txUnroll1.xy + px;
658+
pos.x += (k / 8) * 14;
665659
// scoop up the unrolled values
666660
if (l == 0)
667661
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[0] >> s);
@@ -671,7 +665,6 @@
671665
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[2] >> s);
672666
else
673667
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[3] >> s);
674-
//dist[k] = isnan(dist[k]) ? 0.0 : dist[k];
675668
}
676669
float rho = _SV.Load(uint3(799, 799, 0)).x;
677670
float s = -rho;
@@ -685,13 +678,15 @@
685678
px -= txPredict2.xy;
686679
uint vidx[SV_NUM];
687680
float dist[SV_NUM];
681+
688682
for (uint k = 0; k < SV_NUM; k++) {
689683
vidx[k] = (uint)floor(_SV.Load(uint3(k, 798, 0)).x);
690684
// index
691685
uint l = (k % 8) / 2;
692686
// shift value
693-
uint s = (1 - ((k % 8) % 2)) * 16;
694-
uint2 pos = txUnroll2.xy + px + (k / 8) * uint2(8, 0);
687+
uint s = ((k % 8) % 2) == 0 ? 16 : 0;
688+
uint2 pos = txUnroll2.xy + px;
689+
pos.x += (k / 8) * 8;
695690
// scoop up the unrolled values
696691
if (l == 0)
697692
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[0] >> s);
@@ -701,7 +696,6 @@
701696
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[2] >> s);
702697
else
703698
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[3] >> s);
704-
//dist[k] = isnan(dist[k]) ? 0.0 : dist[k];
705699
}
706700

707701
float rho = _SV.Load(uint3(799, 799, 0)).x;
@@ -716,13 +710,15 @@
716710
px -= txPredict3.xy;
717711
uint vidx[SV_NUM];
718712
float dist[SV_NUM];
713+
719714
for (uint k = 0; k < SV_NUM; k++) {
720715
vidx[k] = (uint)floor(_SV.Load(uint3(k, 798, 0)).x);
721716
// index
722717
uint l = (k % 8) / 2;
723718
// shift value
724-
uint s = (1 - ((k % 8) % 2)) * 16;
725-
uint2 pos = txUnroll3.xy + px + (k / 8) * uint2(1, 0);
719+
uint s = ((k % 8) % 2) == 0 ? 16 : 0;
720+
uint2 pos = txUnroll3.xy + px;
721+
pos.x += (k / 8);
726722
// scoop up the unrolled values
727723
if (l == 0)
728724
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[0] >> s);
@@ -732,7 +728,6 @@
732728
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[2] >> s);
733729
else
734730
dist[k] = f16tof32(_Buffer.Load(uint3(pos, 0))[3] >> s);
735-
//dist[k] = isnan(dist[k]) ? 0.0 : dist[k];
736731
}
737732

738733
float rho = _SV.Load(uint3(799, 799, 0)).x;

Unity/Assets/SVM Detector/Shaders/svmhelper.cginc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _SVM_HELPER
22
#define _SVM_HELPER
33

4-
#define SV_NUM 303
4+
#define SV_NUM 350
55
#define NOISE_THRESH 4.0
66

77
#define txCam1 uint4(0, 0, 1728, 896)

Unity/Assets/SVM Detector/Shaders/visual.shader

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
pos = (cam3) ? txCam3Bin.xy :
146146
(floor(scoreHOG[id.x].y) == 2) ? txCam2Bin.xy : txCam1Bin.xy;
147147
uint2 of2 = floor(fmod(ps.uv * 16, 8));
148-
pos += scoreHOG[id.x].wz * 8 + cam3 ? of2 : of2.yx;
148+
pos += scoreHOG[id.x].wz * 8 + (cam3 ? of2 : of2.yx);
149149

150150
float bins[8];
151151
uint4 buf = _Buffer.Load(uint3(pos, 0));
@@ -172,49 +172,49 @@
172172
// bin 0
173173
float l = (bins[0] / btop) * 0.4;
174174
float d = udSegment(p, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
175-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
175+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
176176

177177
// bin 1
178178
float2 pr = rot2(p - ro, 0.3927) + ro;
179179
l = (bins[1] / btop) * 0.4;
180180
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
181-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
181+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
182182

183183
// bin 2
184184
pr = rot2(p - ro, 0.7854) + ro;
185185
l = (bins[2] / btop) * 0.4;
186186
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
187-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
187+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
188188

189189
// bin 3
190190
pr = rot2(p - ro, 1.1781) + ro;
191191
l = (bins[3] / btop) * 0.4;
192192
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
193-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
193+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
194194

195195
// bin 4
196196
pr = rot2(p - ro, 1.5708) + ro;
197197
l = (bins[4] / btop) * 0.4;
198198
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
199-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
199+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
200200

201201
// bin 5
202202
pr = rot2(p - ro, 1.9635) + ro;
203203
l = (bins[5] / btop) * 0.4;
204204
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
205-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
205+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
206206

207207
// bin 6
208208
pr = rot2(p - ro, 2.3562) + ro;
209209
l = (bins[6] / btop) * 0.4;
210210
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
211-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
211+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
212212

213213
// bin 7
214214
pr = rot2(p - ro, 2.7489) + ro;
215215
l = (bins[7] / btop) * 0.4;
216216
d = udSegment(pr, float2(0.5 - l, 0.5), float2(0.5 + l, 0.5)) - 0.01;
217-
col.rgb = d < 0.01 ? float3(0.5, 1.0, 0.5) : col.rgb;
217+
col.rgb = d < 0.01 ? float3(0.0, 1.0, 0.0) : col.rgb;
218218

219219
float2 p1 = abs(fmod(ps.uv * 128 + 1.0, 8.0) - 1.0);
220220
float g1 = saturate(min(p1.x, p1.y) * 4);

Unity/Assets/SVM Detector/SupportVectors.asset

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Unity/Assets/SVM Detector/Textures/CameraHigh.renderTexture

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RenderTexture:
1919
m_ColorFormat: 0
2020
m_MipMap: 0
2121
m_GenerateMips: 1
22-
m_SRGB: 0
22+
m_SRGB: 1
2323
m_UseDynamicScale: 0
2424
m_BindMS: 0
2525
m_TextureSettings:

Unity/Assets/SVM Detector/Textures/CameraLow.renderTexture

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RenderTexture:
1919
m_ColorFormat: 0
2020
m_MipMap: 0
2121
m_GenerateMips: 1
22-
m_SRGB: 0
22+
m_SRGB: 1
2323
m_UseDynamicScale: 0
2424
m_BindMS: 0
2525
m_TextureSettings:
Binary file not shown.

0 commit comments

Comments
 (0)