2017-04-25 5 views
0

나는 android에서 tensorflow를 사용하고 있습니다. TFClassify 용 apk를 설치했습니다. 응용 프로그램을 실행하고 추론 시간이 400ms를 넘지 않아 신속하게 실행됩니다. 그러나 사용 가능한 훈련 된 모델을 내 모델로 대체하면 결과를 표시하기 전에 계산을 위해 약 2000ms가 소요됩니다. 왜 그런 차이가 있으며 어떻게 retrained_graph.pb를 최적화 할 수 있습니까?tensorflow에서 계산 시간을 향상시키는 방법

답변

0

재교육 모델을 최적화 된 & 양자화 그래프로 변환 했습니까?

하지 않으면

:

tensorflow/bazel-bin/tensorflow/python/tools/optimize_for_inference \ 
     --input=retrained_graph.pb \ 
     --output=optimized_graph.pb \ 
     --input_names=Mul \ 
     --output_names=final_result 

tensorflow/bazel-bin/tensorflow/tools/quantization/quantize_graph \ 
     --input=optimized_graph.pb \ 
     --output=rounded_graph.pb \ 
     --output_node_names=final_result \ 
     --mode=weights_rounded 

참고로, 먼저 이러한 도구를 구축해야합니다.

+0

그래프를 최적화 및 양자화하여 추론 시간을 수 ms 개선했습니다. 추론 시간은 1800ms로 줄어들지 만 원래 모델 (400ms)보다 훨씬 더 빠릅니다. 개선 할 수있는 더 많은 방법? 내 모델의 크기는 87.1 MB입니다. –

+0

첫째, 그래프 파일 크기는 중요하지 않습니다. .APK로 압축하면 양자화 된 그래프를 ~ 25MB로 압축 할 수 있습니다. 둘째, Android에서 추론 성능을 향상시키는 방법을 알고 싶습니다. 아직 시도하지는 않았지만 http://stackoverflow.com/questions/43585773/how-to-pass-optimization-flags-to-bazel-build-for-tensorflow (makefile로 빌드)만이 단서입니다 나는 지금까지 찾을 수 있었다. –

관련 문제