| 123456789101112131415161718192021222324252627282930 |
- /*---
- title: Detect objects in a photo
- group: Services
- summary: cnn.detect and cnn.classify with answers from the CNN window.
- ---*/
- /*
- The CNN window holds the JSON each function returns. The image must
- exist on the drive; the mock does not look at its pixels.
- */
- requirelib("cnn");
- var photo = "user:/Photo/sunset.jpg";
- var found = cnn.detect(photo, { conf: 0.5 });
- var labels = found.data.map(function (d) {
- return d.label + " (" + Math.round(d.score * 100) + "%)";
- });
- var kind = cnn.classify(photo, { top_k: 1 });
- try {
- cnn.classify("user:/Photo/missing.jpg");
- } catch (e) {
- console.log("Expected failure: " + e.name + ": " + e.message);
- }
- sendJSONResp({
- objects: labels,
- looksLike: kind.data[0].label,
- model: found.model
- });
|