feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
1374
3rdparty/ncnn/python/src/main.cpp
vendored
Normal file
1374
3rdparty/ncnn/python/src/main.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
137
3rdparty/ncnn/python/src/pybind11_allocator.h
vendored
Normal file
137
3rdparty/ncnn/python/src/pybind11_allocator.h
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
/* Tencent is pleased to support the open source community by making ncnn available.
|
||||
*
|
||||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND11_NCNN_ALLOCATOR_H
|
||||
#define PYBIND11_NCNN_ALLOCATOR_H
|
||||
|
||||
#include <allocator.h>
|
||||
|
||||
template<class Base = ncnn::Allocator>
|
||||
class PyAllocator : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base; // Inherit constructors
|
||||
void* fastMalloc(size_t size) override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(void*, Base, fastMalloc, size);
|
||||
}
|
||||
void fastFree(void* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(void, Base, fastFree, ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Other>
|
||||
class PyAllocatorOther : public PyAllocator<Other>
|
||||
{
|
||||
public:
|
||||
using PyAllocator<Other>::PyAllocator;
|
||||
void* fastMalloc(size_t size) override
|
||||
{
|
||||
PYBIND11_OVERLOAD(void*, Other, fastMalloc, size);
|
||||
}
|
||||
void fastFree(void* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD(void, Other, fastFree, ptr);
|
||||
}
|
||||
};
|
||||
|
||||
#if NCNN_VULKAN
|
||||
template<class Base = ncnn::VkAllocator>
|
||||
class PyVkAllocator : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base; // Inherit constructors
|
||||
void clear() override
|
||||
{
|
||||
PYBIND11_OVERLOAD(void, Base, clear, );
|
||||
}
|
||||
ncnn::VkBufferMemory* fastMalloc(size_t size) override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(ncnn::VkBufferMemory*, Base, fastMalloc, size);
|
||||
}
|
||||
void fastFree(ncnn::VkBufferMemory* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(void, Base, fastFree, ptr);
|
||||
}
|
||||
int flush(ncnn::VkBufferMemory* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD(int, Base, flush, ptr);
|
||||
}
|
||||
int invalidate(ncnn::VkBufferMemory* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD(int, Base, invalidate, ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Other>
|
||||
class PyVkAllocatorOther : public PyVkAllocator<Other>
|
||||
{
|
||||
public:
|
||||
using PyVkAllocator<Other>::PyVkAllocator;
|
||||
void clear() override
|
||||
{
|
||||
PYBIND11_OVERLOAD(void, Other, clear, );
|
||||
}
|
||||
ncnn::VkBufferMemory* fastMalloc(size_t size) override
|
||||
{
|
||||
PYBIND11_OVERLOAD(ncnn::VkBufferMemory*, Other, fastMalloc, size);
|
||||
}
|
||||
void fastFree(ncnn::VkBufferMemory* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD(void, Other, fastFree, ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Base = ncnn::VkBlobAllocator>
|
||||
class PyVkBlobAllocator : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base; // Inherit constructors
|
||||
void clear() override
|
||||
{
|
||||
PYBIND11_OVERLOAD(void, Base, clear, );
|
||||
}
|
||||
ncnn::VkImageMemory* fastMalloc(int width, int height,
|
||||
VkFormat format) override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(ncnn::VkImageMemory*, Base, fastMalloc, width,
|
||||
height, format);
|
||||
}
|
||||
void fastFree(ncnn::VkImageMemory* ptr) override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(void, Base, fastFree, ptr);
|
||||
}
|
||||
};
|
||||
|
||||
//template<class Other>
|
||||
//class PyVkImageAllocatorOther : public PyVkImageAllocator<Other>
|
||||
//{
|
||||
//public:
|
||||
// using PyVkImageAllocator<Other>::PyVkImageAllocator;
|
||||
// ncnn::VkImageMemory* fastMalloc(int width, int height,
|
||||
// VkFormat format) override
|
||||
// {
|
||||
// PYBIND11_OVERLOAD(ncnn::VkImageMemory*, Other, fastMalloc, width, height,
|
||||
// format);
|
||||
// }
|
||||
// void fastFree(ncnn::VkImageMemory* ptr) override
|
||||
// {
|
||||
// PYBIND11_OVERLOAD(void, Other, fastFree, ptr);
|
||||
// }
|
||||
//};
|
||||
#endif // NCNN_VULKAN
|
||||
|
||||
#endif
|
52
3rdparty/ncnn/python/src/pybind11_bind.h
vendored
Normal file
52
3rdparty/ncnn/python/src/pybind11_bind.h
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/* Tencent is pleased to support the open source community by making ncnn available.
|
||||
*
|
||||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND11_NCNN_BIND_H
|
||||
#define PYBIND11_NCNN_BIND_H
|
||||
|
||||
#include <pybind11/functional.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// virtual function pass by reference by https://github.com/pybind/pybind11/issues/2033
|
||||
#define PYBIND11_OVERRIDE_REFERENCE_IMPL(ret_type, cname, name, ...) \
|
||||
do \
|
||||
{ \
|
||||
pybind11::gil_scoped_acquire gil; \
|
||||
pybind11::function override = pybind11::get_override(static_cast<const cname*>(this), name); \
|
||||
if (override) \
|
||||
{ \
|
||||
auto o = override.operator()<pybind11::return_value_policy::reference>(__VA_ARGS__); \
|
||||
if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value) \
|
||||
{ \
|
||||
static pybind11::detail::override_caster_t<ret_type> caster; \
|
||||
return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
|
||||
} \
|
||||
else \
|
||||
return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define PYBIND11_OVERRIDE_REFERENCE_NAME(ret_type, cname, name, fn, ...) \
|
||||
do \
|
||||
{ \
|
||||
PYBIND11_OVERRIDE_REFERENCE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
|
||||
return cname::fn(__VA_ARGS__); \
|
||||
} while (false)
|
||||
|
||||
#define PYBIND11_OVERRIDE_REFERENCE(ret_type, cname, fn, ...) \
|
||||
PYBIND11_OVERRIDE_REFERENCE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
71
3rdparty/ncnn/python/src/pybind11_datareader.h
vendored
Normal file
71
3rdparty/ncnn/python/src/pybind11_datareader.h
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
/* Tencent is pleased to support the open source community by making ncnn available.
|
||||
*
|
||||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND11_NCNN_DATAREADER_H
|
||||
#define PYBIND11_NCNN_DATAREADER_H
|
||||
|
||||
#include <datareader.h>
|
||||
|
||||
class DataReaderFromEmpty : public ncnn::DataReader
|
||||
{
|
||||
public:
|
||||
#if NCNN_STRING
|
||||
virtual int scan(const char* format, void* p) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif // NCNN_STRING
|
||||
virtual size_t read(void* buf, size_t size) const
|
||||
{
|
||||
memset(buf, 0, size);
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Base = ncnn::DataReader>
|
||||
class PyDataReader : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base; // Inherit constructors
|
||||
#if NCNN_STRING
|
||||
int scan(const char* format, void* p) const override
|
||||
{
|
||||
PYBIND11_OVERLOAD(int, Base, scan, format, p);
|
||||
}
|
||||
#endif // NCNN_STRING
|
||||
size_t read(void* buf, size_t size) const override
|
||||
{
|
||||
PYBIND11_OVERLOAD(size_t, Base, read, buf, size);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Other>
|
||||
class PyDataReaderOther : public PyDataReader<Other>
|
||||
{
|
||||
public:
|
||||
using PyDataReader<Other>::PyDataReader;
|
||||
#if NCNN_STRING
|
||||
int scan(const char* format, void* p) const override
|
||||
{
|
||||
PYBIND11_OVERLOAD(int, Other, scan, format, p);
|
||||
}
|
||||
#endif // NCNN_STRING
|
||||
size_t read(void* buf, size_t size) const override
|
||||
{
|
||||
PYBIND11_OVERLOAD(size_t, Other, read, buf, size);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
161
3rdparty/ncnn/python/src/pybind11_layer.h
vendored
Normal file
161
3rdparty/ncnn/python/src/pybind11_layer.h
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
/* Tencent is pleased to support the open source community by making ncnn available.
|
||||
*
|
||||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND11_NCNN_LAYER_H
|
||||
#define PYBIND11_NCNN_LAYER_H
|
||||
|
||||
#include <layer.h>
|
||||
#include "pybind11_bind.h"
|
||||
|
||||
class PyLayer : public ncnn::Layer
|
||||
{
|
||||
public:
|
||||
virtual int load_param(const ncnn::ParamDict& pd)
|
||||
{
|
||||
PYBIND11_OVERRIDE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
load_param,
|
||||
pd);
|
||||
}
|
||||
|
||||
virtual int load_model(const ncnn::ModelBin& mb)
|
||||
{
|
||||
PYBIND11_OVERRIDE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
load_model,
|
||||
mb);
|
||||
}
|
||||
|
||||
virtual int create_pipeline(const ncnn::Option& opt)
|
||||
{
|
||||
PYBIND11_OVERRIDE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
create_pipeline,
|
||||
opt);
|
||||
}
|
||||
|
||||
virtual int destroy_pipeline(const ncnn::Option& opt)
|
||||
{
|
||||
PYBIND11_OVERRIDE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
destroy_pipeline,
|
||||
opt);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int forward(const std::vector<ncnn::Mat>& bottom_blobs, std::vector<ncnn::Mat>& top_blobs, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward,
|
||||
bottom_blobs,
|
||||
top_blobs,
|
||||
opt);
|
||||
}
|
||||
virtual int forward(const ncnn::Mat& bottom_blob, ncnn::Mat& top_blob, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward,
|
||||
bottom_blob,
|
||||
top_blob,
|
||||
opt);
|
||||
}
|
||||
|
||||
virtual int forward_inplace(std::vector<ncnn::Mat>& bottom_top_blobs, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward_inplace,
|
||||
bottom_top_blobs,
|
||||
opt);
|
||||
}
|
||||
virtual int forward_inplace(ncnn::Mat& bottom_top_blob, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward_inplace,
|
||||
bottom_top_blob,
|
||||
opt);
|
||||
}
|
||||
|
||||
#if NCNN_VULKAN
|
||||
public:
|
||||
virtual int upload_model(ncnn::VkTransfer& cmd, const ncnn::Option& opt)
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
upload_model,
|
||||
cmd,
|
||||
opt);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual int forward(const std::vector<ncnn::VkMat>& bottom_blobs, std::vector<ncnn::VkMat>& top_blobs, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward,
|
||||
bottom_blobs,
|
||||
top_blobs,
|
||||
cmd,
|
||||
opt);
|
||||
}
|
||||
virtual int forward(const ncnn::VkMat& bottom_blob, ncnn::VkMat& top_blob, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward,
|
||||
bottom_blob,
|
||||
top_blob,
|
||||
cmd,
|
||||
opt);
|
||||
}
|
||||
|
||||
virtual int forward_inplace(std::vector<ncnn::VkMat>& bottom_top_blobs, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward_inplace,
|
||||
bottom_top_blobs,
|
||||
cmd,
|
||||
opt);
|
||||
}
|
||||
virtual int forward_inplace(ncnn::VkMat& bottom_top_blob, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
|
||||
{
|
||||
PYBIND11_OVERRIDE_REFERENCE(
|
||||
int,
|
||||
ncnn::Layer,
|
||||
forward_inplace,
|
||||
bottom_top_blob,
|
||||
cmd,
|
||||
opt);
|
||||
}
|
||||
#endif // NCNN_VULKAN
|
||||
};
|
||||
|
||||
#endif
|
44
3rdparty/ncnn/python/src/pybind11_mat.h
vendored
Normal file
44
3rdparty/ncnn/python/src/pybind11_mat.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* Tencent is pleased to support the open source community by making ncnn available.
|
||||
*
|
||||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND11_NCNN_MAT_H
|
||||
#define PYBIND11_NCNN_MAT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
#include <mat.h>
|
||||
|
||||
std::string get_mat_format(const ncnn::Mat& m)
|
||||
{
|
||||
std::string format;
|
||||
if (m.elemsize == 4)
|
||||
{
|
||||
format = pybind11::format_descriptor<float>::format();
|
||||
}
|
||||
if (m.elemsize == 2)
|
||||
{
|
||||
// see https://docs.python.org/3/library/struct.html#format-characters
|
||||
format = "e";
|
||||
}
|
||||
if (m.elemsize == 1)
|
||||
{
|
||||
format = pybind11::format_descriptor<int8_t>::format();
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
#endif
|
49
3rdparty/ncnn/python/src/pybind11_modelbin.h
vendored
Normal file
49
3rdparty/ncnn/python/src/pybind11_modelbin.h
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/* Tencent is pleased to support the open source community by making ncnn available.
|
||||
*
|
||||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef PYBIND11_NCNN_MODELBIN_H
|
||||
#define PYBIND11_NCNN_MODELBIN_H
|
||||
|
||||
#include <modelbin.h>
|
||||
|
||||
template<class Base = ncnn::ModelBin>
|
||||
class PyModelBin : public Base
|
||||
{
|
||||
public:
|
||||
using Base::Base; // Inherit constructors
|
||||
ncnn::Mat load(int w, int type) const override
|
||||
{
|
||||
PYBIND11_OVERLOAD_PURE(ncnn::Mat, Base, load, w, type);
|
||||
}
|
||||
//ncnn::Mat load(int w, int h, int type) const override {
|
||||
// PYBIND11_OVERLOAD(ncnn::Mat, Base, load, w, h, type);
|
||||
//}
|
||||
//ncnn::Mat load(int w, int h, int c, int type) const override {
|
||||
// PYBIND11_OVERLOAD(ncnn::Mat, Base, load, w, h, c, type);
|
||||
//}
|
||||
};
|
||||
|
||||
template<class Other>
|
||||
class PyModelBinOther : public PyModelBin<Other>
|
||||
{
|
||||
public:
|
||||
using PyModelBin<Other>::PyModelBin;
|
||||
ncnn::Mat load(int w, int type) const override
|
||||
{
|
||||
PYBIND11_OVERLOAD(ncnn::Mat, Other, load, w, type);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user