Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection Result not correct #5

Open
philp123 opened this issue Jan 6, 2020 · 0 comments
Open

Detection Result not correct #5

philp123 opened this issue Jan 6, 2020 · 0 comments

Comments

@philp123
Copy link

philp123 commented Jan 6, 2020

I used the following command to compile ncnn arm64-v8a library and my ndk version is 20.1.5948944(/home/liuwenjie/Android/Sdk/ndk/20.1.5948944)
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake
-DANDROID_ABI="arm64-v8a" -DANDROID_PLATFORM=android-21 -DCMAKE_INSTALL_PREFIX=/home/liuwen/ncnn_lib ..
This will create the libncnn.a static library.

Then I used ncnn-android-squeezenet squeezencnn_jni.cpp to compile libsqueezencnn.so. The libsqueezencnn.so has been created successfully and the apk is installed in my ViVO Z3.But the ncnn output.channel is always 0.

The only difference changed(squeezencnn_jni.cpp)

175 cls_scores.resize(out.w);
176 for (int j=0; j<out.w; j++)
177 {
178 cls_scores[j] = out[j]; ----------> const float* prob = out.channel(j);
----------> cls_scores[j] = prob[0];
179 }

CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_ANDROID_STL_TYPE c++_static)

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math -fopenmp")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math -std=c++11 -fopenmp")
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -Wl,--gc-sections -fopenmp")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--gc-sections -fopenmp")

if(CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -fopenmp")
endif()

set(NCNN_PATH /home/liuwenjie/ncnn_lib)
include_directories(${NCNN_PATH}/include)
include_directories(${NCNN_PATH}/include/ncnn)

add_library(ncnn STATIC IMPORTED)
set_target_properties(ncnn PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/arm64-v8a/libncnn.a)
find_library(log-lib log)
add_library(hello-jni SHARED squeezencnn_jni.cpp)
target_link_libraries(hello-jni android ncnn ${log-lib} jnigraphics z)

Android.mk

LOCAL_PATH := $(call my-dir)

NCNN_INSTALL_PATH := ${LOCAL_PATH}/ncnn-android-vulkan-lib

include $(CLEAR_VARS)
LOCAL_MODULE := ncnn
LOCAL_SRC_FILES := $(NCNN_INSTALL_PATH)/$(TARGET_ARCH_ABI)/libncnn.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := squeezencnn
LOCAL_SRC_FILES := squeezencnn_jni.cpp

LOCAL_C_INCLUDES := $(NCNN_INSTALL_PATH)/include $(NCNN_INSTALL_PATH)/include/ncnn

LOCAL_STATIC_LIBRARIES := ncnn

LOCAL_CFLAGS := -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math
LOCAL_CPPFLAGS := -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math
LOCAL_LDFLAGS += -Wl,--gc-sections

LOCAL_CFLAGS += -fopenmp
LOCAL_CPPFLAGS += -fopenmp
LOCAL_LDFLAGS += -fopenmp

LOCAL_LDLIBS := -lz -llog -ljnigraphics -lvulkan -landroid

include $(BUILD_SHARED_LIBRARY)

squeezencnn_jni.cpp

Both CMakeLists.txt and Android.mk could create libsqueezencnn.so library but produce 0.(sample in the following)
` std::vector cls_scores;
{
const float mean_vals[3] = {104.f, 117.f, 123.f};
in.substract_mean_normalize(mean_vals, 0);

    ncnn::Extractor ex = squeezenet.create_extractor();

    ex.set_vulkan_compute(use_gpu);

    ex.input(squeezenet_v1_1_param_id::BLOB_data, in);

172 ncnn::Mat out;
173 ex.extract(squeezenet_v1_1_param_id::BLOB_prob, out);

175 cls_scores.resize(out.w); -----> out.w == 0
}
`


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant