Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ViT_migraphx
Commits
2c275bc7
Commit
2c275bc7
authored
Sep 14, 2023
by
lijian6
Browse files
Update
Signed-off-by:
lijian
<
lijian6@sugon.com
>
parent
99304bcc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
Makefile
Makefile
+1
-1
README.md
README.md
+2
-0
src/main.cpp
src/main.cpp
+29
-1
No files found.
Makefile
View file @
2c275bc7
...
@@ -5,7 +5,7 @@ CC = g++
...
@@ -5,7 +5,7 @@ CC = g++
CFLAGS
=
-std
=
c++17
CFLAGS
=
-std
=
c++17
INC_P
=
-I
/opt/dtk/include
-I
/usr/local/include
INC_P
=
-I
/opt/dtk/include
-I
/usr/local/include
LIB_P
=
-L
/opt/dtk/lib
-L
/usr/local/lib
LIB_P
=
-L
/opt/dtk/lib
-L
/usr/local/lib
LDLIBS
=
-lopencv_core
-lopencv_imgcodecs
-lopencv_dnn
-lmigraphx
-lmigraphx_device
-lmigraphx_gpu
-lmigraphx_onnx
LDLIBS
=
-lopencv_core
-lopencv_imgcodecs
-lopencv_dnn
-lopencv_imgproc
-lmigraphx
-lmigraphx_device
-lmigraphx_gpu
-lmigraphx_onnx
SRC_F
=
src/main.cpp
SRC_F
=
src/main.cpp
EXEC
=
ViT_MIGraphX
EXEC
=
ViT_MIGraphX
...
...
README.md
View file @
2c275bc7
...
@@ -73,6 +73,8 @@ make
...
@@ -73,6 +73,8 @@ make
```
```
运行ViT模型,对daisy图片进行分类
运行ViT模型,对daisy图片进行分类
## result

## 精度
## 精度
...
...
src/main.cpp
View file @
2c275bc7
...
@@ -112,6 +112,34 @@ void postprocess(migraphx::argument result, int *n, string inputdir)
...
@@ -112,6 +112,34 @@ void postprocess(migraphx::argument result, int *n, string inputdir)
}
}
}
}
}
}
void
postprocess_single
(
migraphx
::
argument
result
,
int
*
n
,
cv
::
Mat
&
srcImage
)
{
const
char
*
labels
[]
=
{
"daisy"
,
"dandelion"
,
"roses"
,
"sunflowers"
,
"tulips"
};
migraphx
::
shape
outputShape
=
result
.
get_shape
();
float
*
logits
=
(
float
*
)
result
.
data
();
std
::
vector
<
float
>
logit
;
for
(
int
j
=
0
;
j
<
outputShape
.
elements
();
++
j
)
{
logit
.
push_back
(
logits
[
j
]);
}
std
::
vector
<
float
>
probs
=
ComputeSoftmax
(
logit
);
for
(
int
j
=
0
;
j
<
outputShape
.
elements
();
++
j
)
{
if
(
probs
[
j
]
>=
0.5
)
{
char
text
[
20
];
char
text1
[
20
];
fprintf
(
stdout
,
"labels: %s, confidence: %.3f
\n
"
,
labels
[
j
],
probs
[
j
]);
snprintf
(
text
,
sizeof
(
text
),
"labels: %s"
,
labels
[
j
]);
snprintf
(
text1
,
sizeof
(
text1
),
"confidence: %.3f"
,
probs
[
j
]);
cv
::
putText
(
srcImage
,
text
,
cv
::
Point
(
8
,
15
),
cv
::
FONT_HERSHEY_PLAIN
,
1.0
,
Scalar
(
0
,
0
,
255
),
1
);
cv
::
putText
(
srcImage
,
text1
,
cv
::
Point
(
8
,
25
),
cv
::
FONT_HERSHEY_PLAIN
,
1.0
,
Scalar
(
0
,
0
,
255
),
1
);
cv
::
imwrite
(
"result.jpg"
,
srcImage
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
if
(
argc
<
3
||
argc
>
3
)
if
(
argc
<
3
||
argc
>
3
)
...
@@ -173,7 +201,7 @@ int main(int argc, char *argv[])
...
@@ -173,7 +201,7 @@ int main(int argc, char *argv[])
std
::
vector
<
migraphx
::
argument
>
results
=
classifier
.
net
.
eval
(
inputData
);
std
::
vector
<
migraphx
::
argument
>
results
=
classifier
.
net
.
eval
(
inputData
);
postprocess
(
results
[
0
],
&
n
,
inputs
);
postprocess
_single
(
results
[
0
],
&
n
,
srcImage
);
}
}
return
0
;
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment