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
4884292f
Commit
4884292f
authored
Jun 09, 2023
by
Sikhin VC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api changes
parent
a9f78581
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
schemas/api_schema.py
schemas/api_schema.py
+2
-0
yolo_optimization.py
yolo_optimization.py
+10
-6
No files found.
schemas/api_schema.py
View file @
4884292f
...
...
@@ -8,3 +8,5 @@ from pydantic import BaseModel
class
optimization
(
BaseModel
):
num_class
:
str
image_size
:
str
weight_path
:
str
mount_path
:
str
yolo_optimization.py
View file @
4884292f
...
...
@@ -10,9 +10,11 @@ import uvicorn
app
=
FastAPI
()
class
ModelOptimization
:
def
__init__
(
self
,
num_class
,
image_size
=
416
):
def
__init__
(
self
,
num_class
,
mount_path
,
weight_path
,
image_size
=
416
):
self
.
num_class
=
num_class
self
.
image_size
=
image_size
self
.
mount_path
=
mount_path
self
.
weight_path
=
weight_path
def
change_configurations
(
self
):
logger
.
info
(
f
"Provided number of classes and image size are : {self.num_class} and {self.image_size}"
)
...
...
@@ -32,16 +34,17 @@ class ModelOptimization:
logger
.
info
(
"Successfully changed configurations"
)
except
Exception
as
e
:
logger
.
info
(
f
"Failed to change configurations : {e}"
)
def
transfer_weight_file
(
self
,
remote_path
,
remote_cred
):
def
optimize_model
(
self
,
weight_path
):
def
optimize_model
(
self
):
try
:
current_directory
=
os
.
getcwd
()
if
os
.
path
.
exists
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
)):
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
)
shutil
.
copy
(
self
.
weight_path
,
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
))
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}"
)
...
...
@@ -60,6 +63,7 @@ class ModelOptimization:
logger
.
info
(
"Optimizing model"
)
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"
])
shutil
.
move
(
os
.
path
.
join
(
current_directory
,
'tensorrtx/yolov5/build'
,
engine_name
),
self
.
mount_path
)
except
Exception
as
e
:
logger
.
info
(
f
"Failed to optimized model : {e}"
)
...
...
@@ -67,9 +71,9 @@ class ModelOptimization:
@
app
.
post
(
"/optimize"
)
async
def
root
(
content
:
optimization
):
# print(content.dict())
obj
=
ModelOptimization
(
num_class
=
int
(
content
.
num_class
),
image_size
=
int
(
content
.
image_size
))
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
.
optimize_model
(
weight_path
=
"jk_v5_cam_47.wts"
)
obj
.
optimize_model
()
return
{
"message"
:
"successfull"
}
...
...
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