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
109db292
Commit
109db292
authored
Jun 09, 2023
by
Sikhin VC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api changes
parent
880e9d0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
yolo_optimization.py
yolo_optimization.py
+7
-12
No files found.
yolo_optimization.py
View file @
109db292
...
@@ -37,23 +37,17 @@ class ModelOptimization:
...
@@ -37,23 +37,17 @@ class ModelOptimization:
def
optimize_model
(
self
):
def
optimize_model
(
self
):
try
:
try
:
current_directory
=
os
.
getcwd
()
current_directory
=
os
.
getcwd
()
logger
.
info
(
f
"Current directory is : {current_directory}"
)
if
os
.
path
.
exists
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
)):
if
os
.
path
.
exists
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
)):
shutil
.
rmtree
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
shutil
.
rmtree
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
logger
.
info
(
"Removed existing build directory"
)
os
.
mkdir
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
os
.
mkdir
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
logger
.
info
(
"Built new build directory"
)
shutil
.
copy
(
self
.
weight_path
,
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
shutil
.
copy
(
self
.
weight_path
,
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
logger
.
info
(
"Copied wts file to build directory"
)
weight_name_with_extension
=
os
.
path
.
basename
(
self
.
weight_path
)
weight_name_with_extension
=
os
.
path
.
basename
(
self
.
weight_path
)
weight_name
,
extension
=
os
.
path
.
splitext
(
weight_name_with_extension
)
logger
.
info
(
f
"Current directory is : {current_directory}"
)
# build_files = glob.glob("tensorrtx/yolov5/build/*")
# for file in build_files:
# os.remove(file)
# build_path = os.path.join(current_directory, "yolov5", "build")
# os.mkdir(build_path)
# logger.info(f"Created build folder")
os
.
chdir
(
'tensorrtx/yolov5/build'
)
os
.
chdir
(
'tensorrtx/yolov5/build'
)
logger
.
info
(
"Changed to build directory"
)
logger
.
info
(
"Running CMake command"
)
logger
.
info
(
"Running CMake command"
)
subprocess
.
run
([
'cmake'
,
'..'
])
subprocess
.
run
([
'cmake'
,
'..'
])
logger
.
info
(
"Running Make command"
)
logger
.
info
(
"Running Make command"
)
...
@@ -62,13 +56,14 @@ class ModelOptimization:
...
@@ -62,13 +56,14 @@ class ModelOptimization:
engine_name
=
"best.engine"
engine_name
=
"best.engine"
subprocess
.
run
([
"sudo"
,
"./yolov5"
,
"-s"
,
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
,
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"
])
shutil
.
move
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
,
engine_name
),
self
.
mount_path
)
shutil
.
move
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
,
engine_name
),
self
.
mount_path
)
shutil
.
move
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
,
"libmyplugins.so"
),
self
.
mount_path
)
logger
.
info
(
f
"Moved engine file and libmyplugins.so file to {self.mount_path}"
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
f
"Failed to optimized model : {e}"
)
logger
.
info
(
f
"Failed to optimized model : {e}"
)
@
app
.
post
(
"/optimize"
)
@
app
.
post
(
"/optimize"
)
async
def
root
(
content
:
optimization
):
async
def
root
(
content
:
optimization
):
# print(content.dict())
obj
=
ModelOptimization
(
num_class
=
int
(
content
.
num_class
),
image_size
=
int
(
content
.
image_size
),
weight_path
=
content
.
weight_path
,
mount_path
=
content
.
mount_path
)
obj
=
ModelOptimization
(
num_class
=
int
(
content
.
num_class
),
image_size
=
int
(
content
.
image_size
),
weight_path
=
content
.
weight_path
,
mount_path
=
content
.
mount_path
)
obj
.
change_configurations
()
obj
.
change_configurations
()
obj
.
optimize_model
()
obj
.
optimize_model
()
...
...
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