Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 35
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
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
22_23-J 35
22_23-J 35
Commits
55e7bfe8
Commit
55e7bfe8
authored
Feb 03, 2023
by
Chamindu Madushan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed unauthorized animal identification by scikit-learn
parent
c55b3161
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
animalIdentification.py
animalIdentification.py
+78
-0
No files found.
animalIdentification.py
0 → 100644
View file @
55e7bfe8
from
bing_image_downloader
import
downloader
downloader
.
download
(
"civet"
,
limit
=
30
,
output_dir
=
'images'
,
adult_filter_off
=
True
)
from
bing_image_downloader
import
downloader
downloader
.
download
(
"cat"
,
limit
=
30
,
output_dir
=
'images'
,
adult_filter_off
=
True
)
from
bing_image_downloader
import
downloader
downloader
.
download
(
"rat"
,
limit
=
40
,
output_dir
=
'images'
,
adult_filter_off
=
True
)
# prepocess
import
os
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
skimage.io
import
imread
from
skimage.transform
import
resize
target
=
[]
images
=
[]
flat_data
=
[]
DATADIR
=
'/content/images'
CATEGORIES
=
[
'civet'
,
'cat'
,
'snakes'
,
'rat'
]
for
category
in
CATEGORIES
:
class_num
=
CATEGORIES
.
index
(
category
)
# label encoding
path
=
os
.
path
.
join
(
DATADIR
,
category
)
# create path to use all images
for
img
in
os
.
listdir
(
path
):
img_array
=
imread
(
os
.
path
.
join
(
path
,
img
))
# print(img_array.shape)
# plt.imshow(img_array)
img_resized
=
resize
(
img_array
,
(
150
,
150
,
3
))
# Normalizes to 0 to 1
flat_data
.
append
(
img_resized
.
flatten
())
images
.
append
(
img_resized
)
target
.
append
(
class_num
)
flat_data
=
np
.
array
(
flat_data
)
target
=
np
.
array
(
target
)
images
=
np
.
array
(
images
)
# split data into Training and Testing
from
sklearn.model_selection
import
train_test_split
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
flat_data
,
target
,
test_size
=
0.3
,
random_state
=
109
)
from
sklearn.model_selection
import
GridSearchCV
from
sklearn
import
svm
# support vector machine for a model
param_grid
=
[
{
'C'
:
[
1
,
10
,
100
,
1000
],
'kernel'
:
[
'linear'
]},
{
'C'
:
[
1
,
10
,
100
,
1000
],
'gamma'
:
[
0.001
,
0.0001
],
'kernel'
:
[
'rbf'
]},
]
svc
=
svm
.
SVC
(
probability
=
True
)
clf
=
GridSearchCV
(
svc
,
param_grid
)
clf
.
fit
(
X_train
,
y_train
)
y_pred
=
clf
.
predict
(
X_test
)
y_pred
y_test
from
sklearn.metrics
import
accuracy_score
,
confusion_matrix
accuracy_score
(
y_pred
,
y_test
)
# check Accuracy
confusion_matrix
(
y_pred
,
y_test
)
# save the model using pickle library
import
pickle
pickle
.
dump
(
clf
,
open
(
'img_model.p'
,
'wb'
))
model
=
pickle
.
load
(
open
(
'img_model.p'
,
'rb'
))
\ No newline at end of file
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