Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
CHILD INTELLIGENT ASSESSMENT TOOL
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
2020-046
CHILD INTELLIGENT ASSESSMENT TOOL
Commits
3e30946b
Commit
3e30946b
authored
Jul 09, 2020
by
Gunasinghe M.D.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete predict.py
parent
96ed0209
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
86 deletions
+0
-86
predict.py
predict.py
+0
-86
No files found.
predict.py
deleted
100644 → 0
View file @
96ed0209
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: Gunasinghe M.D.
"""
import
pandas
as
pd
import
numpy
as
np
import
cv2
import
argparse
from
keras.models
import
load_model
from
keras.preprocessing.image
import
ImageDataGenerator
from
sklearn.metrics
import
confusion_matrix
,
accuracy_score
from
myutil
import
probas_to_classes
# Loading and compiling presaved trained CNN
model
=
load_model
(
'drawing_classification.h5'
)
label
=
{
0
:
"Circle"
,
1
:
"Square"
,
2
:
"Triangle"
}
def
predict_one
(
file_name
):
img
=
cv2
.
imread
(
file_name
)
img
=
cv2
.
resize
(
img
,
(
28
,
28
))
img
=
np
.
reshape
(
img
,
[
1
,
28
,
28
,
3
])
classes
=
model
.
predict_classes
(
img
)[
0
]
category
=
label
[
classes
]
print
(
"
\n
And {1} is the {0}"
.
format
(
category
,
file_name
))
# return category
def
predict_dataset
(
input_dir
):
test_datagen
=
ImageDataGenerator
(
rescale
=
1.
/
255
)
test_generator
=
test_datagen
.
flow_from_directory
(
"shapes/test"
,
target_size
=
(
28
,
28
),
color_mode
=
"rgb"
,
shuffle
=
False
,
class_mode
=
'categorical'
,
batch_size
=
1
)
filenames
=
test_generator
.
filenames
nb_samples
=
len
(
filenames
)
predict
=
model
.
predict_generator
(
test_generator
,
steps
=
nb_samples
)
return
predict
,
test_generator
def
main
():
# Instantiate the parser
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--testdata'
,
help
=
'Classify images on test data'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--validationdata'
,
help
=
'Classify images on test data'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--image'
,
help
=
'Input your image file name'
)
args
=
parser
.
parse_args
()
on_dataset
=
False
if
args
.
testdata
:
print
(
"Classify images on test dataset"
)
on_dataset
=
True
input_dir
=
"shapes/test"
if
args
.
validationdata
:
print
(
"Classify images on validation dataset"
)
on_dataset
=
True
input_dir
=
"shapes/validation"
if
on_dataset
:
predict
,
test_generator
=
predict_dataset
(
input_dir
)
y_pred
=
probas_to_classes
(
predict
)
y_true
=
test_generator
.
classes
X_images
=
test_generator
.
filenames
cm
=
confusion_matrix
(
y_true
,
y_pred
)
ac
=
accuracy_score
(
y_true
,
y_pred
)
for
ele
in
list
(
zip
(
X_images
,
y_true
,
y_pred
)):
print
(
ele
)
else
:
file_name
=
args
.
image
predict_one
(
file_name
)
if
__name__
==
'__main__'
:
main
()
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