Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 131 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,132 @@

cmake_minimum_required(VERSION 3.0)
project(c-net C)

add_definitions(-Wall -Wno-unused-function -Ofast)
set(CMAKE_C_STANDARD 99)

if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory")
endif()
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE)
endif()

add_subdirectory(c-utils)
add_subdirectory(c-benchmark)
add_subdirectory(c-tester)
add_subdirectory(c-tensor)
add_subdirectory(c-image)
add_subdirectory(c-network)
add_subdirectory(c-netend)
option(ENABLE_STB_IMAGE "enable stb image" OFF)
option(ENABLE_ESP32 "enable esp32 build" ON)
option(ENABLE_POSIX_PORTS "enable posix ports supported" OFF)
option(ENABLE_DEBUG_MEMORY "enable debug memory allocation" ON)

macro(cnet_add_operation class file)
# WITH_LAYER_xxx option
if(${ARGC} EQUAL 3)
option(WITH_LAYER_${class} "build with layer ${class}" ${ARGV2})
else()
option(WITH_LAYER_${class} "build with layer ${class}" ON)
endif()

message(STATUS "WITH_LAYER_${class} = ${WITH_LAYER_${class}}")
if(WITH_LAYER_${class})
list(APPEND OPERATION_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/c-network/src/operation/${file}.c")
endif()

# generate operation_declaration and operation_registry file
if(WITH_LAYER_${class})
set(operation_names "${operation_names}\t\"${class}\",\n")
set(operation_creators "${operation_creators}/// Creator for ${class}\nDEFINE_OPERATION_CREATOR(${class});\n\n")
set(operation_creator "${operation_creator}\t${class}_operation_creator, // ${class}\n")
else()
set(operation_names "${operation_names}\t\"\",\n")
set(operation_creator "${operation_creator}\t0/*${class}_operation_creator*/, // ${class}\n")
endif()

endmacro()

set(UTILS_SRCS
c-utils/src/allocator.c
c-utils/src/container_linked_list.c
c-utils/src/container_vector.c
c-utils/src/threadpool-pthreads.c
c-utils/src/option.c
c-utils/src/ncx-pool/ncx_slab.c
c-utils/src/memory_cached.c
)

set(TESTER_SRCS
c-tester/src/tester.c
c-tester/src/unity.c
)

set(BENCH_MARK_SRCS
c-benchmark/src/benchmark.c
)

set(TENSOR_SRCS
c-tensor/src/tensor.c
c-tensor/src/tensor_softmax.c
c-tensor/src/tensor_padding.c
c-tensor/src/tensor_cut_border.c
c-tensor/src/tensor_resize_bilinear.c
c-tensor/src/tensor_resize_bicubic.c
)

cnet_add_operation(convolution convolution ON)
cnet_add_operation(pooling pooling ON)
cnet_add_operation(padding padding ON)
cnet_add_operation(crop crop ON)
cnet_add_operation(inner_product inner_product ON)
cnet_add_operation(activation activation ON)
cnet_add_operation(batch_norm batch_norm ON)
cnet_add_operation(slice slice ON)
cnet_add_operation(concat concat ON)
cnet_add_operation(reshape reshape ON)
cnet_add_operation(sigmoid sigmoid ON)
cnet_add_operation(softmax softmax ON)
cnet_add_operation(permute permute ON)
cnet_add_operation(unary unary ON)
cnet_add_operation(binary binary ON)
cnet_add_operation(upsample upsample ON)
cnet_add_operation(prelu prelu ON)
cnet_add_operation(memory_data memory_data ON)
cnet_add_operation(shuffle_channel shuffle_channel ON)

# configure_file(c-network/src/operation_registry.c.in
# ${CMAKE_CURRENT_SOURCE_DIR}/c-network/src/operation_registry.c)
set(NETWORK_SRCS
c-network/src/operation.c
c-network/src/network.c
c-network/src/operation_benchmark.c
c-network/src/quantize16.c
c-network/src/operation_registry.c
${OPERATION_SRCS}
)

set(NETEND_SRCS
c-netend/src/detection/object_box.c
c-netend/src/detection/mtcnn.c
c-netend/src/detection/retina_face.c
c-netend/src/detection/affine_matrix.c
c-netend/src/detection/yolov2.c
c-netend/src/detection/yolov3.c
c-netend/src/face/face_info.c
c-netend/src/face/arc_face.c
c-netend/src/face/mtcnn_face_detector.c
c-netend/src/lpr/plate_info.c
c-netend/src/lpr/lpr_recognizer.c
c-netend/src/lpr/lpc_recoginizer.c
c-netend/src/lpr/mtcnn_plate_detector.c
)

set(IMAGE_SRCS
c-image/src/imgproc.c
c-image/src/tensor_pixel.c
)

set(COMPONENT_SRCS
${UTILS_SRCS}
${TESTER_SRCS}
${BENCH_MARK_SRCS}
${TENSOR_SRCS}
${NETWORK_SRCS}
${NETEND_SRCS}
${IMAGE_SRCS}
)

register_component()

include_directories(c-utils/include)
include_directories(c-tester/include)
include_directories(c-benchmark/include)
include_directories(c-tensor/include)
include_directories(c-network/include)
include_directories(c-netend/include)
include_directories(c-image/include)
add_definitions(-DESP32)
add_definitions(-Wall -Wno-unused-function -Ofast)
7 changes: 7 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


config COMPONENT_CNET_ENABLE
bool "Enbale cnet component"
default y
select COMPONENT_KENDRYTE_SDK_ENABLE
select COMPONENT_POSIX_ENABLE
4 changes: 2 additions & 2 deletions c-netend/src/detection/affine_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void get_affine_matrix_from_5p(float *src_5pts, const float *dst_5pts, float *M)
_sqloss += ((pts0[0] + pts1[i] - dst[i]) * (pts0[0] + pts1[i] - dst[i])
+ (pts0[1] + pts1[i + 5] - dst[i + 5]) * (pts0[1] + pts1[i + 5] - dst[i + 5]));
}
if (abs(_sqloss - sqloss) < 1e-2) {
if (fabs(_sqloss - sqloss) < 1e-2) {
break;
}
sqloss = _sqloss;
Expand Down Expand Up @@ -241,7 +241,7 @@ int guass_jordan(float m[3][5], float eps) {
for (int y = 0; y < h; y++) {
int maxrow = y;
for (int y2 = y + 1; y2 < h; y2++) {
if (abs(m[y2][y]) > abs(m[maxrow][y])) {
if (fabs(m[y2][y]) > fabs(m[maxrow][y])) {
maxrow = y2;
}
}
Expand Down
2 changes: 2 additions & 0 deletions c-netend/src/detection/object_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "detection/object_box.h"
#include "tensor_pixel.h"

#include <stdio.h>

object_box_t object_box_create_default() {
object_box_t box;
memset(&box, 0, sizeof(box));
Expand Down
1 change: 1 addition & 0 deletions c-network/include/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define CNET_LAYER_H

#include "operation_config.h"
#include <stdio.h>

/// Blob container
typedef struct blob_container {
Expand Down
2 changes: 1 addition & 1 deletion c-network/src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ FUNCTION_IRAM static int session_forward_operation(

if (opt->light_mode) {

if(*bottom_blobs.data[i].data.refcount == 2){
if(NULL != bottom_blobs.data[i].data.refcount && *bottom_blobs.data[i].data.refcount == 2){
/// delete after taken in light mode
tensor_release(&context->blob_data[bottom_blob_index].data);
} else {
Expand Down
2 changes: 2 additions & 0 deletions c-network/src/operation/convolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "operation_config.h"
#include "quantize16.h"

#include <stdio.h>

typedef struct conv_int16_context {
tensor_t* bottom;
tensor_t* top;
Expand Down
3 changes: 2 additions & 1 deletion c-tensor/src/tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <allocator.h>
#include "tensor.h"
#include "container_vector.h"
#include <stdio.h>

/**
* vector impl for tensor_t
Expand Down Expand Up @@ -114,7 +115,7 @@ void tensor_print_int32(tensor_t *tensor){
int32_t *data = (int32_t*) m.data;
for(int h = 0; h < m.d1; h++){
for(int w = 0; w < m.d0; w ++){
printf("%d,", data[h*m.d0 + w]);
printf("%ld,", data[h*m.d0 + w]);
}
printf("\n");
}
Expand Down
1 change: 1 addition & 0 deletions c-tensor/src/tensor_padding.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,5 @@ tensor_t tensor_padding(
padding_channels_context_t context = {src, &dst, top, left, type, v, elem_size};
PARALLELIZE_1D(padding_channels_thread, context, channels);

return dst;
}
Loading