8000 Fixed randomization of RGB values during learning · codinghead/simple-neural-network@671adaa · GitHub
[go: up one dir, main page]

Skip to content

Commit 671adaa

Browse files
committed
Fixed randomization of RGB values during learning
1 parent 9b79ff2 commit 671adaa

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

trafficlight/tlight_detect/tlight_detect.pde

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,9 @@ void dashedCircle(float radius, int dashWidth, int dashSpacing) {
256256
void teachRed(int r, int g, int b) {
257257
float newR, newG, newB;
258258

259-
r += random(-4, 4);
260-
261-
newR = (r / 255.0);
262-
newG = (g / 255.0);
263-
newB = (b / 255.0);
259+
newR = (randomise(r) / 255.0);
260+
newG = (randomise(g) / 255.0);
261+
newB = (randomise(b) / 255.0);
264262

265263
//println("Red:", newR, newG, newB);
266264

@@ -279,9 +277,9 @@ void teachRed(int r, int g, int b) {
279277
void teachAmber(int r, int g, int b) {
280278
float newR, newG, newB;
281279

282-
newR = (r / 255.0);
283-
newG = (g / 255.0);
284-
newB = (b / 255.0);
280+
newR = (randomise(r) / 255.0);
281+
newG = (randomise(g) / 255.0);
282+
newB = (randomise(b) / 255.0);
285283

286284
//println("Amber:", newR, newG, newB);
287285

@@ -300,9 +298,9 @@ void teachAmber(int r, int g, int b) {
300298
void teachGreen(int r, int g, int b) {
301299
float newR, newG, newB;
302300

303-
newR = (r / 255.0);
304-
newG = (g / 255.0);
305-
newB = (b / 255.0);
301+
newR = (randomise(r) / 255.0);
302+
newG = (randomise(g) / 255.0);
303+
newB = (randomise(b) / 255.0);
306304

307305
network.setInputNode(0, newR);
308306
network.setInputNode(1, newG);
@@ -319,9 +317,9 @@ void teachGreen(int r, int g, int b) {
319317
void teachOther(int r, int g, int b) {
320318
float newR, newG, newB;
321319

322-
newR = (r / 255.0);
323-
newG = (g / 255.0);
324-
newB = (b / 255.0);
320+
newR = (randomise(r) / 255.0);
321+
newG = (randomise(g) / 255.0);
322+
newB = (randomise(b) / 255.0);
325323

326324
network.setInputNode(0, newR);
327325
network.setInputNode(1, newG);
@@ -335,27 +333,14 @@ void teachOther(int r, int g, int b) {
335333
network.calculateOutput();
336334
}
337335

338-
void randomise(int r, int g, int b) {
339-
r += random(-4, 4);
340-
g += random(-4, 4);
341-
b += random(-4, 4);
342-
343-
if (r > 255) {
344-
r = 255;
345-
}
346-
if (r < 0 ) {
347-
r = 0;
348-
}
349-
if (g > 255) {
350-
g = 255;
351-
}
352-
if (g < 0 ) {
353-
g = 0;
354-
}
355-
if (b > 255) {
356-
b = 255;
336+
int randomise(int value) {
337+
value += random(-4, 4);
338+
339+
if (value > 255) {
340+
value = 255;
357341
}
358-
if (b < 0 ) {
359-
b = 0;
342+
if (value < 0 ) {
343+
value = 0;
360344
}
345+
return value;
361346
}

0 commit comments

Comments
 (0)
0