17 |
18 |
--------------------------------------------------------------------------------
/CNNCache/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/CNNCache/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/examples/squeezencnn/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CNNCache/app/CMakeFiles/feature_tests.c:
--------------------------------------------------------------------------------
1 |
2 | const char features[] = {"\n"
3 | "C_FEATURE:"
4 | #if ((__clang_major__ * 100) + __clang_minor__) >= 400
5 | "1"
6 | #else
7 | "0"
8 | #endif
9 | "c_function_prototypes\n"
10 | "C_FEATURE:"
11 | #if ((__clang_major__ * 100) + __clang_minor__) >= 400 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
12 | "1"
13 | #else
14 | "0"
15 | #endif
16 | "c_restrict\n"
17 | "C_FEATURE:"
18 | #if ((__clang_major__ * 100) + __clang_minor__) >= 400 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
19 | "1"
20 | #else
21 | "0"
22 | #endif
23 | "c_static_assert\n"
24 | "C_FEATURE:"
25 | #if ((__clang_major__ * 100) + __clang_minor__) >= 400 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
26 | "1"
27 | #else
28 | "0"
29 | #endif
30 | "c_variadic_macros\n"
31 |
32 | };
33 |
34 | int main(int argc, char** argv) { (void)argv; return features[argc]; }
35 |
--------------------------------------------------------------------------------
/src/blob.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "blob.h"
16 |
17 | namespace ncnn {
18 |
19 | Blob::Blob()
20 | {
21 | producer = -1;
22 | }
23 |
24 | } // namespace ncnn
25 |
--------------------------------------------------------------------------------
/examples/squeezencnn/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 | key.store=/home/nihui/osd/nihuini-release-key.keystore
19 | key.alias=nihuini
20 | key.store.password=nihuini
21 | key.alias.password=nihuini
22 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/platform.h.in:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef NCNN_PLATFORM_H
16 | #define NCNN_PLATFORM_H
17 |
18 | #cmakedefine01 NCNN_STDIO
19 | #cmakedefine01 NCNN_STRING
20 | #cmakedefine01 NCNN_OPENCV
21 | #cmakedefine01 NCNN_CNNCACHE
22 |
23 | #endif // NCNN_PLATFORM_H
24 |
--------------------------------------------------------------------------------
/tools/tensorflow/resource_handle.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "ResourceHandle";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | // Protocol buffer representing a handle to a tensorflow resource. Handles are
10 | // not valid across executions, but can be serialized back and forth from within
11 | // a single run.
12 | message ResourceHandleProto {
13 | // Unique name for the device containing the resource.
14 | string device = 1;
15 |
16 | // Container in which this resource is placed.
17 | string container = 2;
18 |
19 | // Unique name of this resource.
20 | string name = 3;
21 |
22 | // Hash code for the type of the resource. Is only valid in the same device
23 | // and in the same execution.
24 | uint64 hash_code = 4;
25 |
26 | // For debug-only, the name of the type pointed to by this handle, if
27 | // available.
28 | string maybe_type_name = 5;
29 | };
30 |
--------------------------------------------------------------------------------
/CNNCache/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/echo/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/examples/squeezencnn/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | # change this folder path to yours
4 | NCNN_INSTALL_PATH := /Users/echo/GoogleDrive/DL/ncnn/build-android/install
5 |
6 | include $(CLEAR_VARS)
7 | LOCAL_MODULE := ncnn
8 | LOCAL_SRC_FILES := $(NCNN_INSTALL_PATH)/lib/libncnn.a
9 | include $(PREBUILT_STATIC_LIBRARY)
10 |
11 | include $(CLEAR_VARS)
12 |
13 | LOCAL_MODULE := squeezencnn
14 | LOCAL_SRC_FILES := squeezencnn_jni.cpp
15 |
16 | LOCAL_C_INCLUDES := $(NCNN_INSTALL_PATH)/include
17 |
18 | LOCAL_STATIC_LIBRARIES := ncnn
19 |
20 | LOCAL_CFLAGS := -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math
21 | LOCAL_CPPFLAGS := -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math
22 | LOCAL_LDFLAGS += -Wl,--gc-sections
23 |
24 | LOCAL_CFLAGS += -fopenmp
25 | LOCAL_CPPFLAGS += -fopenmp
26 | LOCAL_LDFLAGS += -fopenmp
27 |
28 | LOCAL_LDLIBS := -lz -llog -ljnigraphics
29 |
30 | include $(BUILD_SHARED_LIBRARY)
31 |
--------------------------------------------------------------------------------
/src/layer/arm/lrn_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_LRN_ARM_H
16 | #define LAYER_LRN_ARM_H
17 |
18 | #include "lrn.h"
19 |
20 | namespace ncnn {
21 |
22 | class LRN_arm : public LRN
23 | {
24 | public:
25 | virtual int forward_inplace(Mat& bottom_top_blob) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_LRN_ARM_H
31 |
--------------------------------------------------------------------------------
/tools/tensorflow/versions.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "VersionsProtos";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | // Version information for a piece of serialized data
10 | //
11 | // There are different types of versions for each type of data
12 | // (GraphDef, etc.), but they all have the same common shape
13 | // described here.
14 | //
15 | // Each consumer has "consumer" and "min_producer" versions (specified
16 | // elsewhere). A consumer is allowed to consume this data if
17 | //
18 | // producer >= min_producer
19 | // consumer >= min_consumer
20 | // consumer not in bad_consumers
21 | //
22 | message VersionDef {
23 | // The version of the code that produced this data.
24 | int32 producer = 1;
25 |
26 | // Any consumer below this version is not allowed to consume this data.
27 | int32 min_consumer = 2;
28 |
29 | // Specific consumer versions which are disallowed (e.g. due to bugs).
30 | repeated int32 bad_consumers = 3;
31 | };
32 |
--------------------------------------------------------------------------------
/src/layer/arm/pooling_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_POOLING_ARM_H
16 | #define LAYER_POOLING_ARM_H
17 |
18 | #include "pooling.h"
19 |
20 | namespace ncnn {
21 |
22 | class Pooling_arm : public Pooling
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_POOLING_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/flatten.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_FLATTEN_H
16 | #define LAYER_FLATTEN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Flatten : public Layer
23 | {
24 | public:
25 | Flatten();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_FLATTEN_H
33 |
--------------------------------------------------------------------------------
/src/layer/arm/slice_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SLICE_ARM_H
16 | #define LAYER_SLICE_ARM_H
17 |
18 | #include "slice.h"
19 |
20 | namespace ncnn {
21 |
22 | class Slice_arm : public Slice
23 | {
24 | public:
25 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_SLICE_ARM_H
31 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/res/layout/activity_camera.xml:
--------------------------------------------------------------------------------
1 |
16 |
23 |
--------------------------------------------------------------------------------
/src/layer/arm/eltwise_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ELTWISE_ARM_H
16 | #define LAYER_ELTWISE_ARM_H
17 |
18 | #include "eltwise.h"
19 |
20 | namespace ncnn {
21 |
22 | class Eltwise_arm : public Eltwise
23 | {
24 | public:
25 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_ELTWISE_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/x86/convolution_x86.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CONVOLUTION_X86_H
16 | #define LAYER_CONVOLUTION_X86_H
17 |
18 | #include "convolution.h"
19 |
20 | namespace ncnn {
21 |
22 | class Convolution_x86 : public Convolution
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_CONVOLUTION_X86_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/innerproduct_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_INNERPRODUCT_ARM_H
16 | #define LAYER_INNERPRODUCT_ARM_H
17 |
18 | #include "innerproduct.h"
19 |
20 | namespace ncnn {
21 |
22 | class InnerProduct_arm : public InnerProduct
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_INNERPRODUCT_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/split.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SPLIT_H
16 | #define LAYER_SPLIT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Split : public Layer
23 | {
24 | public:
25 | Split();
26 |
27 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
28 |
29 | public:
30 | };
31 |
32 | } // namespace ncnn
33 |
34 | #endif // LAYER_SPLIT_H
35 |
--------------------------------------------------------------------------------
/src/layer/arm/deconvolution_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_DECONVOLUTION_ARM_H
16 | #define LAYER_DECONVOLUTION_ARM_H
17 |
18 | #include "deconvolution.h"
19 |
20 | namespace ncnn {
21 |
22 | class Deconvolution_arm : public Deconvolution
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_DECONVOLUTION_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/bias_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_BIAS_ARM_H
16 | #define LAYER_BIAS_ARM_H
17 |
18 | #include "bias.h"
19 |
20 | namespace ncnn {
21 |
22 | class Bias_arm : public Bias
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_BIAS_ARM_H
33 |
--------------------------------------------------------------------------------
/src/layer/arm/relu_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_RELU_ARM_H
16 | #define LAYER_RELU_ARM_H
17 |
18 | #include "relu.h"
19 |
20 | namespace ncnn {
21 |
22 | class ReLU_arm : public ReLU
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_RELU_ARM_H
33 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/java/edu/pku/sei/cnncache/MainActivity.java:
--------------------------------------------------------------------------------
1 | package edu.pku.sei.cnncache;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import edu.pku.sei.cnncache.benchmark.BenchmarkActivity;
9 | import edu.pku.sei.cnncache.classifier.ClassifierActivity;
10 |
11 | /**
12 | * Created by echo on 25/05/2018.
13 | */
14 |
15 | public class MainActivity extends Activity implements View.OnClickListener {
16 | @Override
17 | protected void onCreate(final Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.main);
20 | findViewById(R.id.benchmark_act).setOnClickListener(this);
21 | findViewById(R.id.classifier_act).setOnClickListener(this);
22 | }
23 |
24 | @Override
25 | public void onClick(View view) {
26 | if (view.getId() == R.id.benchmark_act) {
27 | Intent intent = new Intent(this, BenchmarkActivity.class);
28 | startActivity(intent);
29 | }
30 | if (view.getId() == R.id.classifier_act) {
31 | Intent intent = new Intent(this, ClassifierActivity.class);
32 | startActivity(intent);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/layer/arm/prelu_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_PRELU_ARM_H
16 | #define LAYER_PRELU_ARM_H
17 |
18 | #include "prelu.h"
19 |
20 | namespace ncnn {
21 |
22 | class PReLU_arm : public PReLU
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_PRELU_ARM_H
33 |
--------------------------------------------------------------------------------
/src/layer/arm/scale_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SCALE_ARM_H
16 | #define LAYER_SCALE_ARM_H
17 |
18 | #include "scale.h"
19 |
20 | namespace ncnn {
21 |
22 | class Scale_arm : public Scale
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_SCALE_ARM_H
33 |
--------------------------------------------------------------------------------
/src/layer/arm/sigmoid_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SIGMOID_ARM_H
16 | #define LAYER_SIGMOID_ARM_H
17 |
18 | #include "sigmoid.h"
19 |
20 | namespace ncnn {
21 |
22 | class Sigmoid_arm : public Sigmoid
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_SIGMOID_ARM_H
33 |
--------------------------------------------------------------------------------
/src/layer/arm/softmax_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SOFTMAX_ARM_H
16 | #define LAYER_SOFTMAX_ARM_H
17 |
18 | #include "softmax.h"
19 |
20 | namespace ncnn {
21 |
22 | class Softmax_arm : public Softmax
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_SOFTMAX_ARM_H
33 |
--------------------------------------------------------------------------------
/src/layer/bnll.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_BNLL_H
16 | #define LAYER_BNLL_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class BNLL : public Layer
23 | {
24 | public:
25 | BNLL();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob) const;
30 |
31 | public:
32 | };
33 |
34 | } // namespace ncnn
35 |
36 | #endif // LAYER_BNLL_H
37 |
--------------------------------------------------------------------------------
/src/layer/tanh.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_TANH_H
16 | #define LAYER_TANH_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class TanH : public Layer
23 | {
24 | public:
25 | TanH();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob) const;
30 |
31 | public:
32 | };
33 |
34 | } // namespace ncnn
35 |
36 | #endif // LAYER_TANH_H
37 |
--------------------------------------------------------------------------------
/src/layer/dropout.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_DROPOUT_H
16 | #define LAYER_DROPOUT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Dropout : public Layer
23 | {
24 | public:
25 | Dropout();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob) const;
30 |
31 | };
32 |
33 | } // namespace ncnn
34 |
35 | #endif // LAYER_DROPOUT_H
36 |
--------------------------------------------------------------------------------
/examples/squeezencnn/src/com/tencent/squeezencnn/SqueezeNcnn.java:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | package com.tencent.squeezencnn;
16 |
17 | import android.graphics.Bitmap;
18 | import android.content.Context;
19 |
20 | public class SqueezeNcnn
21 | {
22 | public native boolean Init(byte[] param, byte[] bin, byte[] words);
23 |
24 | public native String Detect(Bitmap bitmap);
25 |
26 | static {
27 | System.loadLibrary("squeezencnn");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/layer/absval.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ABSVAL_H
16 | #define LAYER_ABSVAL_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class AbsVal : public Layer
23 | {
24 | public:
25 | AbsVal();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob) const;
30 |
31 | public:
32 | };
33 |
34 | } // namespace ncnn
35 |
36 | #endif // LAYER_ABSVAL_H
37 |
--------------------------------------------------------------------------------
/src/layer/arm/absval_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ABSVAL_ARM_H
16 | #define LAYER_ABSVAL_ARM_H
17 |
18 | #include "absval.h"
19 |
20 | namespace ncnn {
21 |
22 | class AbsVal_arm : public AbsVal
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 |
29 | public:
30 | };
31 |
32 | } // namespace ncnn
33 |
34 | #endif // LAYER_ABSVAL_ARM_H
35 |
--------------------------------------------------------------------------------
/src/layer/arm/batchnorm_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_BATCHNORM_ARM_H
16 | #define LAYER_BATCHNORM_ARM_H
17 |
18 | #include "batchnorm.h"
19 |
20 | namespace ncnn {
21 |
22 | class BatchNorm_arm : public BatchNorm
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
26 |
27 | virtual int forward_inplace(Mat& bottom_top_blob) const;
28 | };
29 |
30 | } // namespace ncnn
31 |
32 | #endif // LAYER_BATCHNORM_ARM_H
33 |
--------------------------------------------------------------------------------
/src/layer/sigmoid.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SIGMOID_H
16 | #define LAYER_SIGMOID_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Sigmoid : public Layer
23 | {
24 | public:
25 | Sigmoid();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob) const;
30 |
31 | public:
32 | };
33 |
34 | } // namespace ncnn
35 |
36 | #endif // LAYER_SIGMOID_H
37 |
--------------------------------------------------------------------------------
/src/layer/softmax.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SOFTMAX_H
16 | #define LAYER_SOFTMAX_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Softmax : public Layer
23 | {
24 | public:
25 | Softmax();
26 |
27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob) const;
30 |
31 | public:
32 | };
33 |
34 | } // namespace ncnn
35 |
36 | #endif // LAYER_SOFTMAX_H
37 |
--------------------------------------------------------------------------------
/src/layer/split.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "split.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Split)
20 |
21 | Split::Split()
22 | {
23 | }
24 |
25 | int Split::forward(const std::vector& bottom_blobs, std::vector& top_blobs) const
26 | {
27 | const Mat& bottom_blob = bottom_blobs[0];
28 | for (size_t i=0; i
2 |
6 |
7 |
11 |
12 |
17 |
22 |
23 |
24 |
29 |
30 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/blob.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef NCNN_BLOB_H
16 | #define NCNN_BLOB_H
17 |
18 | #include
19 | #include
20 | #include "platform.h"
21 |
22 | namespace ncnn {
23 |
24 | class Blob
25 | {
26 | public:
27 | // empty
28 | Blob();
29 |
30 | public:
31 | #if NCNN_STRING
32 | // blob name
33 | std::string name;
34 | #endif // NCNN_STRING
35 | // layer index which produce this blob as output
36 | int producer;
37 | // layer index which need this blob as input
38 | std::vector consumers;
39 | };
40 |
41 | } // namespace ncnn
42 |
43 | #endif // NCNN_BLOB_H
44 |
--------------------------------------------------------------------------------
/src/layer/arm/convolution_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CONVOLUTION_ARM_H
16 | #define LAYER_CONVOLUTION_ARM_H
17 |
18 | #include "convolution.h"
19 |
20 | namespace ncnn {
21 |
22 | class Convolution_arm : public Convolution
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
26 | #if NCNN_CNNCACHE
27 | virtual bool needs_cache() const {return true;}
28 | virtual int forward_cached(const Mat& bottom_blob, Mat& top_blob, MRect& mrect, Mat& cached_blob) const;
29 | #endif
30 | };
31 |
32 | } // namespace ncnn
33 |
34 | #endif // LAYER_CONVOLUTION_ARM_H
35 |
--------------------------------------------------------------------------------
/package.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 | NAME=ncnn
4 |
5 | ##### package android lib
6 | ANDROIDPKGNAME=${NAME}-android-lib
7 | rm -rf $ANDROIDPKGNAME
8 | mkdir -p $ANDROIDPKGNAME
9 | mkdir -p $ANDROIDPKGNAME/armeabi-v7a
10 | mkdir -p $ANDROIDPKGNAME/arm64-v8a
11 | mkdir -p $ANDROIDPKGNAME/include
12 | cp build-android-armv7/install/lib/lib${NAME}.a $ANDROIDPKGNAME/armeabi-v7a/
13 | cp build-android-aarch64/install/lib/lib${NAME}.a $ANDROIDPKGNAME/arm64-v8a/
14 | cp build-android-aarch64/install/include/* $ANDROIDPKGNAME/include/
15 | rm -f $ANDROIDPKGNAME.zip
16 | zip -9 -r $ANDROIDPKGNAME.zip $ANDROIDPKGNAME
17 |
18 | ##### package ios framework
19 | IOSPKGNAME=${NAME}.framework
20 | rm -rf $IOSPKGNAME
21 | mkdir -p $IOSPKGNAME/Versions/A/Headers
22 | mkdir -p $IOSPKGNAME/Versions/A/Resources
23 | ln -s A $IOSPKGNAME/Versions/Current
24 | ln -s Versions/Current/Headers $IOSPKGNAME/Headers
25 | ln -s Versions/Current/Resources $IOSPKGNAME/Resources
26 | ln -s Versions/Current/${NAME} $IOSPKGNAME/${NAME}
27 | lipo -create \
28 | build-ios/install/lib/lib${NAME}.a \
29 | build-ios-sim/install/lib/lib${NAME}.a \
30 | -o $IOSPKGNAME/Versions/A/${NAME}
31 | cp -r build-ios/install/include/* $IOSPKGNAME/Versions/A/Headers/
32 | cp Info.plist ${IOSPKGNAME}/Versions/A/Resources/
33 | rm -f $IOSPKGNAME.zip
34 | zip -9 -y -r $IOSPKGNAME.zip $IOSPKGNAME
35 |
36 |
--------------------------------------------------------------------------------
/src/layer/concat.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CONCAT_H
16 | #define LAYER_CONCAT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Concat : public Layer
23 | {
24 | public:
25 | Concat();
26 |
27 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
28 |
29 | #if NCNN_CNNCACHE
30 | virtual int forward_mrect(std::vector& bottom_mrects, std::vector& top_mrects) const;
31 | virtual bool needs_cache() const {return false;}
32 | #endif
33 |
34 | public:
35 | };
36 |
37 | } // namespace ncnn
38 |
39 | #endif // LAYER_CONCAT_H
40 |
--------------------------------------------------------------------------------
/iosxc.toolchain.cmake:
--------------------------------------------------------------------------------
1 | # Standard settings
2 | # set(UNIX True)
3 | # set(Darwin True)
4 | # set(IOS True)
5 | set (CMAKE_SYSTEM_NAME Darwin)
6 | set (CMAKE_SYSTEM_VERSION 1)
7 | set (UNIX True)
8 | set (APPLE True)
9 | set (IOS True)
10 |
11 | # suppress -rdynamic
12 | # set(CMAKE_SYSTEM_NAME Generic)
13 |
14 | set(CMAKE_C_COMPILER arm-apple-darwin11-clang)
15 | set(CMAKE_CXX_COMPILER arm-apple-darwin11-clang++)
16 |
17 | set(_CMAKE_TOOLCHAIN_PREFIX arm-apple-darwin11-)
18 |
19 | set(CMAKE_IOS_SDK_ROOT "/home/nihui/osd/cctools-port/usage_examples/ios_toolchain/target/SDK/")
20 |
21 | # Set the sysroot default to the most recent SDK
22 | set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
23 |
24 | # set the architecture for iOS
25 | # set(IOS_ARCH arm64)
26 | set(IOS_ARCH armv7;arm64)
27 |
28 | set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
29 |
30 | # Set the find root to the iOS developer roots and to user defined paths
31 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
32 |
33 | # searching for frameworks only
34 | set(CMAKE_FIND_FRAMEWORK FIRST)
35 |
36 | # set up the default search directories for frameworks
37 | set(CMAKE_SYSTEM_FRAMEWORK_PATH
38 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
39 | )
40 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/cpp/image_util/rgb2yuv.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | #ifndef ORG_TENSORFLOW_JNI_IMAGEUTILS_RGB2YUV_H_
17 | #define ORG_TENSORFLOW_JNI_IMAGEUTILS_RGB2YUV_H_
18 |
19 | #include
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | void ConvertARGB8888ToYUV420SP(const uint32_t* const input,
26 | uint8_t* const output, int width, int height);
27 |
28 | void ConvertRGB565ToYUV420SP(const uint16_t* const input, uint8_t* const output,
29 | const int width, const int height);
30 |
31 | #ifdef __cplusplus
32 | }
33 | #endif
34 |
35 | #endif // ORG_TENSORFLOW_JNI_IMAGEUTILS_RGB2YUV_H_
36 |
--------------------------------------------------------------------------------
/src/layer/tile.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_TILE_H
16 | #define LAYER_TILE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Tile : public Layer
23 | {
24 | public:
25 | Tile();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | public:
38 | int dim;
39 | int tiles;
40 | };
41 |
42 | } // namespace ncnn
43 |
44 | #endif // LAYER_TILE_H
45 |
--------------------------------------------------------------------------------
/src/layer/arm/convolutiondepthwise_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CONVOLUTIONDEPTHWISE_ARM_H
16 | #define LAYER_CONVOLUTIONDEPTHWISE_ARM_H
17 |
18 | #include "convolutiondepthwise.h"
19 |
20 | namespace ncnn {
21 |
22 | class ConvolutionDepthWise_arm : public ConvolutionDepthWise
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
26 | #if NCNN_CNNCACHE
27 | virtual bool needs_cache() const {return true;}
28 | virtual int forward_cached(const Mat& bottom_blob, Mat& top_blob, MRect& mrect, Mat& cached_blob) const;
29 | #endif
30 | };
31 |
32 | } // namespace ncnn
33 |
34 | #endif // LAYER_CONVOLUTIONDEPTHWISE_ARM_H
35 |
--------------------------------------------------------------------------------
/src/layer/argmax.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ARGMAX_H
16 | #define LAYER_ARGMAX_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ArgMax : public Layer
23 | {
24 | public:
25 | ArgMax();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | public:
38 | int out_max_val;
39 | int topk;
40 | };
41 |
42 | } // namespace ncnn
43 |
44 | #endif // LAYER_ARGMAX_H
45 |
--------------------------------------------------------------------------------
/iossimxc.toolchain.cmake:
--------------------------------------------------------------------------------
1 | # Standard settings
2 | # set(UNIX True)
3 | # set(Darwin True)
4 | # set(IOS True)
5 | set (CMAKE_SYSTEM_NAME Darwin)
6 | set (CMAKE_SYSTEM_VERSION 1)
7 | set (UNIX True)
8 | set (APPLE True)
9 | set (IOS True)
10 |
11 | # suppress -rdynamic
12 | # set(CMAKE_SYSTEM_NAME Generic)
13 |
14 | set(CMAKE_C_COMPILER i386-apple-darwin11-clang)
15 | set(CMAKE_CXX_COMPILER i386-apple-darwin11-clang++)
16 |
17 | set(_CMAKE_TOOLCHAIN_PREFIX i386-apple-darwin11-)
18 |
19 | set(CMAKE_IOS_SDK_ROOT "/home/nihui/osd/cctools-port/usage_examples/ios_toolchain/target-sim/SDK/")
20 |
21 | # Set the sysroot default to the most recent SDK
22 | set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS Simulator support")
23 |
24 | # set the architecture for iOS
25 | # set(IOS_ARCH i386)
26 | # set(IOS_ARCH x86_64)
27 | set(IOS_ARCH i386;x86_64)
28 |
29 | set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS Simulator")
30 |
31 | # Set the find root to the iOS developer roots and to user defined paths
32 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS Simulator find search path root")
33 |
34 | # searching for frameworks only
35 | set(CMAKE_FIND_FRAMEWORK FIRST)
36 |
37 | # set up the default search directories for frameworks
38 | set(CMAKE_SYSTEM_FRAMEWORK_PATH
39 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
40 | )
41 |
--------------------------------------------------------------------------------
/src/layer/crop.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CROP_H
16 | #define LAYER_CROP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Crop : public Layer
23 | {
24 | public:
25 | Crop();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
36 |
37 | public:
38 | int woffset;
39 | int hoffset;
40 | };
41 |
42 | } // namespace ncnn
43 |
44 | #endif // LAYER_CROP_H
45 |
--------------------------------------------------------------------------------
/src/layer/mvn.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_MVN_H
16 | #define LAYER_MVN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class MVN : public Layer
23 | {
24 | public:
25 | MVN();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | public:
38 | int normalize_variance;
39 | int across_channels;
40 | float eps;
41 | };
42 |
43 | } // namespace ncnn
44 |
45 | #endif // LAYER_MVN_H
46 |
--------------------------------------------------------------------------------
/src/layer/slice.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SLICE_H
16 | #define LAYER_SLICE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Slice : public Layer
23 | {
24 | public:
25 | Slice();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
36 |
37 | public:
38 | int num_slice;
39 | Mat slices;
40 | };
41 |
42 | } // namespace ncnn
43 |
44 | #endif // LAYER_SLICE_H
45 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/layer/elu.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ELU_H
16 | #define LAYER_ELU_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ELU : public Layer
23 | {
24 | public:
25 | ELU();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | float alpha;
41 | };
42 |
43 | } // namespace ncnn
44 |
45 | #endif // LAYER_ELU_H
46 |
--------------------------------------------------------------------------------
/src/layer/relu.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_RELU_H
16 | #define LAYER_RELU_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ReLU : public Layer
23 | {
24 | public:
25 | ReLU();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | float slope;
41 | };
42 |
43 | } // namespace ncnn
44 |
45 | #endif // LAYER_RELU_H
46 |
--------------------------------------------------------------------------------
/src/layer/input.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_INPUT_H
16 | #define LAYER_INPUT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Input : public Layer
23 | {
24 | public:
25 | Input();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | int size[3];
41 | };
42 |
43 | } // namespace ncnn
44 |
45 | #endif // LAYER_INPUT_H
46 |
--------------------------------------------------------------------------------
/src/layer/reshape.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_RESHAPE_H
16 | #define LAYER_RESHAPE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Reshape : public Layer
23 | {
24 | public:
25 | Reshape();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | private:
38 | int w;
39 | int h;
40 | int c;
41 | int permute;
42 | int ndim;
43 | };
44 |
45 | } // namespace ncnn
46 |
47 | #endif // LAYER_RESHAPE_H
48 |
--------------------------------------------------------------------------------
/src/layer/threshold.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_THRESHOLD_H
16 | #define LAYER_THRESHOLD_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Threshold : public Layer
23 | {
24 | public:
25 | Threshold();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | float threshold;
41 | };
42 |
43 | } // namespace ncnn
44 |
45 | #endif // LAYER_THRESHOLD_H
46 |
--------------------------------------------------------------------------------
/src/layer/exp.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_EXP_H
16 | #define LAYER_EXP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Exp : public Layer
23 | {
24 | public:
25 | Exp();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | float base;
41 | float scale;
42 | float shift;
43 | };
44 |
45 | } // namespace ncnn
46 |
47 | #endif // LAYER_EXP_H
48 |
--------------------------------------------------------------------------------
/src/layer/log.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_LOG_H
16 | #define LAYER_LOG_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Log : public Layer
23 | {
24 | public:
25 | Log();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | float base;
41 | float scale;
42 | float shift;
43 | };
44 |
45 | } // namespace ncnn
46 |
47 | #endif // LAYER_LOG_H
48 |
--------------------------------------------------------------------------------
/src/layer/spp.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SPP_H
16 | #define LAYER_SPP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class SPP : public Layer
23 | {
24 | public:
25 | SPP();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | enum { PoolMethod_MAX = 0, PoolMethod_AVE = 1 };
38 |
39 | public:
40 | // param
41 | int pooling_type;
42 | int pyramid_height;
43 | };
44 |
45 | } // namespace ncnn
46 |
47 | #endif // LAYER_SPP_H
48 |
--------------------------------------------------------------------------------
/src/layer/power.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_POWER_H
16 | #define LAYER_POWER_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Power : public Layer
23 | {
24 | public:
25 | Power();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | float power;
41 | float scale;
42 | float shift;
43 | };
44 |
45 | } // namespace ncnn
46 |
47 | #endif // LAYER_POWER_H
48 |
--------------------------------------------------------------------------------
/src/layer/roipooling.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ROIPOOLING_H
16 | #define LAYER_ROIPOOLING_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ROIPooling : public Layer
23 | {
24 | public:
25 | ROIPooling();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
36 |
37 | public:
38 | int pooled_width;
39 | int pooled_height;
40 | float spatial_scale;
41 | };
42 |
43 | } // namespace ncnn
44 |
45 | #endif // LAYER_ROIPOOLING_H
46 |
--------------------------------------------------------------------------------
/src/layer/memorydata.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_MEMORYDATA_H
16 | #define LAYER_MEMORYDATA_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class MemoryData : public Layer
23 | {
24 | public:
25 | MemoryData();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | public:
40 | int channels;
41 | int width;
42 | int height;
43 |
44 | };
45 |
46 | } // namespace ncnn
47 |
48 | #endif // LAYER_MEMORYDATA_H
49 |
--------------------------------------------------------------------------------
/src/layer/eltwise.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_ELTWISE_H
16 | #define LAYER_ELTWISE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Eltwise : public Layer
23 | {
24 | public:
25 | Eltwise();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
36 |
37 | enum { Operation_PROD = 0, Operation_SUM = 1, Operation_MAX = 2 };
38 |
39 | public:
40 | // param
41 | int op_type;
42 | int num_coeff;
43 | Mat coeffs;
44 | };
45 |
46 | } // namespace ncnn
47 |
48 | #endif // LAYER_ELTWISE_H
49 |
--------------------------------------------------------------------------------
/src/layer/prelu.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_PRELU_H
16 | #define LAYER_PRELU_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class PReLU : public Layer
23 | {
24 | public:
25 | PReLU();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | virtual int load_model(FILE* binfp);
33 | #endif // NCNN_STDIO
34 | virtual int load_param(const unsigned char*& mem);
35 | virtual int load_model(const unsigned char*& mem);
36 |
37 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
38 |
39 | virtual int forward_inplace(Mat& bottom_top_blob) const;
40 |
41 | public:
42 | int num_slope;
43 | Mat slope_data;
44 | };
45 |
46 | } // namespace ncnn
47 |
48 | #endif // LAYER_PRELU_H
49 |
--------------------------------------------------------------------------------
/src/layer/lrn.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_LRN_H
16 | #define LAYER_LRN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class LRN : public Layer
23 | {
24 | public:
25 | LRN();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | enum { NormRegion_ACROSS_CHANNELS = 0, NormRegion_WITHIN_CHANNEL = 1 };
40 |
41 | public:
42 | // param
43 | int region_type;
44 | int local_size;
45 | float alpha;
46 | float beta;
47 | };
48 |
49 | } // namespace ncnn
50 |
51 | #endif // LAYER_LRN_H
52 |
--------------------------------------------------------------------------------
/src/layer/proposal.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_PROPOSAL_H
16 | #define LAYER_PROPOSAL_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Proposal : public Layer
23 | {
24 | public:
25 | Proposal();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
36 |
37 | public:
38 | // param
39 | int feat_stride;
40 | int base_size;
41 | // float ratio;
42 | // float scale;
43 | int pre_nms_topN;
44 | int after_nms_topN;
45 | float nms_thresh;
46 | int min_size;
47 | };
48 |
49 | } // namespace ncnn
50 |
51 | #endif // LAYER_PROPOSAL_H
52 |
--------------------------------------------------------------------------------
/src/layer/bias.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_BIAS_H
16 | #define LAYER_BIAS_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Bias : public Layer
23 | {
24 | public:
25 | Bias();
26 | virtual ~Bias();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
39 |
40 | virtual int forward_inplace(Mat& bottom_top_blob) const;
41 |
42 | public:
43 | // param
44 | int bias_data_size;
45 |
46 | // model
47 | Mat bias_data;
48 | };
49 |
50 | } // namespace ncnn
51 |
52 | #endif // LAYER_BIAS_H
53 |
--------------------------------------------------------------------------------
/src/layer/flatten.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "flatten.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Flatten)
20 |
21 | Flatten::Flatten()
22 | {
23 | one_blob_only = true;
24 | support_inplace = false;
25 | }
26 |
27 | int Flatten::forward(const Mat& bottom_blob, Mat& top_blob) const
28 | {
29 | int w = bottom_blob.w;
30 | int h = bottom_blob.h;
31 | int channels = bottom_blob.c;
32 | int size = w * h;
33 |
34 | top_blob.create(size * channels);
35 | if (top_blob.empty())
36 | return -100;
37 |
38 | #pragma omp parallel for
39 | for (int q=0; q& bottom_blobs, std::vector& top_blobs) const;
39 |
40 | public:
41 | // param
42 | int num_output;
43 | int weight_data_size;
44 |
45 | // model
46 | Mat weight_hc_data;
47 | Mat weight_xc_data;
48 | Mat bias_c_data;
49 | };
50 |
51 | } // namespace ncnn
52 |
53 | #endif // LAYER_LSTM_H
54 |
--------------------------------------------------------------------------------
/src/layer/pooling.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_POOLING_H
16 | #define LAYER_POOLING_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Pooling : public Layer
23 | {
24 | public:
25 | Pooling();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | #if NCNN_CNNCACHE
38 | virtual int forward_mrect(MRect& bottom_mrect, MRect& top_mrect) const;
39 | #endif
40 |
41 | enum { PoolMethod_MAX = 0, PoolMethod_AVE = 1 };
42 |
43 | public:
44 | // param
45 | int pooling_type;
46 | int kernel_size;
47 | int stride;
48 | int pad;
49 | int global_pooling;
50 | };
51 |
52 | } // namespace ncnn
53 |
54 | #endif // LAYER_POOLING_H
55 |
--------------------------------------------------------------------------------
/src/layer/scale.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_SCALE_H
16 | #define LAYER_SCALE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Scale : public Layer
23 | {
24 | public:
25 | Scale();
26 | virtual ~Scale();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
39 |
40 | virtual int forward_inplace(Mat& bottom_top_blob) const;
41 |
42 | public:
43 | // param
44 | int scale_data_size;
45 | int bias_term;
46 |
47 | // model
48 | Mat scale_data;
49 | Mat bias_data;
50 | };
51 |
52 | } // namespace ncnn
53 |
54 | #endif // LAYER_SCALE_H
55 |
--------------------------------------------------------------------------------
/src/layer/binaryop.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_BINARYOP_H
16 | #define LAYER_BINARYOP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class BinaryOp : public Layer
23 | {
24 | public:
25 | BinaryOp();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
36 |
37 | enum {
38 | Operation_ADD = 0,
39 | Operation_SUB = 1,
40 | Operation_MUL = 2,
41 | Operation_DIV = 3,
42 | Operation_MAX = 4,
43 | Operation_MIN = 5,
44 | Operation_POW = 6
45 | };
46 |
47 | public:
48 | // param
49 | int op_type;
50 | };
51 |
52 | } // namespace ncnn
53 |
54 | #endif // LAYER_BINARYOP_H
55 |
--------------------------------------------------------------------------------
/src/layer/innerproduct.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_INNERPRODUCT_H
16 | #define LAYER_INNERPRODUCT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class InnerProduct : public Layer
23 | {
24 | public:
25 | InnerProduct();
26 | virtual ~InnerProduct();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
39 |
40 | public:
41 | // param
42 | int num_output;
43 | int bias_term;
44 |
45 | int weight_data_size;
46 |
47 | // model
48 | Mat weight_data;
49 | Mat bias_data;
50 | };
51 |
52 | } // namespace ncnn
53 |
54 | #endif // LAYER_INNERPRODUCT_H
55 |
--------------------------------------------------------------------------------
/src/layer/rnn.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_RNN_H
16 | #define LAYER_RNN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class RNN : public Layer
23 | {
24 | public:
25 | RNN();
26 | virtual ~RNN();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs) const;
39 |
40 | public:
41 | // param
42 | int num_output;
43 | int weight_data_size;
44 |
45 | // model
46 | Mat weight_hh_data;
47 | Mat weight_xh_data;
48 | Mat weight_ho_data;
49 | Mat bias_h_data;
50 | Mat bias_o_data;
51 | };
52 |
53 | } // namespace ncnn
54 |
55 | #endif // LAYER_RNN_H
56 |
--------------------------------------------------------------------------------
/tools/tensorflow/tensor_shape.proto:
--------------------------------------------------------------------------------
1 | // Protocol buffer representing the shape of tensors.
2 |
3 | syntax = "proto3";
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "TensorShapeProtos";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | package tensorflow;
10 |
11 | // Dimensions of a tensor.
12 | message TensorShapeProto {
13 | // One dimension of the tensor.
14 | message Dim {
15 | // Size of the tensor in that dimension.
16 | // This value must be >= -1, but values of -1 are reserved for "unknown"
17 | // shapes (values of -1 mean "unknown" dimension). Certain wrappers
18 | // that work with TensorShapeProto may fail at runtime when deserializing
19 | // a TensorShapeProto containing a dim value of -1.
20 | int64 size = 1;
21 |
22 | // Optional name of the tensor dimension.
23 | string name = 2;
24 | };
25 |
26 | // Dimensions of the tensor, such as {"input", 30}, {"output", 40}
27 | // for a 30 x 40 2D tensor. If an entry has size -1, this
28 | // corresponds to a dimension of unknown size. The names are
29 | // optional.
30 | //
31 | // The order of entries in "dim" matters: It indicates the layout of the
32 | // values in the tensor in-memory representation.
33 | //
34 | // The first entry in "dim" is the outermost dimension used to layout the
35 | // values, the last entry is the innermost dimension. This matches the
36 | // in-memory layout of RowMajor Eigen tensors.
37 | //
38 | // If "dim.size()" > 0, "unknown_rank" must be false.
39 | repeated Dim dim = 2;
40 |
41 | // If true, the number of dimensions in the shape is unknown.
42 | //
43 | // If true, "dim.size()" must be 0.
44 | bool unknown_rank = 3;
45 | };
46 |
--------------------------------------------------------------------------------
/src/layer/reduction.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_REDUCTION_H
16 | #define LAYER_REDUCTION_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Reduction : public Layer
23 | {
24 | public:
25 | Reduction();
26 | virtual ~Reduction();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | #endif // NCNN_STDIO
34 | virtual int load_param(const unsigned char*& mem);
35 |
36 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
37 |
38 | enum {
39 | ReductionOp_SUM = 0,
40 | ReductionOp_ASUM = 1,
41 | ReductionOp_SUMSQ = 2,
42 | ReductionOp_MEAN = 3,
43 | ReductionOp_MAX = 4,
44 | ReductionOp_MIN = 5
45 | };
46 |
47 | public:
48 | // param
49 | int operation;
50 | int dim;
51 | float coeff;
52 | };
53 |
54 | } // namespace ncnn
55 |
56 | #endif // LAYER_REDUCTION_H
57 |
--------------------------------------------------------------------------------
/src/layer/batchnorm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_BATCHNORM_H
16 | #define LAYER_BATCHNORM_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class BatchNorm : public Layer
23 | {
24 | public:
25 | BatchNorm();
26 | virtual ~BatchNorm();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
39 |
40 | virtual int forward_inplace(Mat& bottom_top_blob) const;
41 |
42 | public:
43 | // param
44 | int channels;
45 |
46 | // model
47 | Mat slope_data;
48 | Mat mean_data;
49 | Mat var_data;
50 | Mat bias_data;
51 |
52 | Mat a_data;
53 | Mat b_data;
54 | };
55 |
56 | } // namespace ncnn
57 |
58 | #endif // LAYER_BATCHNORM_H
59 |
--------------------------------------------------------------------------------
/src/layer/deconvolution.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_DECONVOLUTION_H
16 | #define LAYER_DECONVOLUTION_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Deconvolution : public Layer
23 | {
24 | public:
25 | Deconvolution();
26 | virtual ~Deconvolution();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
39 |
40 | public:
41 | // param
42 | int num_output;
43 | int kernel_size;
44 | int dilation;
45 | int stride;
46 | int pad;
47 | int bias_term;
48 |
49 | int weight_data_size;
50 |
51 | // model
52 | Mat weight_data;
53 | Mat bias_data;
54 | };
55 |
56 | } // namespace ncnn
57 |
58 | #endif // LAYER_DECONVOLUTION_H
59 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/java/edu/pku/sei/cnncache/UI/OverlayView.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package edu.pku.sei.cnncache.UI;
17 |
18 | import android.content.Context;
19 | import android.graphics.Canvas;
20 | import android.util.AttributeSet;
21 | import android.view.View;
22 | import java.util.LinkedList;
23 | import java.util.List;
24 |
25 | /**
26 | * A simple View providing a render callback to other classes.
27 | */
28 | public class OverlayView extends View {
29 | private final List callbacks = new LinkedList();
30 |
31 | public OverlayView(final Context context, final AttributeSet attrs) {
32 | super(context, attrs);
33 | }
34 |
35 | /**
36 | * Interface defining the callback for client classes.
37 | */
38 | public interface DrawCallback {
39 | public void drawCallback(final Canvas canvas);
40 | }
41 |
42 | public void addCallback(final DrawCallback callback) {
43 | callbacks.add(callback);
44 | }
45 |
46 | @Override
47 | public synchronized void draw(final Canvas canvas) {
48 | for (final DrawCallback callback : callbacks) {
49 | callback.drawCallback(canvas);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/layer/convolutiondepthwise.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CONVOLUTIONDEPTHWISE_H
16 | #define LAYER_CONVOLUTIONDEPTHWISE_H
17 |
18 | #include "layer.h"
19 | #include "convolution.h"
20 |
21 | namespace ncnn {
22 |
23 | class ConvolutionDepthWise : public Convolution
24 | {
25 | public:
26 | ConvolutionDepthWise();
27 | virtual ~ConvolutionDepthWise();
28 |
29 | #if NCNN_STDIO
30 | #if NCNN_STRING
31 | virtual int load_param(FILE* paramfp);
32 | #endif // NCNN_STRING
33 | virtual int load_param_bin(FILE* paramfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 |
37 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
38 |
39 | #if NCNN_CNNCACHE
40 | virtual int forward_mrect(MRect& bottom_mrect, MRect& top_mrect) const;
41 | virtual int forward_cached(const Mat& bottom_blob, Mat& top_blob, MRect& mrect, Mat& cached_blob) const;
42 | virtual bool needs_cache() const {return true;}
43 | #endif
44 |
45 | public:
46 | int group;
47 | };
48 |
49 | } // namespace ncnn
50 |
51 | #endif // LAYER_CONVOLUTIONDEPTHWISE_H
52 |
--------------------------------------------------------------------------------
/src/cpu.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef NCNN_CPU_H
16 | #define NCNN_CPU_H
17 |
18 | namespace ncnn {
19 |
20 | // test optional cpu features
21 | // neon = armv7 neon or aarch64 asimd
22 | int cpu_support_arm_neon();
23 | // vfpv4 = armv7 fp16 + fma
24 | int cpu_support_arm_vfpv4();
25 | // asimdhp = aarch64 asimd half precision
26 | int cpu_support_arm_asimdhp();
27 |
28 | // cpu info
29 | int get_cpu_count();
30 |
31 | // bind all threads on little clusters if powersave enabled
32 | // affacts HMP arch cpu like ARM big.LITTLE
33 | // only implemented on android at the moment
34 | // switching powersave is expensive and not thread-safe
35 | // 0 = all cores enabled(default)
36 | // 1 = only little clusters enabled
37 | // 2 = only big clusters enabled
38 | // return 0 if success for setter function
39 | int get_cpu_powersave();
40 | int set_cpu_powersave(int powersave);
41 |
42 | // misc function wrapper for openmp routines
43 | int get_omp_num_threads();
44 | void set_omp_num_threads(int num_threads);
45 |
46 | int get_omp_dynamic();
47 | void set_omp_dynamic(int dynamic);
48 |
49 | } // namespace ncnn
50 |
51 | #endif // NCNN_CPU_H
52 |
--------------------------------------------------------------------------------
/src/layer/unaryop.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_UNARYOP_H
16 | #define LAYER_UNARYOP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class UnaryOp : public Layer
23 | {
24 | public:
25 | UnaryOp();
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | virtual int load_param(FILE* paramfp);
30 | #endif // NCNN_STRING
31 | virtual int load_param_bin(FILE* paramfp);
32 | #endif // NCNN_STDIO
33 | virtual int load_param(const unsigned char*& mem);
34 |
35 | virtual int forward(const Mat& bottom_blob, Mat& top_blob) const;
36 |
37 | virtual int forward_inplace(Mat& bottom_top_blob) const;
38 |
39 | enum {
40 | Operation_ABS = 0,
41 | Operation_NEG = 1,
42 | Operation_FLOOR = 2,
43 | Operation_CEIL = 3,
44 | Operation_SQUARE= 4,
45 | Operation_SQRT = 5,
46 | Operation_RSQRT = 6,
47 | Operation_EXP = 7,
48 | Operation_LOG = 8,
49 | Operation_SIN = 9,
50 | Operation_COS = 10,
51 | Operation_TAN = 11,
52 | Operation_ASIN = 12,
53 | Operation_ACOS = 13,
54 | Operation_ATAN = 14
55 | };
56 |
57 | public:
58 | // param
59 | int op_type;
60 | };
61 |
62 | } // namespace ncnn
63 |
64 | #endif // LAYER_UNARYOP_H
65 |
--------------------------------------------------------------------------------
/src/layer/convolution.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef LAYER_CONVOLUTION_H
16 | #define LAYER_CONVOLUTION_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Convolution : public Layer
23 | {
24 | public:
25 | Convolution();
26 | virtual ~Convolution();
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | virtual int load_param(FILE* paramfp);
31 | #endif // NCNN_STRING
32 | virtual int load_param_bin(FILE* paramfp);
33 | virtual int load_model(FILE* binfp);
34 | #endif // NCNN_STDIO
35 | virtual int load_param(const unsigned char*& mem);
36 | virtual int load_model(const unsigned char*& mem);
37 |
38 | virtual int forward(const Mat& bottom_blobs, Mat& top_blobs) const;
39 |
40 | #if NCNN_CNNCACHE
41 | virtual int forward_mrect(MRect& bottom_mrect, MRect& top_mrect) const;
42 | virtual int forward_cached(const Mat& bottom_blob, Mat& top_blob, MRect& mrect, Mat& cached_blob) const;
43 | virtual bool needs_cache() const {return true;}
44 | #endif
45 |
46 | public:
47 | // param
48 | int num_output;
49 | int kernel_size;
50 | int dilation;
51 | int stride;
52 | int pad;
53 | int bias_term;
54 |
55 | int weight_data_size;
56 |
57 | // model
58 | Mat weight_data;
59 | Mat bias_data;
60 | };
61 |
62 | } // namespace ncnn
63 |
64 | #endif // LAYER_CONVOLUTION_H
65 |
--------------------------------------------------------------------------------
/src/layer/arm/deconvolution_arm.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "deconvolution_arm.h"
16 |
17 | namespace ncnn {
18 |
19 | #include "deconvolution_3x3.h"
20 |
21 | DEFINE_LAYER_CREATOR(Deconvolution_arm)
22 |
23 | int Deconvolution_arm::forward(const Mat& bottom_blob, Mat& top_blob) const
24 | {
25 | if (kernel_size != 3 || stride != 1 || dilation != 1)
26 | {
27 | return Deconvolution::forward(bottom_blob, top_blob);
28 | }
29 |
30 | typedef void (*deconv_func)(const Mat&, Mat&, const Mat&, const Mat&);
31 |
32 | deconv_func deconv = deconv3x3s1_neon;
33 |
34 | int w = bottom_blob.w;
35 | int h = bottom_blob.h;
36 | int channels = bottom_blob.c;
37 |
38 | int outw = (w - 1) * stride + kernel_size;
39 | int outh = (h - 1) * stride + kernel_size;
40 |
41 | Mat top_blob_bordered;
42 | top_blob_bordered.create(outw, outh, num_output);
43 | if (top_blob_bordered.empty())
44 | return -100;
45 |
46 | deconv(bottom_blob, top_blob_bordered, weight_data, bias_data);
47 |
48 | top_blob = top_blob_bordered;
49 |
50 | if (pad > 0)
51 | {
52 | copy_cut_border(top_blob_bordered, top_blob, pad, pad, pad, pad);
53 | if (top_blob.empty())
54 | return -100;
55 |
56 | outw = top_blob.w;
57 | outh = top_blob.h;
58 | }
59 |
60 | return 0;
61 | }
62 |
63 | } // namespace ncnn
64 |
--------------------------------------------------------------------------------
/src/layer/input.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "input.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Input)
20 |
21 | Input::Input()
22 | {
23 | one_blob_only = true;
24 | support_inplace = true;
25 | }
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | int Input::load_param(FILE* paramfp)
30 | {
31 | int nscan = fscanf(paramfp, "%d %d %d",
32 | &size[0], &size[1], &size[2]);
33 | if (nscan != 3)
34 | {
35 | fprintf(stderr, "Input load_param failed %d\n", nscan);
36 | return -1;
37 | }
38 |
39 | return 0;
40 | }
41 | #endif // NCNN_STRING
42 | int Input::load_param_bin(FILE* paramfp)
43 | {
44 | fread(&size[0], sizeof(int), 1, paramfp);
45 |
46 | fread(&size[1], sizeof(int), 1, paramfp);
47 |
48 | fread(&size[2], sizeof(int), 1, paramfp);
49 |
50 | return 0;
51 | }
52 | #endif // NCNN_STDIO
53 |
54 | int Input::load_param(const unsigned char*& mem)
55 | {
56 | size[0] = *(int*)(mem);
57 | mem += 4;
58 |
59 | size[1] = *(int*)(mem);
60 | mem += 4;
61 |
62 | size[2] = *(int*)(mem);
63 | mem += 4;
64 |
65 | return 0;
66 | }
67 |
68 | int Input::forward(const Mat& /*bottom_blob*/, Mat& /*top_blob*/) const
69 | {
70 | return 0;
71 | }
72 |
73 | int Input::forward_inplace(Mat& /*bottom_top_blob*/) const
74 | {
75 | return 0;
76 | }
77 |
78 | } // namespace ncnn
79 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/java/edu/pku/sei/cnncache/UI/AutoFitTextureView.java:
--------------------------------------------------------------------------------
1 | package edu.pku.sei.cnncache.UI;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.TextureView;
6 |
7 | /**
8 | * A {@link TextureView} that can be adjusted to a specified aspect ratio.
9 | */
10 | public class AutoFitTextureView extends TextureView {
11 | private int ratioWidth = 0;
12 | private int ratioHeight = 0;
13 |
14 | public AutoFitTextureView(final Context context) {
15 | this(context, null);
16 | }
17 |
18 | public AutoFitTextureView(final Context context, final AttributeSet attrs) {
19 | this(context, attrs, 0);
20 | }
21 |
22 | public AutoFitTextureView(final Context context, final AttributeSet attrs, final int defStyle) {
23 | super(context, attrs, defStyle);
24 | }
25 |
26 | /**
27 | * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
28 | * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
29 | * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
30 | *
31 | * @param width Relative horizontal size
32 | * @param height Relative vertical size
33 | */
34 | public void setAspectRatio(final int width, final int height) {
35 | if (width < 0 || height < 0) {
36 | throw new IllegalArgumentException("Size cannot be negative.");
37 | }
38 | ratioWidth = width;
39 | ratioHeight = height;
40 | requestLayout();
41 | }
42 |
43 | @Override
44 | protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
45 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
46 | final int width = MeasureSpec.getSize(widthMeasureSpec);
47 | final int height = MeasureSpec.getSize(heightMeasureSpec);
48 | if (0 == ratioWidth || 0 == ratioHeight) {
49 | setMeasuredDimension(width, height);
50 | } else {
51 | if (width < height * ratioWidth / ratioHeight) {
52 | setMeasuredDimension(width, width * ratioHeight / ratioWidth);
53 | } else {
54 | setMeasuredDimension(height * ratioWidth / ratioHeight, height);
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2016 The Android Open Source Project
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | project(TENSORFLOW_DEMO)
18 | cmake_minimum_required(VERSION 3.4.1)
19 |
20 | set(CMAKE_VERBOSE_MAKEFILE on)
21 |
22 | get_filename_component(TF_SRC_ROOT ${CMAKE_SOURCE_DIR}/../../../.. ABSOLUTE)
23 | get_filename_component(SAMPLE_SRC_DIR ${CMAKE_SOURCE_DIR}/.. ABSOLUTE)
24 |
25 | if (ANDROID_ABI MATCHES "^armeabi-v7a$")
26 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp -mfpu=neon")
27 | elseif(ANDROID_ABI MATCHES "^arm64-v8a")
28 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -ftree-vectorize")
29 | endif()
30 |
31 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTANDALONE_DEMO_LIB \
32 | -std=c++11 -fno-exceptions -fno-rtti -O2 -Wno-narrowing \
33 | -fPIE")
34 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
35 | -Wl,--allow-multiple-definition \
36 | -Wl,--whole-archive -fPIE -v")
37 |
38 | file(GLOB_RECURSE tensorflow_demo_sources ${SAMPLE_SRC_DIR}/jni/*.*)
39 | add_library(tensorflow_demo SHARED
40 | ${tensorflow_demo_sources})
41 | target_include_directories(tensorflow_demo PRIVATE
42 | ${TF_SRC_ROOT}
43 | ${CMAKE_SOURCE_DIR})
44 |
45 | target_link_libraries(tensorflow_demo
46 | android
47 | log
48 | jnigraphics
49 | m
50 | atomic
51 | z)
52 |
--------------------------------------------------------------------------------
/src/layer/tanh.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "tanh.h"
16 | #include
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(TanH)
21 |
22 | TanH::TanH()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | int TanH::forward(const Mat& bottom_blob, Mat& top_blob) const
29 | {
30 | int w = bottom_blob.w;
31 | int h = bottom_blob.h;
32 | int channels = bottom_blob.c;
33 | int size = w * h;
34 |
35 | top_blob.create(w, h, channels);
36 | if (top_blob.empty())
37 | return -100;
38 |
39 | #pragma omp parallel for
40 | for (int q=0; q
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(Sigmoid)
21 |
22 | Sigmoid::Sigmoid()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | int Sigmoid::forward(const Mat& bottom_blob, Mat& top_blob) const
29 | {
30 | int w = bottom_blob.w;
31 | int h = bottom_blob.h;
32 | int channels = bottom_blob.c;
33 | int size = w * h;
34 |
35 | top_blob.create(w, h, channels);
36 | if (top_blob.empty())
37 | return -100;
38 |
39 | #pragma omp parallel for
40 | for (int q=0; q
2 |
6 |
7 |
11 |
12 |
17 |
22 |
27 |
32 |
33 |
34 |
38 |
43 |
44 |
49 |
50 |
51 |
56 |
57 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/tools/tensorflow/graph.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "GraphProtos";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | import "node_def.proto";
10 | import "function.proto";
11 | import "versions.proto";
12 |
13 | // Represents the graph of operations
14 | message GraphDef {
15 | repeated NodeDef node = 1;
16 |
17 | // Compatibility versions of the graph. See core/public/version.h for version
18 | // history. The GraphDef version is distinct from the TensorFlow version, and
19 | // each release of TensorFlow will support a range of GraphDef versions.
20 | VersionDef versions = 4;
21 |
22 | // Deprecated single version field; use versions above instead. Since all
23 | // GraphDef changes before "versions" was introduced were forward
24 | // compatible, this field is entirely ignored.
25 | int32 version = 3 [deprecated = true];
26 |
27 | // EXPERIMENTAL. DO NOT USE OR DEPEND ON THIS YET.
28 | //
29 | // "library" provides user-defined functions.
30 | //
31 | // Naming:
32 | // * library.function.name are in a flat namespace.
33 | // NOTE: We may need to change it to be hierarchical to support
34 | // different orgs. E.g.,
35 | // { "/google/nn", { ... }},
36 | // { "/google/vision", { ... }}
37 | // { "/org_foo/module_bar", { ... }}
38 | // map named_lib;
39 | // * If node[i].op is the name of one function in "library",
40 | // node[i] is deemed as a function call. Otherwise, node[i].op
41 | // must be a primitive operation supported by the runtime.
42 | //
43 | //
44 | // Function call semantics:
45 | //
46 | // * The callee may start execution as soon as some of its inputs
47 | // are ready. The caller may want to use Tuple() mechanism to
48 | // ensure all inputs are ready in the same time.
49 | //
50 | // * The consumer of return values may start executing as soon as
51 | // the return values the consumer depends on are ready. The
52 | // consumer may want to use Tuple() mechanism to ensure the
53 | // consumer does not start until all return values of the callee
54 | // function are ready.
55 | FunctionDefLibrary library = 2;
56 | };
57 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | if(CMAKE_TOOLCHAIN_FILE)
3 | set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to")
4 | # get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :(
5 | get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME)
6 | find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
7 | message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
8 | endif()
9 |
10 | if(NOT DEFINED CMAKE_INSTALL_PREFIX)
11 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
12 | endif()
13 | message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
14 |
15 | project(ncnn)
16 |
17 | cmake_minimum_required(VERSION 2.8.10)
18 |
19 | # set(CMAKE_BUILD_TYPE debug)
20 | # set(CMAKE_BUILD_TYPE relwithdebinfo)
21 | set(CMAKE_BUILD_TYPE release)
22 | set (CMAKE_CXX_STANDARD 11)
23 |
24 | option(NCNN_OPENMP "openmp support" ON)
25 | option(NCNN_STDIO "load model from external file" ON)
26 | option(NCNN_STRING "plain and verbose string" ON)
27 | option(NCNN_OPENCV "minimal opencv structure emulation" OFF)
28 | option(NCNN_CNNCACHE "using cnncache" ON)
29 |
30 | if(NCNN_OPENMP)
31 | find_package(OpenMP)
32 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
33 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
34 | endif()
35 |
36 | add_definitions(-Wall -Wextra)
37 |
38 | add_definitions(-fPIC)
39 | add_definitions(-Ofast)
40 |
41 | add_definitions(-ffast-math)
42 | # add_definitions(-march=native)
43 |
44 | # add_definitions(-flto)
45 |
46 | add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
47 |
48 | if(ANDROID)
49 | # disable shared library on android
50 | set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
51 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
52 | elseif(IOS)
53 | # disable shared library on xcode ios
54 | set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
55 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
56 | endif()
57 |
58 | ##############################################
59 |
60 | # add_subdirectory(examples)
61 | add_subdirectory(src)
62 | if(NOT ANDROID AND NOT IOS)
63 | add_subdirectory(tools)
64 | endif()
65 |
--------------------------------------------------------------------------------
/src/layer/crop.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "crop.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Crop)
20 |
21 | Crop::Crop()
22 | {
23 | }
24 |
25 | #if NCNN_STDIO
26 | #if NCNN_STRING
27 | int Crop::load_param(FILE* paramfp)
28 | {
29 | int nscan = fscanf(paramfp, "%d %d", &woffset, &hoffset);
30 | if (nscan != 2)
31 | {
32 | fprintf(stderr, "Crop load_param failed %d\n", nscan);
33 | return -1;
34 | }
35 |
36 | return 0;
37 | }
38 | #endif // NCNN_STRING
39 | int Crop::load_param_bin(FILE* paramfp)
40 | {
41 | fread(&woffset, sizeof(int), 1, paramfp);
42 |
43 | fread(&hoffset, sizeof(int), 1, paramfp);
44 |
45 | return 0;
46 | }
47 | #endif // NCNN_STDIO
48 |
49 | int Crop::load_param(const unsigned char*& mem)
50 | {
51 | woffset = *(int*)(mem);
52 | mem += 4;
53 |
54 | hoffset = *(int*)(mem);
55 | mem += 4;
56 |
57 | return 0;
58 | }
59 |
60 | int Crop::forward(const std::vector& bottom_blobs, std::vector& top_blobs) const
61 | {
62 | const Mat& bottom_blob = bottom_blobs[0];
63 | const Mat& reference_blob = bottom_blobs[1];
64 |
65 | int w = bottom_blob.w;
66 | int h = bottom_blob.h;
67 |
68 | int outw = reference_blob.w;
69 | int outh = reference_blob.h;
70 |
71 | int top = hoffset;
72 | int bottom = h - outh - hoffset;
73 | int left = woffset;
74 | int right = w - outw - woffset;
75 |
76 | Mat& top_blob = top_blobs[0];
77 |
78 | copy_cut_border(bottom_blob, top_blob, top, bottom, left, right);
79 | if (top_blob.empty())
80 | return -100;
81 |
82 | return 0;
83 | }
84 |
85 | } // namespace ncnn
86 |
--------------------------------------------------------------------------------
/src/layer/bnll.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "bnll.h"
16 | #include
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(BNLL)
21 |
22 | BNLL::BNLL()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | int BNLL::forward(const Mat& bottom_blob, Mat& top_blob) const
29 | {
30 | int w = bottom_blob.w;
31 | int h = bottom_blob.h;
32 | int channels = bottom_blob.c;
33 | int size = w * h;
34 |
35 | top_blob.create(w, h, channels);
36 | if (top_blob.empty())
37 | return -100;
38 |
39 | #pragma omp parallel for
40 | for (int q=0; q 0)
48 | outptr[i] = ptr[i] + log(1.f + exp(-ptr[i]));
49 | else
50 | outptr[i] = log(1.f + exp(ptr[i]));
51 | }
52 | }
53 |
54 | return 0;
55 | }
56 |
57 | int BNLL::forward_inplace(Mat& bottom_top_blob) const
58 | {
59 | int w = bottom_top_blob.w;
60 | int h = bottom_top_blob.h;
61 | int channels = bottom_top_blob.c;
62 | int size = w * h;
63 |
64 | #pragma omp parallel for
65 | for (int q=0; q 0)
72 | ptr[i] = ptr[i] + log(1.f + exp(-ptr[i]));
73 | else
74 | ptr[i] = log(1.f + exp(ptr[i]));
75 | }
76 | }
77 |
78 | return 0;
79 | }
80 |
81 | } // namespace ncnn
82 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/cpp/image_util/yuv2rgb.h:
--------------------------------------------------------------------------------
1 | /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | // This is a collection of routines which converts various YUV image formats
17 | // to (A)RGB.
18 |
19 | #ifndef ORG_TENSORFLOW_JNI_IMAGEUTILS_YUV2RGB_H_
20 | #define ORG_TENSORFLOW_JNI_IMAGEUTILS_YUV2RGB_H_
21 |
22 | #include
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | void ConvertYUV420ToARGB8888(const uint8_t* const yData,
29 | const uint8_t* const uData,
30 | const uint8_t* const vData, uint32_t* const output,
31 | const int width, const int height,
32 | const int y_row_stride, const int uv_row_stride,
33 | const int uv_pixel_stride);
34 |
35 | // Converts YUV420 semi-planar data to ARGB 8888 data using the supplied width
36 | // and height. The input and output must already be allocated and non-null.
37 | // For efficiency, no error checking is performed.
38 | void ConvertYUV420SPToARGB8888(const uint8_t* const pY,
39 | const uint8_t* const pUV, uint32_t* const output,
40 | const int width, const int height);
41 |
42 | // The same as above, but downsamples each dimension to half size.
43 | void ConvertYUV420SPToARGB8888HalfSize(const uint8_t* const input,
44 | uint32_t* const output, int width,
45 | int height);
46 |
47 | // Converts YUV420 semi-planar data to RGB 565 data using the supplied width
48 | // and height. The input and output must already be allocated and non-null.
49 | // For efficiency, no error checking is performed.
50 | void ConvertYUV420SPToRGB565(const uint8_t* const input, uint16_t* const output,
51 | const int width, const int height);
52 |
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 |
57 | #endif // ORG_TENSORFLOW_JNI_IMAGEUTILS_YUV2RGB_H_
58 |
--------------------------------------------------------------------------------
/tools/tensorflow/attr_value.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "AttrValueProtos";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | import "tensor.proto";
10 | import "tensor_shape.proto";
11 | import "types.proto";
12 |
13 | // Protocol buffer representing the value for an attr used to configure an Op.
14 | // Comment indicates the corresponding attr type. Only the field matching the
15 | // attr type may be filled.
16 | message AttrValue {
17 | // LINT.IfChange
18 | message ListValue {
19 | repeated bytes s = 2; // "list(string)"
20 | repeated int64 i = 3 [packed = true]; // "list(int)"
21 | repeated float f = 4 [packed = true]; // "list(float)"
22 | repeated bool b = 5 [packed = true]; // "list(bool)"
23 | repeated DataType type = 6 [packed = true]; // "list(type)"
24 | repeated TensorShapeProto shape = 7; // "list(shape)"
25 | repeated TensorProto tensor = 8; // "list(tensor)"
26 | repeated NameAttrList func = 9; // "list(attr)"
27 | }
28 | // LINT.ThenChange(https://www.tensorflow.org/code/tensorflow/c/c_api.cc)
29 |
30 | oneof value {
31 | bytes s = 2; // "string"
32 | int64 i = 3; // "int"
33 | float f = 4; // "float"
34 | bool b = 5; // "bool"
35 | DataType type = 6; // "type"
36 | TensorShapeProto shape = 7; // "shape"
37 | TensorProto tensor = 8; // "tensor"
38 | ListValue list = 1; // any "list(...)"
39 |
40 | // "func" represents a function. func.name is a function's name or
41 | // a primitive op's name. func.attr.first is the name of an attr
42 | // defined for that function. func.attr.second is the value for
43 | // that attr in the instantiation.
44 | NameAttrList func = 10;
45 |
46 | // This is a placeholder only used in nodes defined inside a
47 | // function. It indicates the attr value will be supplied when
48 | // the function is instantiated. For example, let us suppose a
49 | // node "N" in function "FN". "N" has an attr "A" with value
50 | // placeholder = "foo". When FN is instantiated with attr "foo"
51 | // set to "bar", the instantiated node N's attr A will have been
52 | // given the value "bar".
53 | string placeholder = 9;
54 | }
55 | }
56 |
57 | // A list of attr names and their values. The whole list is attached
58 | // with a string name. E.g., MatMul[T=float].
59 | message NameAttrList {
60 | string name = 1;
61 | map attr = 2;
62 | }
63 |
--------------------------------------------------------------------------------
/CNNCache/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/tools/tensorflow/node_def.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "NodeProto";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | import "attr_value.proto";
10 |
11 | message NodeDef {
12 | // The name given to this operator. Used for naming inputs,
13 | // logging, visualization, etc. Unique within a single GraphDef.
14 | // Must match the regexp "[A-Za-z0-9.][A-Za-z0-9_./]*".
15 | string name = 1;
16 |
17 | // The operation name. There may be custom parameters in attrs.
18 | // Op names starting with an underscore are reserved for internal use.
19 | string op = 2;
20 |
21 | // Each input is "node:src_output" with "node" being a string name and
22 | // "src_output" indicating which output tensor to use from "node". If
23 | // "src_output" is 0 the ":0" suffix can be omitted. Regular inputs
24 | // may optionally be followed by control inputs that have the format
25 | // "^node".
26 | repeated string input = 3;
27 |
28 | // A (possibly partial) specification for the device on which this
29 | // node should be placed.
30 | // The expected syntax for this string is as follows:
31 | //
32 | // DEVICE_SPEC ::= PARTIAL_SPEC
33 | //
34 | // PARTIAL_SPEC ::= ("/" CONSTRAINT) *
35 | // CONSTRAINT ::= ("job:" JOB_NAME)
36 | // | ("replica:" [1-9][0-9]*)
37 | // | ("task:" [1-9][0-9]*)
38 | // | ( ("gpu" | "cpu") ":" ([1-9][0-9]* | "*") )
39 | //
40 | // Valid values for this string include:
41 | // * "/job:worker/replica:0/task:1/gpu:3" (full specification)
42 | // * "/job:worker/gpu:3" (partial specification)
43 | // * "" (no specification)
44 | //
45 | // If the constraints do not resolve to a single device (or if this
46 | // field is empty or not present), the runtime will attempt to
47 | // choose a device automatically.
48 | string device = 4;
49 |
50 | // Operation-specific graph-construction-time configuration.
51 | // Note that this should include all attrs defined in the
52 | // corresponding OpDef, including those with a value matching
53 | // the default -- this allows the default to change and makes
54 | // NodeDefs easier to interpret on their own. However, if
55 | // an attr with a default is not specified in this list, the
56 | // default will be used.
57 | // The "names" (keys) must match the regexp "[a-z][a-z0-9_]+" (and
58 | // one of the names from the corresponding OpDef's attr field).
59 | // The values must have a type matching the corresponding OpDef
60 | // attr's type field.
61 | // TODO(josh11b): Add some examples here showing best practices.
62 | map attr = 5;
63 | };
64 |
--------------------------------------------------------------------------------
/CNNCache/app/CMakeFiles/3.9.0/CMakeCCompiler.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_C_COMPILER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc")
2 | set(CMAKE_C_COMPILER_ARG1 "")
3 | set(CMAKE_C_COMPILER_ID "AppleClang")
4 | set(CMAKE_C_COMPILER_VERSION "8.1.0.8020042")
5 | set(CMAKE_C_COMPILER_WRAPPER "")
6 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11")
7 | set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert")
8 | set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes")
9 | set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros")
10 | set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert")
11 |
12 | set(CMAKE_C_PLATFORM_ID "Darwin")
13 | set(CMAKE_C_SIMULATE_ID "")
14 | set(CMAKE_C_SIMULATE_VERSION "")
15 |
16 |
17 | set(CMAKE_AR "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar")
18 | set(CMAKE_C_COMPILER_AR "")
19 | set(CMAKE_RANLIB "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib")
20 | set(CMAKE_C_COMPILER_RANLIB "")
21 | set(CMAKE_LINKER "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld")
22 | set(CMAKE_COMPILER_IS_GNUCC )
23 | set(CMAKE_C_COMPILER_LOADED 1)
24 | set(CMAKE_C_COMPILER_WORKS TRUE)
25 | set(CMAKE_C_ABI_COMPILED TRUE)
26 | set(CMAKE_COMPILER_IS_MINGW )
27 | set(CMAKE_COMPILER_IS_CYGWIN )
28 | if(CMAKE_COMPILER_IS_CYGWIN)
29 | set(CYGWIN 1)
30 | set(UNIX 1)
31 | endif()
32 |
33 | set(CMAKE_C_COMPILER_ENV_VAR "CC")
34 |
35 | if(CMAKE_COMPILER_IS_MINGW)
36 | set(MINGW 1)
37 | endif()
38 | set(CMAKE_C_COMPILER_ID_RUN 1)
39 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m)
40 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
41 | set(CMAKE_C_LINKER_PREFERENCE 10)
42 |
43 | # Save compiler ABI information.
44 | set(CMAKE_C_SIZEOF_DATA_PTR "8")
45 | set(CMAKE_C_COMPILER_ABI "")
46 | set(CMAKE_C_LIBRARY_ARCHITECTURE "")
47 |
48 | if(CMAKE_C_SIZEOF_DATA_PTR)
49 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}")
50 | endif()
51 |
52 | if(CMAKE_C_COMPILER_ABI)
53 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}")
54 | endif()
55 |
56 | if(CMAKE_C_LIBRARY_ARCHITECTURE)
57 | set(CMAKE_LIBRARY_ARCHITECTURE "")
58 | endif()
59 |
60 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "")
61 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX)
62 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}")
63 | endif()
64 |
65 |
66 |
67 |
68 |
69 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
70 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/lib")
71 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks")
72 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/java/edu/pku/sei/cnncache/Models/NCNN.java:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | package edu.pku.sei.cnncache.Models;
16 |
17 | import android.graphics.Bitmap;
18 | import java.util.LinkedHashMap;
19 | import java.util.Map;
20 |
21 | public class NCNN
22 | {
23 | private static final String TAG = "NCNN";
24 | public static Map models = new LinkedHashMap<>();
25 |
26 | public native boolean Init(
27 | String param, String bin, boolean is_param_bin, byte[] words, String input, String output, int log_type);
28 |
29 | public boolean Init(MODEL model, byte[] words, int log_type) {
30 | return Init(model.param_path, model.bin_path, false,
31 | words, model.input_layer, model.output_layer, 0);
32 | }
33 |
34 | public native boolean Release();
35 |
36 | public native String Detect(Bitmap bitmap);
37 |
38 | public native String Classify(Bitmap bitmap, boolean use_cache, boolean update_cache,
39 | int size, int[] x1, int[] y1, int[] x2, int[] y2, int off_x, int off_y);
40 |
41 | public native float[] run(Bitmap bitmap, boolean use_cache, boolean update_cache,
42 | int size, int[] x1, int[] y1, int[] x2, int[] y2, int off_x, int off_y);
43 |
44 | public native boolean ClearCache();
45 |
46 | public native boolean test();
47 |
48 | static {
49 | System.loadLibrary("libncnn");
50 | }
51 |
52 | public NCNN() {
53 | models.put("googlenet", new MODEL(
54 | "data", "prob", 224,
55 | "/sdcard/ncnn/models/googlenet.param",
56 | "/sdcard/ncnn/models/googlenet.bin"));
57 | models.put("alexnet", new MODEL(
58 | "data", "prob", 227,
59 | "/sdcard/ncnn/models/alexnet.param",
60 | "/sdcard/ncnn/models/alexnet.bin"
61 | ));
62 | }
63 |
64 | public class MODEL {
65 | public String input_layer;
66 | public String output_layer;
67 | public int input_size;
68 | public String param_path;
69 | public String bin_path;
70 | MODEL(String arg0, String arg1, int arg2, String arg3, String arg4) {
71 | input_layer = arg0;
72 | output_layer = arg1;
73 | input_size = arg2;
74 | param_path = arg3;
75 | bin_path = arg4;
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/src/layer/threshold.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "threshold.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Threshold)
20 |
21 | Threshold::Threshold()
22 | {
23 | one_blob_only = true;
24 | support_inplace = true;
25 | }
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | int Threshold::load_param(FILE* paramfp)
30 | {
31 | int nscan = fscanf(paramfp, "%f", &threshold);
32 | if (nscan != 1)
33 | {
34 | fprintf(stderr, "Threshold load_param failed %d\n", nscan);
35 | return -1;
36 | }
37 |
38 | return 0;
39 | }
40 | #endif // NCNN_STRING
41 | int Threshold::load_param_bin(FILE* paramfp)
42 | {
43 | fread(&threshold, sizeof(float), 1, paramfp);
44 |
45 | return 0;
46 | }
47 | #endif // NCNN_STDIO
48 |
49 | int Threshold::load_param(const unsigned char*& mem)
50 | {
51 | threshold = *(float*)(mem);
52 | mem += 4;
53 |
54 | return 0;
55 | }
56 |
57 | int Threshold::forward(const Mat& bottom_blob, Mat& top_blob) const
58 | {
59 | int w = bottom_blob.w;
60 | int h = bottom_blob.h;
61 | int channels = bottom_blob.c;
62 | int size = w * h;
63 |
64 | top_blob.create(w, h, channels);
65 | if (top_blob.empty())
66 | return -100;
67 |
68 | #pragma omp parallel for
69 | for (int q=0; q threshold ? 1.f : 0.f;
77 | }
78 | }
79 |
80 | return 0;
81 | }
82 |
83 | int Threshold::forward_inplace(Mat& bottom_top_blob) const
84 | {
85 | int w = bottom_top_blob.w;
86 | int h = bottom_top_blob.h;
87 | int channels = bottom_top_blob.c;
88 | int size = w * h;
89 |
90 | #pragma omp parallel for
91 | for (int q=0; q threshold ? 1.f : 0.f;
98 | }
99 | }
100 |
101 | return 0;
102 | }
103 |
104 | } // namespace ncnn
105 |
--------------------------------------------------------------------------------
/examples/squeezenet.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | #include "net.h"
22 |
23 | static int detect_squeezenet(const cv::Mat& bgr, std::vector& cls_scores)
24 | {
25 | ncnn::Net squeezenet;
26 | squeezenet.load_param("squeezenet_v1.1.param");
27 | squeezenet.load_model("squeezenet_v1.1.bin");
28 |
29 | ncnn::Mat in = ncnn::Mat::from_pixels_resize(bgr.data, ncnn::Mat::PIXEL_BGR, bgr.cols, bgr.rows, 227, 227);
30 |
31 | const float mean_vals[3] = {104.f, 117.f, 123.f};
32 | in.substract_mean_normalize(mean_vals, 0);
33 |
34 | ncnn::Extractor ex = squeezenet.create_extractor();
35 | ex.set_light_mode(true);
36 |
37 | ex.input("data", in);
38 |
39 | ncnn::Mat out;
40 | ex.extract("prob", out);
41 |
42 | cls_scores.resize(out.c);
43 | for (int j=0; j& cls_scores, int topk)
53 | {
54 | // partial sort topk with index
55 | int size = cls_scores.size();
56 | std::vector< std::pair > vec;
57 | vec.resize(size);
58 | for (int i=0; i >());
65 |
66 | // print topk and score
67 | for (int i=0; i cls_scores;
89 | detect_squeezenet(m, cls_scores);
90 |
91 | print_topk(cls_scores, 3);
92 |
93 | return 0;
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/src/layer/argmax.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "argmax.h"
16 | #include
17 | #include
18 |
19 | namespace ncnn {
20 |
21 | DEFINE_LAYER_CREATOR(ArgMax)
22 |
23 | ArgMax::ArgMax()
24 | {
25 | }
26 |
27 | #if NCNN_STDIO
28 | #if NCNN_STRING
29 | int ArgMax::load_param(FILE* paramfp)
30 | {
31 | int nscan = fscanf(paramfp, "%d %d", &out_max_val, &topk);
32 | if (nscan != 2)
33 | {
34 | fprintf(stderr, "ArgMax load_param failed %d\n", nscan);
35 | return -1;
36 | }
37 |
38 | return 0;
39 | }
40 | #endif // NCNN_STRING
41 | int ArgMax::load_param_bin(FILE* paramfp)
42 | {
43 | fread(&out_max_val, sizeof(int), 1, paramfp);
44 |
45 | fread(&topk, sizeof(int), 1, paramfp);
46 |
47 | return 0;
48 | }
49 | #endif // NCNN_STDIO
50 |
51 | int ArgMax::load_param(const unsigned char*& mem)
52 | {
53 | out_max_val = *(int*)(mem);
54 | mem += 4;
55 |
56 | topk = *(int*)(mem);
57 | mem += 4;
58 |
59 | return 0;
60 | }
61 |
62 | int ArgMax::forward(const Mat& bottom_blob, Mat& top_blob) const
63 | {
64 | int size = bottom_blob.total();
65 |
66 | if (out_max_val)
67 | top_blob.create(topk, 2);
68 | else
69 | top_blob.create(topk, 1);
70 | if (top_blob.empty())
71 | return -100;
72 |
73 | const float* ptr = bottom_blob;
74 |
75 | // partial sort topk with index
76 | // optional value
77 | std::vector< std::pair > vec;
78 | vec.resize(size);
79 | for (int i=0; i >());
86 |
87 | float* outptr = top_blob;
88 | if (out_max_val)
89 | {
90 | float* valptr = outptr + topk;
91 | for (int i=0; i
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(ELU)
21 |
22 | ELU::ELU()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | int ELU::load_param(FILE* paramfp)
31 | {
32 | int nscan = fscanf(paramfp, "%f", &alpha);
33 | if (nscan != 1)
34 | {
35 | fprintf(stderr, "ELU load_param failed %d\n", nscan);
36 | return -1;
37 | }
38 |
39 | return 0;
40 | }
41 | #endif // NCNN_STRING
42 | int ELU::load_param_bin(FILE* paramfp)
43 | {
44 | fread(&alpha, sizeof(float), 1, paramfp);
45 |
46 | return 0;
47 | }
48 | #endif // NCNN_STDIO
49 |
50 | int ELU::load_param(const unsigned char*& mem)
51 | {
52 | alpha = *(float*)(mem);
53 | mem += 4;
54 |
55 | return 0;
56 | }
57 |
58 | int ELU::forward(const Mat& bottom_blob, Mat& top_blob) const
59 | {
60 | int w = bottom_blob.w;
61 | int h = bottom_blob.h;
62 | int channels = bottom_blob.c;
63 | int size = w * h;
64 |
65 | top_blob.create(w, h, channels);
66 | if (top_blob.empty())
67 | return -100;
68 |
69 | #pragma omp parallel for
70 | for (int q=0; q& bottom_blobs, std::vector& top_blobs) const
26 | {
27 | int w = bottom_blobs[0].w;
28 | int h = bottom_blobs[0].h;
29 |
30 | // total channels
31 | int top_channels = 0;
32 | for (size_t b=0; b& bottom_mrects, std::vector& top_mrects) const
66 | {
67 | top_mrects.resize(1);
68 | MRect& mr = top_mrects[0];
69 | mr.set_offset(bottom_mrects[0].x_offset, bottom_mrects[0].y_offset);
70 | for (size_t i = 0, max = bottom_mrects[0].size(); i < max; i ++) {
71 | int x1 = bottom_mrects[0].changed_vecs[i].x1;
72 | int y1 = bottom_mrects[0].changed_vecs[i].y1;
73 | int x2 = bottom_mrects[0].changed_vecs[i].x2;
74 | int y2 = bottom_mrects[0].changed_vecs[i].y2;
75 | for (size_t j = 1, maxx = bottom_mrects.size(); j < maxx; j ++) {
76 | const struct rect temp = bottom_mrects[j].changed_vecs[i];
77 | if (temp.x1 <= x1 && temp.y1 <= y1) {
78 | x1 = temp.x1;
79 | y1 = temp.y1;
80 | }
81 | if (temp.x2 >= x2 && temp.y2 >= y2) {
82 | x2 = temp.x2;
83 | y2 = temp.y2;
84 | }
85 | }
86 | mr.add_rect(x1, y1, x2, y2);
87 | // LOGI("YYYYY %d %d %d %d\n", x1, y1, x2, y2);
88 | }
89 | return 0;
90 | }
91 | #endif
92 |
93 | } // namespace ncnn
94 |
--------------------------------------------------------------------------------
/CNNCache/app/src/main/res/layout/camera_connection_fragment.xml:
--------------------------------------------------------------------------------
1 |
16 |
19 |
20 |
27 |
33 |
34 |
39 |
40 |
46 |
47 |
53 |
54 |
55 |
56 |
63 |
64 |
69 |
70 |
76 |
77 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/src/layer/power.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "power.h"
16 | #include
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(Power)
21 |
22 | Power::Power()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | #if NCNN_STDIO
29 | #if NCNN_STRING
30 | int Power::load_param(FILE* paramfp)
31 | {
32 | int nscan = fscanf(paramfp, "%f %f %f", &power, &scale, &shift);
33 | if (nscan != 3)
34 | {
35 | fprintf(stderr, "Power load_param failed %d\n", nscan);
36 | return -1;
37 | }
38 |
39 | return 0;
40 | }
41 | #endif // NCNN_STRING
42 | int Power::load_param_bin(FILE* paramfp)
43 | {
44 | fread(&power, sizeof(float), 1, paramfp);
45 |
46 | fread(&scale, sizeof(float), 1, paramfp);
47 |
48 | fread(&shift, sizeof(float), 1, paramfp);
49 |
50 | return 0;
51 | }
52 | #endif // NCNN_STDIO
53 |
54 | int Power::load_param(const unsigned char*& mem)
55 | {
56 | power = *(float*)(mem);
57 | mem += 4;
58 |
59 | scale = *(float*)(mem);
60 | mem += 4;
61 |
62 | shift = *(float*)(mem);
63 | mem += 4;
64 |
65 | return 0;
66 | }
67 |
68 | int Power::forward(const Mat& bottom_blob, Mat& top_blob) const
69 | {
70 | int w = bottom_blob.w;
71 | int h = bottom_blob.h;
72 | int channels = bottom_blob.c;
73 | int size = w * h;
74 |
75 | top_blob.create(w, h, channels);
76 | if (top_blob.empty())
77 | return -100;
78 |
79 | #pragma omp parallel for
80 | for (int q=0; q
18 | #endif // __ARM_NEON
19 |
20 | namespace ncnn {
21 |
22 | DEFINE_LAYER_CREATOR(Slice_arm)
23 |
24 | int Slice_arm::forward(const std::vector& bottom_blobs, std::vector& top_blobs) const
25 | {
26 | const Mat& bottom_blob = bottom_blobs[0];
27 | int w = bottom_blob.w;
28 | int h = bottom_blob.h;
29 | int channels = bottom_blob.c;
30 |
31 | int q = 0;
32 | const int* slices_ptr = (const int*)slices.data;
33 | for (size_t i=0; i> 3;
53 | int remain = size - (nn << 3);
54 | #else
55 | int remain = size;
56 | #endif // __ARM_NEON
57 |
58 | #if __ARM_NEON
59 | #if __aarch64__
60 | for (; nn>0; nn--)
61 | {
62 | float32x4_t _p = vld1q_f32(ptr);
63 | float32x4_t _p2 = vld1q_f32(ptr+4);
64 | vst1q_f32(outptr, _p);
65 | vst1q_f32(outptr+4, _p2);
66 |
67 | ptr += 8;
68 | outptr += 8;
69 | }
70 | #else
71 | if (nn > 0)
72 | {
73 | asm volatile(
74 | "0: \n"
75 | "pld [%1, #256] \n"
76 | "vld1.f32 {d0-d3}, [%1 :128]! \n"
77 | "subs %0, #1 \n"
78 | "vst1.f32 {d0-d3}, [%2 :128]! \n"
79 | "bne 0b \n"
80 | : "=r"(nn), // %0
81 | "=r"(ptr), // %1
82 | "=r"(outptr) // %2
83 | : "0"(nn),
84 | "1"(ptr),
85 | "2"(outptr)
86 | : "cc", "memory", "q0"
87 | );
88 | }
89 | #endif // __aarch64__
90 | #endif // __ARM_NEON
91 | for (; remain>0; remain--)
92 | {
93 | *outptr++ = *ptr++;
94 | }
95 |
96 | q += slice;
97 | }
98 |
99 | return 0;
100 | }
101 |
102 | } // namespace ncnn
103 |
--------------------------------------------------------------------------------
/src/opencv.cpp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 | //
5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // https://opensource.org/licenses/BSD-3-Clause
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #include "opencv.h"
16 |
17 | #if NCNN_OPENCV
18 |
19 | #include
20 |
21 | namespace cv {
22 |
23 | Mat imread(const std::string& path, int flags)
24 | {
25 | (void)flags;
26 |
27 | // read pgm/ppm
28 | FILE* fp = fopen(path.c_str(), "rb");
29 | if (!fp)
30 | return Mat();
31 |
32 | Mat m;
33 |
34 | char magic[3];
35 | int w, h;
36 | int nscan = fscanf(fp, "%2s\n%d %d\n255\n", magic, &w, &h);
37 | if (nscan == 3 && magic[0] == 'P' && (magic[1] == '5' || magic[1] == '6'))
38 | {
39 | if (magic[1] == '5')
40 | {
41 | m.create(h, w, CV_8UC1);
42 | }
43 | else if (magic[1] == '6')
44 | {
45 | m.create(h, w, CV_8UC3);
46 | }
47 | if (m.empty())
48 | {
49 | fclose(fp);
50 | return Mat();
51 | }
52 |
53 | fread(m.data, 1, m.total(), fp);
54 | }
55 |
56 | fclose(fp);
57 |
58 | return m;
59 | }
60 |
61 | void imwrite(const std::string& path, const Mat& m)
62 | {
63 | // write pgm/ppm
64 | FILE* fp = fopen(path.c_str(), "wb");
65 | if (!fp)
66 | return;
67 |
68 | if (m.channels() == 1)
69 | {
70 | fprintf(fp, "P5\n%d %d\n255\n", m.cols, m.rows);
71 | }
72 | else if (m.channels() == 3)
73 | {
74 | fprintf(fp, "P6\n%d %d\n255\n", m.cols, m.rows);
75 | }
76 |
77 | fwrite(m.data, 1, m.total(), fp);
78 |
79 | fclose(fp);
80 | }
81 |
82 | void resize(const Mat& src, Mat& dst, const Size& size, float sw, float sh, int flags)
83 | {
84 | int srcw = src.cols;
85 | int srch = src.rows;
86 |
87 | int w = size.width;
88 | int h = size.height;
89 |
90 | if (w == 0 || h == 0)
91 | {
92 | w = srcw * sw;
93 | h = srch * sh;
94 | }
95 |
96 | if (w == 0 || h == 0)
97 | return;
98 |
99 | if (w == srcw && h == srch)
100 | {
101 | dst = src.clone();
102 | return;
103 | }
104 |
105 | cv::Mat tmp(h, w, src.c);
106 | if (tmp.empty())
107 | return;
108 |
109 | if (src.c == 1)
110 | ncnn::resize_bilinear_c1(src.data, srcw, srch, tmp.data, w, h);
111 | else if (src.c == 3)
112 | ncnn::resize_bilinear_c3(src.data, srcw, srch, tmp.data, w, h);
113 | else if (src.c == 4)
114 | ncnn::resize_bilinear_c4(src.data, srcw, srch, tmp.data, w, h);
115 |
116 | dst = tmp;
117 | }
118 |
119 | } // namespace cv
120 |
121 | #endif // NCNN_OPENCV
122 |
--------------------------------------------------------------------------------