-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed all the examples and added an MNIST detector example
- Loading branch information
Showing
14 changed files
with
178 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
group 'ch.bildspur' | ||
version '0.3.1' | ||
version '0.3.2' | ||
|
||
apply plugin: 'java' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import ch.bildspur.vision.*; | ||
import ch.bildspur.vision.result.*; | ||
import java.util.List; | ||
|
||
PImage testImage; | ||
|
||
DeepVision vision; | ||
ULFGFaceDetectionNetwork network; | ||
List<ObjectDetectionResult> detections; | ||
|
||
public void setup() { | ||
size(640, 480); | ||
colorMode(HSB, 360, 100, 100); | ||
|
||
vision = new DeepVision(this); | ||
testImage = loadImage(sketchPath("data/selfie.jpg")); | ||
|
||
println("creating network..."); | ||
network = vision.createULFGFaceDetectorRFB640(); | ||
network.setConfidenceThreshold(0.2); | ||
|
||
println("loading model..."); | ||
network.setup(); | ||
|
||
//network.setConfidenceThreshold(0.2f); | ||
|
||
println("inferencing..."); | ||
detections = network.run(testImage); | ||
println("done!"); | ||
|
||
for (ObjectDetectionResult detection : detections) { | ||
System.out.println(detection.getClassName() + "\t[" + detection.getConfidence() + "]"); | ||
} | ||
|
||
println("found " + detections.size() + " faces!"); | ||
} | ||
|
||
public void draw() { | ||
background(55); | ||
image(testImage, 0, 0); | ||
|
||
noFill(); | ||
strokeWeight(2f); | ||
|
||
stroke(200, 80, 100); | ||
for (ObjectDetectionResult detection : detections) { | ||
rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight()); | ||
} | ||
|
||
surface.setTitle("Face Recognition Test - Faces: " + detections.size()); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import ch.bildspur.vision.*; | ||
import ch.bildspur.vision.result.*; | ||
|
||
DeepVision vision; | ||
MNISTClassificationNetwork network; | ||
|
||
ClassificationResult result; | ||
long inferenceTime = 0; | ||
PImage canvas = new PImage(28, 28, RGB); | ||
|
||
boolean mouseDrawing = false; | ||
float factor = 560 / 28; | ||
|
||
public void setup() { | ||
size(560, 560, FX2D); | ||
colorMode(HSB, 360, 100, 100); | ||
|
||
vision = new DeepVision(this); | ||
|
||
println("creating network..."); | ||
network = vision.createMNISTClassifier(); | ||
|
||
println("loading model..."); | ||
network.setup(); | ||
|
||
clearCanvas(); | ||
println("ready!"); | ||
} | ||
|
||
public void draw() { | ||
background(55); | ||
|
||
if (mouseDrawing) { | ||
int x = round(mouseX / factor); | ||
int y = round(mouseY / factor); | ||
|
||
canvas.set(x, y, color(255)); | ||
canvas.updatePixels(); | ||
} | ||
|
||
//image(canvas, 0, 0, width, height); | ||
for (int y = 0; y < canvas.width; y++) { | ||
for (int x = 0; x < canvas.width; x++) { | ||
color c = canvas.get(x, y); | ||
fill(c); | ||
noStroke(); | ||
rect(x * factor, y * factor, factor, factor); | ||
} | ||
} | ||
|
||
// display info | ||
fill(140, 80, 100); | ||
textSize(16); | ||
text("space: run inference / c: clear canvas", 10, 20); | ||
|
||
if (result != null) { | ||
text("Detected '" + result.getClassName() + "' with " + result.getConfidence() + "%", 10, 50); | ||
} | ||
|
||
surface.setTitle("MNIST Detector"); | ||
} | ||
|
||
void mousePressed() { | ||
mouseDrawing = true; | ||
} | ||
|
||
void mouseReleased() { | ||
mouseDrawing = false; | ||
} | ||
|
||
void keyPressed() { | ||
if (key == ' ') { | ||
println("inferencing..."); | ||
int start = millis(); | ||
result = network.run(canvas); | ||
inferenceTime = millis() - start; | ||
} | ||
|
||
if (key == 'c' || key == 'C') { | ||
println("clearing canvas..."); | ||
clearCanvas(); | ||
result = null; | ||
} | ||
} | ||
|
||
void clearCanvas() { | ||
for (int y = 0; y < canvas.width; y++) { | ||
for (int x = 0; x < canvas.width; x++) { | ||
canvas.set(x, y, color(0)); | ||
} | ||
} | ||
canvas.updatePixels(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters