MobileNet-v1 Runs Much Slower using TFSharp Plugin
Dear staff, I re-implemented the object detection demo on Unity using TFSharp Plugin. I ran the code on an Android phone. The runner session took in average 1.5 seconds to run. Whereas the same Tensorflow Android example demo took only 0.3s. I did find in the adb that some object couldn't find the libtensorflow file. Does it affect the performance? Do you have a newer version of the TFSharp Plugin?
Here is the log:
04-28 12:25:47.195 11595 11609 I Unity : SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 4, Memory = 5772mb 04-28 12:25:47.198 11595 11609 I Unity : SystemInfo ARM big.LITTLE configuration: 4 big (mask: 15), 0 little (mask: 0) 04-28 12:25:47.199 11595 11609 I Unity : ApplicationInfo com.cornelledtech.arvb version 0.0.8 build a7f772b4-d1e1-42cd-b8e3-a3263bff10e2 04-28 12:25:47.199 11595 11609 I Unity : Built from '2017.3/release' branch, Version '2017.3.1f1 (fc1d3344e6ea)', Build type 'Release', Scripting Backend 'mono' 04-28 12:25:47.403 11595 11609 D Unity : GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_vertex_half_float GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_compressed_ETC1_RGB8_texture GL_AMD_compressed_ATC_texture GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_OES_texture_compression_astc GL_OES_texture_npot GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_OES_texture_3D GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_QCOM_alpha_test GL_OES_depth24 GL_OES_packed_depth_stencil GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_EXT_sRGB GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_EXT_texture_type_2_10_10_10_REV GL_EXT_texture_sRGB_decode GL_OES_element_index_uint GL_EXT_copy_image GL_EXT_geometry_shader GL_EXT_tessellation_shader GL_OES_texture_stencil8 GL_EXT_shader_io_blocks GL_OES_shader_image_atomic GL_OES_sample_variables GL_EXT_texture_border_clamp GL_EXT_multisampled_render_to_texture GL_OES_sha 04-28 12:25:47.403 11595 11609 D Unity : der_multisample_interpolation GL_EXT_texture_cube_map_array GL_EXT_draw_buffers_indexed GL_EXT_gpu_shader5 GL_EXT_robustness GL_EXT_texture_buffer GL_EXT_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_OES_texture_storage_multisample_2d_array GL_OES_sample_shading GL_OES_get_program_binary GL_EXT_debug_label GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_QCOM_tiled_rendering GL_ANDROID_extension_pack_es31a GL_EXT_primitive_bounding_box GL_OES_standard_derivatives GL_OES_vertex_array_object GL_EXT_disjoint_timer_query GL_KHR_debug GL_EXT_YUV_target GL_EXT_sRGB_write_control GL_EXT_texture_norm16 GL_EXT_discard_framebuffer GL_OES_surfaceless_context GL_OVR_multiview GL_OVR_multiview2 GL_EXT_texture_sRGB_R8 GL_KHR_no_error GL_EXT_debug_marker GL_OES_EGL_image_external_essl3 GL_OVR_multiview_multisampled_render_to_texture GL_EXT_buffer_storage GL_EXT_blit_framebuffer_params GL_EXT_clip_cull_distance GL_EXT_protected_textures GL_EXT_shader_non_constant_global_i 04-28 12:25:47.403 11595 11609 D Unity : nitializers 04-28 12:25:50.302 11595 11746 E Unity : java.net.UnknownHostException: Unable to resolve host "config.uca.cloud.unity3d.com": No address associated with hostname 04-28 12:25:50.302 11595 11746 E Unity : 04-28 12:25:50.302 11595 11746 E Unity : (Filename: Line: 390) 04-28 12:25:50.302 11595 11746 E Unity : 04-28 12:25:50.735 11595 11609 E Unity : Unable to find libtensorflow
This is a problem similar to #342
@xiaomaogy Thank you so much for helping me out! I implemented the Unity project that merely reproduces the TFDetect app (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/DetectorActivity.java). I can share it with you if it helps.
@zkwen That would be really helpful if you could share it with me. Also are you using your second account?
@xiaomaogy lol Yeah @zkwencu is my primary account now. Was trying to tidy up this account but it was a mess. Started with a new one instead. To keep it consistent, I'll share the project under @alexwzk.
@xiaomaogy I just shared the project TFDetect-Unity with you. Let me know if you encounter any issues accessing and compiling the code. Thanks for taking a look. Looking forward to hearing back from you!
@alexwzk Thanks for sharing that. I will take a look this week and hopefully can get some clues regarding this.
@xiaomaogy Thank you! This is wonderful! And thanks again for your prompt reply after ur work hour.
@alexwzk I've tried with your code and the runtime is around 1.2s on Pixel 2XL. I've suggested a possible solution to this in https://github.com/Unity-Technologies/ml-agents/issues/342.
Also I'm trying to compile a newer version of TensorFlowSharp plugin for android, maybe in 1.7 version. When that completes I will post it here to let you try.
Excellent! I’ll try out your suggestions. Im also writing a native Tensorflow Java plugin for Unity from the scratch just in case other options still cant reduce the running time.
@xiaomaogy Yup, renaming the so dependency file does resolve issue #342, whereas the running time remains slow. I'll keep you posted when I come up with a solution. Thanks!
Hi, Vincent! Thank you so much for helping me investigating this issue! I'm wee embarrassed and just want to let you know that this issue can be closed. The reason my code being slow is not because of your TFSharp plugin. My code spends the extra 1s on allocating memory for several TF objects, which shouldn't be executed every time the session runs again. The performance becomes competitive with native Android code after I moved the following objects creation code to the Start() method:
m_Session = new TFSession(m_Graph);
m_Shape = new TFShape(1, s_InputSize, s_InputSize, 3); // 1 image per batch, width, height, 3 channels for rgb
m_PixelBytes = new byte[s_InputSize * s_InputSize * 3];
m_TfOutputs = new TFOutput[s_NumOutputs];
for (int i = 0; i < s_OutputStrings.Length; ++i)
{
m_TfOutputs[i] = m_Graph[s_OutputStrings[i]][0];
}
@zkwencu Glad to hear that you've found out the solution to the issue.
hey @alexwzk, can you share that project with me as well?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.