mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 18:04:13 +00:00
39 lines
1.7 KiB
Plaintext
39 lines
1.7 KiB
Plaintext
|
contract TensorflowExampleMac{
|
||
|
function onCreate(args){
|
||
|
var models = Global.Resources.loadAsInputStream("/model/tensorflow_inception_graph.pb");
|
||
|
var labels = Global.Resources.loadAsInputStream("/model/imagenet_comp_graph_label_strings.txt");
|
||
|
com.yancloud.sc.LabelImage.loadModel(models,labels);
|
||
|
return "done";
|
||
|
}
|
||
|
function constructAndExecuteGraphToNormalizeImage(imageInput){
|
||
|
var g = new org.tensorflow.Graph();
|
||
|
var b = new GraphBuilder(g);
|
||
|
var H = 224;
|
||
|
var mean = 177.0;
|
||
|
var scale = 1.0;
|
||
|
var input = b.constant("input",YancloudUtil.inputStreamToBytes(imageInput));
|
||
|
var output = b.div(b.sub(b.resizeBilinear(b.expandDims(b.cast(b.decodeJpeg(input,3),java.lang.Float.class),
|
||
|
b.constant("make_batch",0)),b.constant("size", [H,H])),
|
||
|
b.constant("mean",mean)),b.constantt("scale",scale));
|
||
|
var s = new session(g);
|
||
|
var ret = s.runner().fetch(output.op().name()).run().get(0).expect(java.lang.Float.class);
|
||
|
s.close();
|
||
|
g.close();
|
||
|
return ret;
|
||
|
}
|
||
|
@Description("示例参数: /imgs/cup.jpg")
|
||
|
export function testLocal(args){
|
||
|
var imageInput = Global.Resources.loadAsInputStream(args);
|
||
|
var start = new Date().getTime();
|
||
|
var labelProbabilities = com.yancloud.sc.LabelImage.matchImageInputStream(imageInput);
|
||
|
print(new Date().getTime()-start);
|
||
|
return labelProbabilities;
|
||
|
}
|
||
|
@Description("示例参数: https://c-ssl.duitang.com/uploads/item/201105/26/20110526192527_UYHTQ.thumb.700_0.jpg")
|
||
|
export function main(args){
|
||
|
var imageInput = YancloudUtil.httpAsInputStream(args);
|
||
|
var labelProbabilities = com.yancloud.sc.LabelImage.matchImageInputStream(imageInput);
|
||
|
return labelProbabilities;
|
||
|
}
|
||
|
}
|