Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BirdsRecognition
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
Container 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
Projet Commande Entreprise - Groupe 12
BirdsRecognition
Commits
89833993
Commit
89833993
authored
3 years ago
by
ABDERRAHIM El Habib
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
b30834fd
No related branches found
No related tags found
1 merge request
!1
uploading main
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Main.py
+64
-0
64 additions, 0 deletions
Main.py
with
64 additions
and
0 deletions
Main.py
0 → 100644
+
64
−
0
View file @
89833993
#basic imports
import
numpy
as
np
import
cv2
import
Model
import
WeightReader
import
Load_image
import
Process_predictions
import
pandas
as
pd
Model
=
Model
.
make_yolov3_model
()
weight_reader
=
WeightReader
(
"
yolov3.weights
"
)
weight_reader
.
load_weights
(
Model
)
input_w
,
input_h
=
416
,
416
# here put the size of your input image
photo_filename
=
'
birds9.jpg
'
# here put the filename of your input image
image
,
image_w
,
image_h
=
Load_image
.
load_image_pixels
(
photo_filename
,
(
input_w
,
input_h
))
outputs
=
Model
.
predict
(
image
)
anchors
=
[[
116
,
90
,
156
,
198
,
373
,
326
],
[
30
,
61
,
62
,
45
,
59
,
119
],
[
10
,
13
,
16
,
30
,
33
,
23
]]
class_threshold
=
0.6
boxes
=
list
()
for
i
in
range
(
len
(
outputs
)):
boxes
+=
Process_predictions
.
decode_netout
(
outputs
[
i
][
0
],
anchors
[
i
],
class_threshold
,
input_h
,
input_w
)
Process_predictions
.
correct_yolo_boxes
(
boxes
,
image_h
,
image_w
,
input_h
,
input_w
)
Process_predictions
.
do_nms
(
boxes
,
0.5
)
labels
=
[
"
person
"
,
"
bicycle
"
,
"
car
"
,
"
motorbike
"
,
"
aeroplane
"
,
"
bus
"
,
"
train
"
,
"
truck
"
,
"
boat
"
,
"
traffic light
"
,
"
fire hydrant
"
,
"
stop sign
"
,
"
parking meter
"
,
"
bench
"
,
"
bird
"
,
"
cat
"
,
"
dog
"
,
"
horse
"
,
"
sheep
"
,
"
cow
"
,
"
elephant
"
,
"
bear
"
,
"
zebra
"
,
"
giraffe
"
,
"
backpack
"
,
"
umbrella
"
,
"
handbag
"
,
"
tie
"
,
"
suitcase
"
,
"
frisbee
"
,
"
skis
"
,
"
snowboard
"
,
"
sports ball
"
,
"
kite
"
,
"
baseball bat
"
,
"
baseball glove
"
,
"
skateboard
"
,
"
surfboard
"
,
"
tennis racket
"
,
"
bottle
"
,
"
wine glass
"
,
"
cup
"
,
"
fork
"
,
"
knife
"
,
"
spoon
"
,
"
bowl
"
,
"
banana
"
,
"
apple
"
,
"
sandwich
"
,
"
orange
"
,
"
broccoli
"
,
"
carrot
"
,
"
hot dog
"
,
"
pizza
"
,
"
donut
"
,
"
cake
"
,
"
chair
"
,
"
sofa
"
,
"
pottedplant
"
,
"
bed
"
,
"
diningtable
"
,
"
toilet
"
,
"
tvmonitor
"
,
"
laptop
"
,
"
mouse
"
,
"
remote
"
,
"
keyboard
"
,
"
cell phone
"
,
"
microwave
"
,
"
oven
"
,
"
toaster
"
,
"
sink
"
,
"
refrigerator
"
,
"
book
"
,
"
clock
"
,
"
vase
"
,
"
scissors
"
,
"
teddy bear
"
,
"
hair drier
"
,
"
toothbrush
"
]
v_boxes
,
v_labels
,
v_scores
=
Process_predictions
.
get_boxes
(
boxes
,
labels
,
class_threshold
)
#view our detections
Process_predictions
.
draw_boxes
(
photo_filename
,
v_boxes
,
v_labels
,
v_scores
)
csv_array
=
np
.
zeros
((
len
(
v_boxes
),
5
))
# this code creates an array in which we save the coordinates of the rectangles: the detected birds
id_image
=
0
# i still don't know how to fill up image ids
from
PIL
import
Image
#for j in range( number of images )
for
i
in
range
(
len
(
v_boxes
)):
csv_array
[
i
][
0
]
=
i
csv_array
[
i
][
1
]
=
v_boxes
[
i
].
xmin
csv_array
[
i
][
2
]
=
v_boxes
[
i
].
ymax
csv_array
[
i
][
3
]
=
v_boxes
[
i
].
xmax
csv_array
[
i
][
4
]
=
v_boxes
[
i
].
ymin
# we convert our array to a dataframe and then we save it in a csv file
import
pandas
as
pd
pd
.
DataFrame
(
csv_array
).
to_csv
(
'
sample.csv
'
)
#now we will reload our original image and crop the detected birds and save them in different files
img
=
cv2
.
imread
(
'
birds9.jpg
'
)
# insert original image here
print
(
img
.
shape
)
# Print image shape
for
i
in
range
(
len
(
v_boxes
)):
cropped_image
=
img
[
v_boxes
[
i
].
ymin
:
v_boxes
[
i
].
ymax
,
v_boxes
[
i
].
xmin
:
v_boxes
[
i
].
xmax
]
cv2
.
imwrite
(
"
oiseau
"
+
str
(
i
+
1
)
+
"
.jpg
"
,
cropped_image
)
\ 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