Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yolo_model_optimization
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikhin.vc
yolo_model_optimization
Commits
aaec516a
Commit
aaec516a
authored
Jun 08, 2023
by
Sikhin VC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abc
parent
6d1bcfcd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
9 deletions
+17
-9
schemas/__pycache__/api_schema.cpython-39.pyc
schemas/__pycache__/api_schema.cpython-39.pyc
+0
-0
tensorrtx/yolov5/yololayer.h
tensorrtx/yolov5/yololayer.h
+2
-2
yolo_optimization.py
yolo_optimization.py
+15
-7
No files found.
schemas/__pycache__/api_schema.cpython-39.pyc
0 → 100644
View file @
aaec516a
File added
tensorrtx/yolov5/yololayer.h
View file @
aaec516a
...
@@ -17,9 +17,9 @@ namespace Yolo
...
@@ -17,9 +17,9 @@ namespace Yolo
float
anchors
[
CHECK_COUNT
*
2
];
float
anchors
[
CHECK_COUNT
*
2
];
};
};
static
constexpr
int
MAX_OUTPUT_BBOX_COUNT
=
1000
;
static
constexpr
int
MAX_OUTPUT_BBOX_COUNT
=
1000
;
static
constexpr
int
CLASS_NUM
=
2
;
static
constexpr
int
CLASS_NUM
=
1
;
static
constexpr
int
INPUT_H
=
416
;
static
constexpr
int
INPUT_H
=
416
;
static
constexpr
int
INPUT_H
=
416
;
static
constexpr
int
INPUT_W
=
416
;
static
constexpr
int
LOCATIONS
=
4
;
static
constexpr
int
LOCATIONS
=
4
;
struct
alignas
(
float
)
Detection
{
struct
alignas
(
float
)
Detection
{
...
...
yolo_optimization.py
View file @
aaec516a
...
@@ -5,6 +5,7 @@ from loguru import logger
...
@@ -5,6 +5,7 @@ from loguru import logger
import
shutil
import
shutil
from
fastapi
import
FastAPI
from
fastapi
import
FastAPI
from
schemas.api_schema
import
optimization
from
schemas.api_schema
import
optimization
import
uvicorn
app
=
FastAPI
()
app
=
FastAPI
()
...
@@ -23,7 +24,7 @@ class ModelOptimization:
...
@@ -23,7 +24,7 @@ class ModelOptimization:
data
[
19
]
=
f
" static constexpr int CLASS_NUM = {self.num_class};
\n
"
data
[
19
]
=
f
" static constexpr int CLASS_NUM = {self.num_class};
\n
"
data
[
20
]
=
f
" static constexpr int INPUT_H = {self.image_size};
\n
"
data
[
20
]
=
f
" static constexpr int INPUT_H = {self.image_size};
\n
"
data
[
21
]
=
f
" static constexpr int INPUT_
H
= {self.image_size};
\n
"
data
[
21
]
=
f
" static constexpr int INPUT_
W
= {self.image_size};
\n
"
# and write everything back
# and write everything back
with
open
(
'tensorrtx/yolov5/yololayer.h'
,
'w'
)
as
file
:
with
open
(
'tensorrtx/yolov5/yololayer.h'
,
'w'
)
as
file
:
...
@@ -34,14 +35,17 @@ class ModelOptimization:
...
@@ -34,14 +35,17 @@ class ModelOptimization:
def
optimize_model
(
self
,
weight_path
):
def
optimize_model
(
self
,
weight_path
):
try
:
try
:
shutil
.
copy
(
weight_path
,
'tensorrtx/yolov5/build'
)
current_directory
=
os
.
getcwd
()
shutil
.
rmtree
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
os
.
mkdir
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
shutil
.
copy
(
weight_path
,
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
weight_name_with_extension
=
os
.
path
.
basename
(
weight_path
)
weight_name_with_extension
=
os
.
path
.
basename
(
weight_path
)
weight_name
,
extension
=
os
.
path
.
splitext
(
weight_name_with_extension
)
weight_name
,
extension
=
os
.
path
.
splitext
(
weight_name_with_extension
)
current_directory
=
os
.
getcwd
()
logger
.
info
(
f
"Current directory is : {current_directory}"
)
logger
.
info
(
f
"Current directory is : {current_directory}"
)
build_files
=
glob
.
glob
(
"tensorrtx/yolov5/build/*"
)
#
build_files = glob.glob("tensorrtx/yolov5/build/*")
for
file
in
build_files
:
#
for file in build_files:
os
.
remove
(
file
)
#
os.remove(file)
# build_path = os.path.join(current_directory, "yolov5", "build")
# build_path = os.path.join(current_directory, "yolov5", "build")
# os.mkdir(build_path)
# os.mkdir(build_path)
...
@@ -53,7 +57,7 @@ class ModelOptimization:
...
@@ -53,7 +57,7 @@ class ModelOptimization:
subprocess
.
run
([
'make'
])
subprocess
.
run
([
'make'
])
logger
.
info
(
"Optimizing model"
)
logger
.
info
(
"Optimizing model"
)
engine_name
=
"best.engine"
engine_name
=
"best.engine"
subprocess
.
run
([
"sudo"
,
"./yolov5"
,
"-s"
,
weight_name_with_extension
,
engine_name
,
"c"
,
"0.33"
,
"0.50"
])
subprocess
.
run
([
"sudo"
,
"./yolov5"
,
"-s"
,
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
,
weight_name_with_extension
)
,
engine_name
,
"c"
,
"0.33"
,
"0.50"
])
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
f
"Failed to optimized model : {e}"
)
logger
.
info
(
f
"Failed to optimized model : {e}"
)
...
@@ -67,3 +71,7 @@ async def root(content: optimization):
...
@@ -67,3 +71,7 @@ async def root(content: optimization):
return
{
"message"
:
"successfull"
}
return
{
"message"
:
"successfull"
}
if
__name__
==
'__main__'
:
uvicorn
.
run
(
app
,
port
=
8080
,
host
=
'localhost'
)
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