Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2022-154
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-154
2022-154
Commits
f66ee476
Commit
f66ee476
authored
Nov 14, 2022
by
Senatilaka T.S.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
ce7fddbf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
iot/InspBot/yolov5.py
iot/InspBot/yolov5.py
+33
-0
No files found.
iot/InspBot/yolov5.py
0 → 100644
View file @
f66ee476
import
io
import
torch
from
PIL
import
Image
ddWeights
=
'./weights/dd.pt'
gsWeights
=
'./weights/gs.pt'
def
setModel
(
modelType
):
global
model
weight
=
ddWeights
if
modelType
==
'gs'
:
weight
=
gsWeights
model
=
torch
.
hub
.
load
(
"./yolov5"
,
'custom'
,
path
=
weight
,
source
=
'local'
)
model
.
conf
=
0.6
def
yolov5
(
img
):
results
=
model
(
img
)
detected_classes
=
[]
confidence
=
0.0
names
=
results
.
names
if
results
.
pred
is
not
None
:
pred
=
results
.
pred
[
0
]
if
pred
is
not
None
:
for
c
in
pred
[:,
-
1
]
.
unique
():
n
=
(
pred
[:,
-
1
]
==
c
)
.
sum
()
confidence
=
pred
[
0
][
4
]
.
item
()
detected_classes
.
append
(
f
"{names[int(c)]}{'s' * (n > 1)}"
)
rendered_imgs
=
results
.
render
()
converted_img
=
Image
.
fromarray
(
rendered_imgs
[
0
])
.
convert
(
"RGB"
)
return
detected_classes
,
confidence
,
converted_img
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