kfront-base-ai
v0.1.1
Published
A WEB deep learning framework base on tensorflowjs.
Downloads
3
Readme
Getting Started
1.引入KAI
import { KAI } from "kfront-base-ai";
2.初始化KAI的实例
const kai = new KAI();
3.在window.onload事件中加载引入的模块所需的模型
window.onload = () => {
kai.loadSSDModel(MODEL_BASE_URL);
};
4.KAI的实例运行具体业务的方法
let detectedBox = await kai.executeSSDModule(image);
Guides
如何使用KAI中的某个算法?
demo: 使用KAI的单目标检测算法
import { KAI } from "kfront-base-ai";
.....
const MODEL_BASE_URL = 'http://localhost:8080/models/';
const kai = new KAI();
window.onload = () => {
kai.loadSSDModel(MODEL_BASE_URL);
};
const detect = async () => {
let detectedBox = await kai.executeSSDModule(image);
......
};
(1) 在使用KAI算法前先加载算法对应的模型文件。一个算法的模型文件只需加载一次即可,避免多次加载造成页面消耗系统资源。
(2) 执行算法模块。算法模块执行过程是异步进行,获取结果时请使用async/await 或Promise的形式获取。通常一个算法会被调用多次,用户在使用过程中存在递归循环调用算法的情况,请在算法执行完毕后清除循环所用的定时器,避免过度消耗系统资源导致浏览器奔溃。
如何使用KAI中的前端存储?
demo: 使用KAI Store API 保存数据
import { KAI } from "kfront-base-ai";
......
const kai = new KAI();
kai.initStore('kai-system',1, 'user', ['name', 'age']);
let res = await kai.addOneRow({
name: 'sony',
age: 20
});
(1) 创建或打开数据库表。在执行数据的增删改查前请先调用initStore()创建或打开数据表。
(2) 调用KAI Store增删改查的 API。
如何获取KAI的异常日志?
demo: 获取KAI异常日志
import { KAI } from "kfront-base-ai";
......
const kai = new KAI();
let excpLogs = await kai.getExceptionLogs('2019-01-01 10:00:00', '2019-01-02 22:00:00');
若用户在开发过程中遇到KAI发生异常时或需要查询KAI历史异常日志时,请调用getExceptionLogs()获取指定时间段内的日志。
API Reference
About Logger
async getExceptionLogs(startDate: String, endDate: String)
功能: 获取指定时间段的KAI发生异常时的错误日志
参数:
startDate: 开始查询时间的日期字符串(参数格式:'年-月-日 时:分:秒')
endDate: 结束查询时间的日期字符串(参数格式:'年-月-日 时:分:秒')
返回值:返回查询结果的Promise<Array>对象
About Algorithm
async loadSSDModel(baseUrl: String)
功能:加载SSD模型文件(SSD:单目标检测)
参数:
baseUrl: 模型文件基础路径
返回值: 无返回值
async executeSSDModule(input: HTMLCanvas|HTMLImage|HTMLVideo)
功能: 检测视频或图片中的单个目标对象
参数:
input: 图片或视频
返回值: 返回检测结果的Promise<Array>对象
async executeSTTModule(input: HTMLCanvas|HTMLImage, box: Array, width: Number, height: Number)
功能: 追踪视频或图片中的单个目标
参数:
input: 追踪源视频的每一帧图片
box: 被用户标记的目标在视频中的位置
width: 视频宽度
height: 视频高度
返回值: 返回检测结果的Promise<Array>对象
About Store
initStore(dbName: String, dbVersion: Number, storeName: String, indexList: Array)
功能:
参数:
dbName: 用户需要创建的数据库名称
dbVersion: 数据库版本号数值(只能是整数)
storeName: 用户要在数据库中创建的数据表名称
indexList: 数据表中创建多个索引(索引的字段必须和数据库表字段一致)
返回值: 无返回值
async addOneRow(item: JSONObject)
功能: 添加一行数据
参数:
item: 添加的数据
返回值: 返回添加数据结果的Promise<Object>对象
async deleteOneRow(id: Number|String)
功能: 删除一行数据
参数:
id: 要删除数据所在行的id
返回值: 返回删除数据结果的Promise<Object>对象
async updateOneRow(id: Number|String, item: JSONObject)
功能: 更新一行数据
参数:
id: 要更新数据所在行的id
item: 更新后的数据
返回值: 返回更新数据结果的Promise<Object>对象
async queryOneRow(cloumnName: String, cloumnValue: any)
功能: 查询指定索引下的某个值所在行的数据
参数:
cloumnName: 索引字段
cloumnValue: 搜索值
返回值: 返回查询数据结果的Promise<Object>对象
async queryOneRowID(cloumnName, cloumnValue)
功能: 查询指定索引下的某个值所在行数据的id
参数:
cloumnName: 索引字段
cloumnValue: 搜索值
返回值: 返回查询数据结果的Promise<Object>对象
async queryOneStore()
功能: 查询一个数据库表中的所有数据
参数: 无参数
返回值: 返回查询数据结果的Promise<Object>对象