Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SORACE
Ncnn
提交
00b0094b
N
Ncnn
项目概览
SORACE
/
Ncnn
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Ncnn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
00b0094b
编写于
5月 20, 2021
作者:
N
nihuini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
copy-pasta makes msvc happy
上级
9a12597d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
418 addition
and
11 deletion
+418
-11
src/platform.h.in
src/platform.h.in
+0
-6
tools/mlir/ncnn_dialect.h
tools/mlir/ncnn_dialect.h
+1
-1
tools/mlir/ncnn_rewriter.cpp
tools/mlir/ncnn_rewriter.cpp
+1
-1
tools/quantize/CMakeLists.txt
tools/quantize/CMakeLists.txt
+2
-3
tools/quantize/imreadwrite.cpp
tools/quantize/imreadwrite.cpp
+212
-0
tools/quantize/imreadwrite.h
tools/quantize/imreadwrite.h
+200
-0
tools/quantize/ncnn2table.cpp
tools/quantize/ncnn2table.cpp
+2
-0
未找到文件。
src/platform.h.in
浏览文件 @
00b0094b
...
@@ -17,15 +17,9 @@
...
@@ -17,15 +17,9 @@
#cmakedefine01 NCNN_STDIO
#cmakedefine01 NCNN_STDIO
#cmakedefine01 NCNN_STRING
#cmakedefine01 NCNN_STRING
#ifndef NCNN_SIMPLEOCV
#cmakedefine01 NCNN_SIMPLEOCV
#cmakedefine01 NCNN_SIMPLEOCV
#endif // NCNN_SIMPLEOCV
#ifndef NCNN_SIMPLEOMP
#cmakedefine01 NCNN_SIMPLEOMP
#cmakedefine01 NCNN_SIMPLEOMP
#endif // NCNN_SIMPLEOMP
#ifndef NCNN_SIMPLESTL
#cmakedefine01 NCNN_SIMPLESTL
#cmakedefine01 NCNN_SIMPLESTL
#endif // NCNN_SIMPLESTL
#cmakedefine01 NCNN_THREADS
#cmakedefine01 NCNN_THREADS
#cmakedefine01 NCNN_BENCHMARK
#cmakedefine01 NCNN_BENCHMARK
#cmakedefine01 NCNN_PLATFORM_API
#cmakedefine01 NCNN_PLATFORM_API
...
...
tools/mlir/ncnn_dialect.h
浏览文件 @
00b0094b
...
@@ -35,7 +35,7 @@ public:
...
@@ -35,7 +35,7 @@ public:
}
}
};
};
std
::
unique_ptr
<
OperationPass
<
FuncOp
>>
createNCNNOptimizePass
();
std
::
unique_ptr
<
OperationPass
<
FuncOp
>
>
createNCNNOptimizePass
();
}
// namespace ncnn
}
// namespace ncnn
...
...
tools/mlir/ncnn_rewriter.cpp
浏览文件 @
00b0094b
...
@@ -42,7 +42,7 @@ void NCNNOptimizePass::runOnFunction()
...
@@ -42,7 +42,7 @@ void NCNNOptimizePass::runOnFunction()
(
void
)
mlir
::
applyPatternsAndFoldGreedily
(
getFunction
(),
std
::
move
(
patterns
));
(
void
)
mlir
::
applyPatternsAndFoldGreedily
(
getFunction
(),
std
::
move
(
patterns
));
}
}
std
::
unique_ptr
<
OperationPass
<
FuncOp
>>
createNCNNOptimizePass
()
std
::
unique_ptr
<
OperationPass
<
FuncOp
>
>
createNCNNOptimizePass
()
{
{
return
std
::
make_unique
<
NCNNOptimizePass
>
();
return
std
::
make_unique
<
NCNNOptimizePass
>
();
}
}
...
...
tools/quantize/CMakeLists.txt
浏览文件 @
00b0094b
...
@@ -23,9 +23,8 @@ if(NCNN_PIXEL)
...
@@ -23,9 +23,8 @@ if(NCNN_PIXEL)
target_compile_definitions
(
ncnn2table PUBLIC USE_NCNN_SIMPLEOCV
)
target_compile_definitions
(
ncnn2table PUBLIC USE_NCNN_SIMPLEOCV
)
target_link_libraries
(
ncnn2table PRIVATE ncnn
)
target_link_libraries
(
ncnn2table PRIVATE ncnn
)
else
()
else
()
add_executable
(
ncnn2table ncnn2table.cpp ../../src/simpleocv.cpp
)
add_executable
(
ncnn2table ncnn2table.cpp imreadwrite.cpp
)
target_compile_definitions
(
ncnn2table PUBLIC NCNN_SIMPLEOCV=1
)
target_compile_definitions
(
ncnn2table PUBLIC USE_LOCAL_IMREADWRITE
)
target_compile_definitions
(
ncnn2table PUBLIC USE_NCNN_SIMPLEOCV
)
target_link_libraries
(
ncnn2table PRIVATE ncnn
)
target_link_libraries
(
ncnn2table PRIVATE ncnn
)
endif
()
endif
()
...
...
tools/quantize/imreadwrite.cpp
0 → 100644
浏览文件 @
00b0094b
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2021 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.
#include "imreadwrite.h"
#include <stdio.h>
#define STB_IMAGE_IMPLEMENTATION
#define STBI_NO_THREAD_LOCALS
#define STBI_ONLY_JPEG
#define STBI_ONLY_PNG
#define STBI_ONLY_BMP
#define STBI_ONLY_PNM
#include "../../src/stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "../../src/stb_image_write.h"
namespace
cv
{
Mat
imread
(
const
std
::
string
&
path
,
int
flags
)
{
int
desired_channels
=
0
;
if
(
flags
==
IMREAD_UNCHANGED
)
{
desired_channels
=
0
;
}
else
if
(
flags
==
IMREAD_GRAYSCALE
)
{
desired_channels
=
1
;
}
else
if
(
flags
==
IMREAD_COLOR
)
{
desired_channels
=
3
;
}
else
{
// unknown flags
return
Mat
();
}
int
w
;
int
h
;
int
c
;
unsigned
char
*
pixeldata
=
stbi_load
(
path
.
c_str
(),
&
w
,
&
h
,
&
c
,
desired_channels
);
if
(
!
pixeldata
)
{
// load failed
return
Mat
();
}
if
(
desired_channels
)
{
c
=
desired_channels
;
}
// copy pixeldata to Mat
Mat
img
;
if
(
c
==
1
)
{
img
.
create
(
h
,
w
,
CV_8UC1
);
}
else
if
(
c
==
3
)
{
img
.
create
(
h
,
w
,
CV_8UC3
);
}
else
if
(
c
==
4
)
{
img
.
create
(
h
,
w
,
CV_8UC4
);
}
else
{
// unexpected channels
stbi_image_free
(
pixeldata
);
return
Mat
();
}
memcpy
(
img
.
data
,
pixeldata
,
w
*
h
*
c
);
stbi_image_free
(
pixeldata
);
// // resolve exif orientation
// {
// std::ifstream ifs;
// ifs.open(filename.c_str(), std::ifstream::in);
//
// if (ifs.good())
// {
// ExifReader exif_reader(ifs);
// if (exif_reader.parse())
// {
// ExifEntry_t e = exif_reader.getTag(ORIENTATION);
// int orientation = e.field_u16;
// if (orientation >= 1 && orientation <= 8)
// rotate_by_orientation(img, img, orientation);
// }
// }
//
// ifs.close();
// }
// rgb to bgr
if
(
c
==
3
)
{
uchar
*
p
=
img
.
data
;
for
(
int
i
=
0
;
i
<
w
*
h
;
i
++
)
{
std
::
swap
(
p
[
0
],
p
[
2
]);
p
+=
3
;
}
}
if
(
c
==
4
)
{
uchar
*
p
=
img
.
data
;
for
(
int
i
=
0
;
i
<
w
*
h
;
i
++
)
{
std
::
swap
(
p
[
0
],
p
[
2
]);
p
+=
4
;
}
}
return
img
;
}
bool
imwrite
(
const
std
::
string
&
path
,
const
Mat
&
m
,
const
std
::
vector
<
int
>&
params
)
{
const
char
*
_ext
=
strrchr
(
path
.
c_str
(),
'.'
);
if
(
!
_ext
)
{
// missing extension
return
false
;
}
std
::
string
ext
=
_ext
;
Mat
img
=
m
.
clone
();
// bgr to rgb
int
c
=
0
;
if
(
img
.
type
()
==
CV_8UC1
)
{
c
=
1
;
}
else
if
(
img
.
type
()
==
CV_8UC3
)
{
c
=
3
;
uchar
*
p
=
img
.
data
;
for
(
int
i
=
0
;
i
<
img
.
cols
*
img
.
rows
;
i
++
)
{
std
::
swap
(
p
[
0
],
p
[
2
]);
p
+=
3
;
}
}
else
if
(
img
.
type
()
==
CV_8UC4
)
{
c
=
4
;
uchar
*
p
=
img
.
data
;
for
(
int
i
=
0
;
i
<
img
.
cols
*
img
.
rows
;
i
++
)
{
std
::
swap
(
p
[
0
],
p
[
2
]);
p
+=
4
;
}
}
else
{
// unexpected image channels
return
false
;
}
bool
success
=
false
;
if
(
ext
==
".jpg"
||
ext
==
".jpeg"
||
ext
==
".JPG"
||
ext
==
".JPEG"
)
{
int
quality
=
95
;
for
(
size_t
i
=
0
;
i
<
params
.
size
();
i
+=
2
)
{
if
(
params
[
i
]
==
IMWRITE_JPEG_QUALITY
)
{
quality
=
params
[
i
+
1
];
break
;
}
}
success
=
stbi_write_jpg
(
path
.
c_str
(),
img
.
cols
,
img
.
rows
,
c
,
img
.
data
,
quality
);
}
else
if
(
ext
==
".png"
||
ext
==
".PNG"
)
{
success
=
stbi_write_png
(
path
.
c_str
(),
img
.
cols
,
img
.
rows
,
c
,
img
.
data
,
0
);
}
else
if
(
ext
==
".bmp"
||
ext
==
".BMP"
)
{
success
=
stbi_write_bmp
(
path
.
c_str
(),
img
.
cols
,
img
.
rows
,
c
,
img
.
data
);
}
else
{
// unknown extension type
return
false
;
}
return
success
;
}
}
// namespace cv
tools/quantize/imreadwrite.h
0 → 100644
浏览文件 @
00b0094b
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2017 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 IMREADWRITE_H
#define IMREADWRITE_H
#include <limits.h>
#include <string.h>
#include "allocator.h"
#include "mat.h"
#ifndef NCNN_XADD
using
ncnn
::
NCNN_XADD
;
#endif
typedef
unsigned
char
uchar
;
enum
{
CV_LOAD_IMAGE_UNCHANGED
=
-
1
,
CV_LOAD_IMAGE_GRAYSCALE
=
0
,
CV_LOAD_IMAGE_COLOR
=
1
,
};
enum
{
CV_IMWRITE_JPEG_QUALITY
=
1
};
// minimal opencv style data structure implementation
namespace
cv
{
#define CV_8UC1 1
#define CV_8UC3 3
#define CV_8UC4 4
#define CV_32FC1 4
struct
Mat
{
Mat
()
:
data
(
0
),
refcount
(
0
),
rows
(
0
),
cols
(
0
),
c
(
0
)
{
}
Mat
(
int
_rows
,
int
_cols
,
int
flags
)
:
data
(
0
),
refcount
(
0
)
{
create
(
_rows
,
_cols
,
flags
);
}
// copy
Mat
(
const
Mat
&
m
)
:
data
(
m
.
data
),
refcount
(
m
.
refcount
)
{
if
(
refcount
)
NCNN_XADD
(
refcount
,
1
);
rows
=
m
.
rows
;
cols
=
m
.
cols
;
c
=
m
.
c
;
}
Mat
(
int
_rows
,
int
_cols
,
int
flags
,
void
*
_data
)
:
data
((
unsigned
char
*
)
_data
),
refcount
(
0
)
{
rows
=
_rows
;
cols
=
_cols
;
c
=
flags
;
}
~
Mat
()
{
release
();
}
// assign
Mat
&
operator
=
(
const
Mat
&
m
)
{
if
(
this
==
&
m
)
return
*
this
;
if
(
m
.
refcount
)
NCNN_XADD
(
m
.
refcount
,
1
);
release
();
data
=
m
.
data
;
refcount
=
m
.
refcount
;
rows
=
m
.
rows
;
cols
=
m
.
cols
;
c
=
m
.
c
;
return
*
this
;
}
void
create
(
int
_rows
,
int
_cols
,
int
flags
)
{
release
();
rows
=
_rows
;
cols
=
_cols
;
c
=
flags
;
if
(
total
()
>
0
)
{
// refcount address must be aligned, so we expand totalsize here
size_t
totalsize
=
(
total
()
+
3
)
>>
2
<<
2
;
data
=
(
uchar
*
)
ncnn
::
fastMalloc
(
totalsize
+
(
int
)
sizeof
(
*
refcount
));
refcount
=
(
int
*
)(((
uchar
*
)
data
)
+
totalsize
);
*
refcount
=
1
;
}
}
void
release
()
{
if
(
refcount
&&
NCNN_XADD
(
refcount
,
-
1
)
==
1
)
ncnn
::
fastFree
(
data
);
data
=
0
;
rows
=
0
;
cols
=
0
;
c
=
0
;
refcount
=
0
;
}
Mat
clone
()
const
{
if
(
empty
())
return
Mat
();
Mat
m
(
rows
,
cols
,
c
);
if
(
total
()
>
0
)
{
memcpy
(
m
.
data
,
data
,
total
());
}
return
m
;
}
bool
empty
()
const
{
return
data
==
0
||
total
()
==
0
;
}
int
type
()
const
{
return
c
;
}
size_t
total
()
const
{
return
cols
*
rows
*
c
;
}
uchar
*
data
;
// pointer to the reference counter;
// when points to user-allocated data, the pointer is NULL
int
*
refcount
;
int
rows
;
int
cols
;
int
c
;
};
enum
ImreadModes
{
IMREAD_UNCHANGED
=
-
1
,
IMREAD_GRAYSCALE
=
0
,
IMREAD_COLOR
=
1
};
Mat
imread
(
const
std
::
string
&
path
,
int
flags
=
IMREAD_COLOR
);
enum
ImwriteFlags
{
IMWRITE_JPEG_QUALITY
=
1
};
bool
imwrite
(
const
std
::
string
&
path
,
const
Mat
&
m
,
const
std
::
vector
<
int
>&
params
=
std
::
vector
<
int
>
());
}
// namespace cv
#endif // IMREADWRITE_H
tools/quantize/ncnn2table.cpp
浏览文件 @
00b0094b
...
@@ -30,6 +30,8 @@
...
@@ -30,6 +30,8 @@
#if defined(USE_NCNN_SIMPLEOCV)
#if defined(USE_NCNN_SIMPLEOCV)
#include "simpleocv.h"
#include "simpleocv.h"
#elif defined(USE_LOCAL_IMREADWRITE)
#include "imreadwrite.h"
#else
#else
#include <opencv2/core/core.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui.hpp>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录