Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pokedex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
michael.divia
Pokedex
Commits
67858bd1
Commit
67858bd1
authored
3 months ago
by
michael.divia
Browse files
Options
Downloads
Patches
Plain Diff
Predict 4 Rpi
parent
1949d2bd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Python/predict_pokemon.py
+46
-0
46 additions, 0 deletions
Python/predict_pokemon.py
yaml/resnet50.yaml
+0
-8
0 additions, 8 deletions
yaml/resnet50.yaml
with
46 additions
and
8 deletions
Python/predict_pokemon.py
0 → 100644
+
46
−
0
View file @
67858bd1
import
cv2
import
numpy
as
np
import
json
from
hailo_platform.pyhailort
import
HailoRT
# Load class names
with
open
(
"
../models/ResNet50/class_names.json
"
,
"
r
"
)
as
f
:
class_names
=
json
.
load
(
f
)
# --- Load HEF and configure device ---
hef_path
=
"
../models/ResNet50/resnet50.hef
"
device
=
HailoRT
.
Device
()
hef
=
HailoRT
.
Hef
(
hef_path
)
configured_network_group
=
device
.
create_hef_group
(
hef
)
input_vstream_info
=
configured_network_group
.
get_input_vstream_infos
()[
0
]
output_vstream_info
=
configured_network_group
.
get_output_vstream_infos
()[
0
]
# --- Open webcam ---
cap
=
cv2
.
VideoCapture
(
0
)
if
not
cap
.
isOpened
():
print
(
"
-- Unable to open webcam
"
)
exit
()
print
(
"
-- Taking picture...
"
)
ret
,
frame
=
cap
.
read
()
cap
.
release
()
if
not
ret
:
print
(
"
-- Failed to capture image
"
)
exit
()
# --- Preprocess image ---
image
=
cv2
.
resize
(
frame
,
(
224
,
224
))
image
=
image
.
astype
(
np
.
float32
)
/
255.0
# Normalize to [0, 1]
image
=
np
.
expand_dims
(
image
,
axis
=
0
)
# Add batch dimension
image
=
np
.
transpose
(
image
,
(
0
,
3
,
1
,
2
))
# NHWC ? NCHW if required (check your model)
# --- Inference ---
with
HailoRT
.
VirtualStreams
(
input_vstream_info
,
output_vstream_info
,
configured_network_group
)
as
(
input_vstreams
,
output_vstreams
):
input_vstreams
[
0
].
send
(
image
)
output_data
=
output_vstreams
[
0
].
recv
()
# --- Postprocess ---
predicted_idx
=
int
(
np
.
argmax
(
output_data
))
predicted_name
=
class_names
[
predicted_idx
]
print
(
f
"
-- Predicted Pokémon:
{
predicted_name
}
"
)
This diff is collapsed.
Click to expand it.
yaml/resnet50.yaml
deleted
100644 → 0
+
0
−
8
View file @
1949d2bd
network
:
name
:
custom_resnet50
framework
:
onnx
path
:
resnet50_pokemon.onnx
input_shape
:
[
1
,
224
,
224
,
3
]
mean_std
:
mean
:
[
123.68
,
116.779
,
103.939
]
std
:
[
1.0
,
1.0
,
1.0
]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment