Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-220
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
2022-220
2022-220
Commits
a36c3507
Commit
a36c3507
authored
Nov 13, 2022
by
Pathirana K.P.G.I
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
cdfab0ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
preprocessing.py
preprocessing.py
+63
-0
No files found.
preprocessing.py
0 → 100644
View file @
a36c3507
import
os
import
cv2
import
numpy
as
np
path
=
'Data'
categories
=
os
.
listdir
(
path
)
labels
=
list
(
range
(
len
(
categories
)))
categorDict
=
dict
(
zip
(
categories
,
labels
))
print
(
categories
)
print
(
labels
)
print
(
categorDict
)
size
=
50
dataset
=
[]
for
category
in
categories
:
imgs_path
=
os
.
path
.
join
(
path
,
category
)
imgs_names
=
os
.
listdir
(
imgs_path
)
for
img_name
in
imgs_names
:
img_path
=
os
.
path
.
join
(
imgs_path
,
img_name
)
img
=
cv2
.
imread
(
img_path
)
try
:
gray
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2GRAY
)
gray
=
cv2
.
resize
(
gray
,
(
size
,
size
))
dataset
.
append
([
gray
,
categorDict
[
category
]])
except
Exception
as
e
:
print
(
e
)
len
(
dataset
)
from
random
import
shuffle
shuffle
(
dataset
)
data
=
[]
target
=
[]
for
img
,
label
in
dataset
:
data
.
append
(
img
)
target
.
append
(
label
)
data
=
np
.
array
(
data
)
target
=
np
.
array
(
target
)
data
=
data
.
reshape
(
data
.
shape
[
0
],
size
,
size
,
1
)
/
255
from
keras.utils
import
np_utils
target
=
np_utils
.
to_categorical
(
target
)
print
(
data
.
shape
)
print
(
target
.
shape
)
np
.
save
(
'Processed_Data/data'
,
data
)
np
.
save
(
'Processed_Data/target'
,
target
)
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