在iOS和GPU上使用.tflite。

问题描述 投票:-1回答:1

我创建了一个新的tflite模型,它基于 MobilenetV2. 在iOS上使用CPU,不用量化也能很好的工作。我应该说TensorFlow团队做得很好,非常感谢。

不幸的是,有一个延迟的问题。我使用iPhone5s来测试我的模型,所以我对CPU有以下结果。

  1. 在224*224输入图像的情况下,MobilenetV2的延迟为500ms。

  2. 对于使用160*160输入图像的MobilenetV2,250-300ms。

我使用了下面的 pod 'TensorFlowLite', '~> 1.13.1' 。

这还不够,所以我读了TF的相关优化文档(训练后量化)。我想我需要使用Float16或UInt8量化和GPU Delegate(见下图) https:/www.tensorflow.orgliteperformancepost_training_quantization).我用 Tensorflow v2.1.0 来训练和量化我的模型。

  1. Float16的权重量化。 (我使用了Float16量化后的MobilenetV2模型)

https:/github.comtensorflowexamplestreemasterliteexamplesimage_segmentationios。

  • pod 'TensorFlowLiteSwift', '0.0.1-nightly' 。

没有错误,但模型不工作

  • pod 'TensorFlowLiteSwift', '2.1.0' 。

2020-05-01 21:36:13.578369+0300 TFL Segmentation[6367:330410] 初始化TensorFlow Lite运行时.2020-05-01 21:36:20.877393+0300 TFL Segmentation[6367:330397] 由于执行过程中出现错误,命令缓冲区的执行被中止。导致GPU挂起错误(IOAF代码3)

  1. 全整数量化 权数和激活数

pod'TensorFlowLiteGpuExperimental'

代码样本。https:/github.commakeml-appMakeML-NailstreemasterSegmentation%20Nails。

我用的是uint8量化后的MobilenetV2模型。

GpuDelegateOptions options;
    options.allow_precision_loss = true;
    options.wait_type = GpuDelegateOptions::WaitType::kActive;

    //delegate = NewGpuDelegate(nullptr);
    delegate = NewGpuDelegate(&options);

    if (interpreter->ModifyGraphWithDelegate(delegate) != kTfLiteOk)

Segmentation Live[6411:331887][DYMTLInitPlatform]平台初始化成功加载模型1resolved reporterDidn't find op for builtin opcode 'PAD' version '2'.

是否可以在IOS上使用MObilenetV2量化模型?希望我做了一些错误的事情:),它是可能的。

问候,Dmitriy

ios tensorflow deep-learning gpu quantization
1个回答
0
投票

对不起,文档已经过时了--GPU代表应该被包含在文档中。TensorFlowLiteSwift 2.1.0. 然而,看起来你使用的是C API,所以取决于 TensorFlowLiteC 就足够了。

MobileNetV2在iOS中与TFLite runtime一起工作,如果我没记错的话,它没有PAD op。你能附上你的模型文件吗?根据所提供的信息,很难看出是什么原因导致的错误。作为安全检查,你可以从这里得到quantnon-quant版本的MobileNetV2。https:/www.tensorflow.orgliteguidehosted_models


0
投票

这是一个链接到GITHUB问题的答案。https:/github.comtensorflowtensorflowissues39101。

© www.soinside.com 2019 - 2024. All rights reserved.