博客
关于我
TFLite: interprenter run
阅读量:752 次
发布时间:2019-03-23

本文共 1560 字,大约阅读时间需要 5 分钟。

私 void classifyFrame() {// 获取BitmapBitmap bitmap = textureView.getBitmap(classifier.getImageSizeX(), classifier.getImageSizeY());// 感兴趣的文本String textToShow = classifier.classifyFrame(bitmap);}

// 输入数据的保存空间ByteBuffer=imgData=ByteBuffer.allocateDirect(DIM_BATCH_SIZE//1* getImageSizeX()* getImageSizeY()* DIM_PIXEL_SIZE//3* getNumBytesPerChannel());

// 将Bitmap转换为ByteBufferprivate void convertBitmapToByteBuffer(Bitmap bitmap) {imgData.rewind();bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

long startTime = SystemClock.uptimeMillis();pixel=0;for (int i=0; i

}

protected void addPixelValue(int pixelValue) {imgData.put((byte)((pixelValue >> 16) & 0xFF));imgData.put((byte)((pixelValue >> 8) & 0xFF));imgData.put((byte)(pixelValue & 0xFF));}

// TensorFlow Lite引擎protected Interpreter tflite;// 输入结果存储空间private ByteBuffer imgData;

// 模型加载与预处理tflite= new Interpreter(loadModelFile(activity));imgData=ByteBuffer.allocateDirect(DIM_BATCH_SIZE//1* getImageSizeX()* getImageSizeY()* DIM_PIXEL_SIZE//3* getNumBytesPerChannel());

// 模型运行public void run(Object input) {Object[] inputs = {input};Map<Integer, Object> outputs = new HashMap<>();outputs.put(0, output);runForMultipleInputsOutputs(inputs, outputs);}

public void runForMultipleInputsOutputs(Object[] inputs, Map<Integer, Object> outputs) {Tensor[] tensors = wrapper.run(inputs);for (Integer idx : outputs.keySet()) {tensors[idx].copyTo(outputs.get(idx));}}

// 定义模型输入维度private static native int[] getInputDims(long interpreterHandle, int inputIdx, int numBytes);

转载地址:http://icuzk.baihongyu.com/

你可能感兴趣的文章
MySQL主从复制及排错
查看>>
mysql主从复制及故障修复
查看>>
MySQL主从复制的原理和实践操作
查看>>
webpack loader配置全流程详解
查看>>
mysql主从复制,读写分离,半同步复制实现
查看>>
MySQL主从失败 错误Got fatal error 1236解决方法
查看>>
MySQL主从架构与读写分离实战
查看>>
MySQL主从篇:死磕主从复制中数据同步原理与优化
查看>>
mysql主从配置
查看>>
MySQL之2003-Can‘t connect to MySQL server on ‘localhost‘(10038)的解决办法
查看>>
MySQL之CRUD
查看>>
MySQL之DML
查看>>
Mysql之IN 和 Exists 用法
查看>>
MYSQL之REPLACE INTO和INSERT … ON DUPLICATE KEY UPDATE用法
查看>>
MySQL之SQL语句优化步骤
查看>>