This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit be5d9e5
Showing
35 changed files
with
10,904 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "appium" | ||
} |
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,2 @@ | ||
build | ||
node_modules |
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,3 @@ | ||
## OSX Deps | ||
|
||
```brew install cairo libjpeg``` |
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,13 @@ | ||
"use strict"; | ||
|
||
|
||
let gulp = require('gulp'), | ||
boilerplate = require('appium-gulp-plugins').boilerplate.use(gulp); | ||
|
||
boilerplate({ | ||
build: 'test-ai-classifier', | ||
coverage: { | ||
files: ['./test/unit/**/*-specs.js', '!./test/functional/**'], | ||
verbose: true | ||
}, | ||
}); |
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,2 @@ | ||
import classifier from './lib/classifier'; | ||
export default classifier; |
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,67 @@ | ||
import path from 'path'; | ||
import Canvas, { Image } from 'canvas'; | ||
import labels from './labels'; | ||
import * as tf from '@tensorflow/tfjs'; | ||
|
||
import '@tensorflow/tfjs-node'; | ||
|
||
const TF_MODEL = path.resolve(__dirname, "..", "..", "model", "model.pb"); | ||
const TF_WEIGHTS = path.resolve(__dirname, "..", "..", "model", "weights.json"); | ||
|
||
const IMG_CHANNELS = 3; | ||
|
||
let _cached_model = null; | ||
|
||
export async function getModel () { | ||
if (!_cached_model) { | ||
_cached_model = await tf.loadFrozenModel(`file://${TF_MODEL}`, `file://${TF_WEIGHTS}`); | ||
} | ||
return _cached_model; | ||
} | ||
|
||
async function canvasFromImage (imgPath) { | ||
let img = new Image(); | ||
img.src = imgPath; | ||
let cvs = new Canvas(img.width, img.height); | ||
let ctx = cvs.getContext('2d', {pixelFormat: 'A8'}); // grayscale, I hope | ||
ctx.drawImage(img, 0, 0, img.width, img.height); | ||
return cvs; | ||
} | ||
|
||
export async function tensorFromImage (imgPath, height=299, width=299, mean=0, | ||
std=255) { | ||
const canvas = await canvasFromImage(imgPath); | ||
let t = await tf.fromPixels(canvas, IMG_CHANNELS); | ||
t = tf.cast(t, 'float32'); | ||
t = t.expandDims(0); | ||
t = tf.image.resizeBilinear(t, [height, width]); | ||
t = tf.div(tf.sub(t, [mean]), [std]); | ||
return t; | ||
} | ||
|
||
export async function predictionFromImage (imgPath) { | ||
const model = await getModel(); | ||
const t = await tensorFromImage(imgPath); | ||
let pred = model.predict(t); | ||
pred = pred.squeeze(); | ||
let confMap = getConfidenceMap(await pred.data()); | ||
confMap.sort((a, b) => b[1] - a[1]); | ||
return confMap[0][0]; | ||
} | ||
|
||
function getConfidenceMap (predArr) { | ||
if (predArr.length !== labels.length) { | ||
throw new Error(`Prediction result array had ${predArr.length} elements ` + | ||
`but labels list had ${labels.length} elements. They ` + | ||
`need to match.`); | ||
} | ||
let map = []; | ||
for (let i = 0; i < labels.length; i++) { | ||
map.push([labels[i], predArr[i]]); | ||
} | ||
return map; | ||
} | ||
|
||
export default async function find (driver, label, multiple) { | ||
const model = await getModel(); | ||
} |
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,110 @@ | ||
const LABELS = [ | ||
" unclassified", | ||
"add", | ||
"airplane", | ||
"alarm", | ||
"arrow down", | ||
"arrow left", | ||
"arrow right", | ||
"arrow up", | ||
"attach", | ||
"bag", | ||
"barcode", | ||
"battery", | ||
"bluetooth", | ||
"bookmark", | ||
"brightness", | ||
"calculator", | ||
"calendar", | ||
"call", | ||
"camera", | ||
"car", | ||
"cart", | ||
"chart", | ||
"check mark", | ||
"clock", | ||
"close", | ||
"cloud", | ||
"computer", | ||
"contrast", | ||
"credit card", | ||
"crop", | ||
"cursor", | ||
"cut", | ||
"dashboard", | ||
"delete", | ||
"dollar", | ||
"download", | ||
"edit", | ||
"external link", | ||
"eye", | ||
"fab", | ||
"facebook", | ||
"fast forward", | ||
"favorite", | ||
"file", | ||
"filter", | ||
"fingerprint", | ||
"fire", | ||
"flag", | ||
"flashlight", | ||
"folder", | ||
"gift", | ||
"globe", | ||
"gmail", | ||
"google", | ||
"grid", | ||
"headphones", | ||
"home", | ||
"inbox", | ||
"info", | ||
"laptop", | ||
"light bulb", | ||
"link", | ||
"location", | ||
"lock", | ||
"mail", | ||
"map", | ||
"maximize", | ||
"megaphone", | ||
"menu", | ||
"microphone", | ||
"minimize", | ||
"mobile", | ||
"moon", | ||
"music", | ||
"mute", | ||
"notifications", | ||
"overflow menu", | ||
"pinterest", | ||
"play", | ||
"printer", | ||
"profile avatar", | ||
"qr code", | ||
"question", | ||
"refresh", | ||
"reply", | ||
"rewind", | ||
"save", | ||
"search", | ||
"send", | ||
"settings", | ||
"share", | ||
"signal", | ||
"sort", | ||
"tag", | ||
"television", | ||
"thumbs up", | ||
"ticket", | ||
"trash", | ||
"trophy", | ||
"twitter", | ||
"unlock", | ||
"upload", | ||
"user", | ||
"video camera", | ||
"volume", | ||
"warning" | ||
]; | ||
|
||
export default LABELS; |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.