【发布时间】:2019-07-09 12:03:43
【问题描述】:
我正在开发一个 Android 应用程序,该应用程序将包含一个用于离线推理的 tensorflow-lite 模型。
我知道完全避免有人偷我的模型是不可能的,但我想为尝试它的人制造困难。
我想将我的 .tflite 模型保留在 .apk 中,但没有顶层的权重。然后,在执行时,我可以下载最后一层的权重并将其加载到内存中。
所以,如果有人试图窃取我的模型,他会得到一个无用的模型,因为由于缺少最后一层的权重而无法使用它。
- 是否可以生成没有最后一层权重的 tflite 模型?
- 是否可以将这些权重加载到内存中已加载的模型中?
这就是我加载 .tflite 模型的方式:
tflite = new Interpreter(loadModelFile(), tfliteOptions);
// loads tflite grapg from file
private MappedByteBuffer loadModelFile() throws IOException {
AssetFileDescriptor fileDescriptor = mAssetManager.openFd(chosen);
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
FileChannel fileChannel = inputStream.getChannel();
long startOffset = fileDescriptor.getStartOffset();
long declaredLength = fileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
}
- 还有其他方法可以让我的模型更安全吗?我真的需要在本地进行推断。
【问题讨论】:
标签: android tensorflow tensorflow-lite