Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
21_22-J 38
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
21_22-J 38
21_22-J 38
Commits
c6817b52
Commit
c6817b52
authored
Jan 03, 2022
by
W.D.R.P. Sandeepa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented build_model function
parent
0b43ffd9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
1 deletion
+45
-1
backend/IT18218640/train.py
backend/IT18218640/train.py
+45
-1
No files found.
backend/IT18218640/train.py
View file @
c6817b52
...
@@ -5,3 +5,47 @@ from sklearn.model_selection import train_test_split
...
@@ -5,3 +5,47 @@ from sklearn.model_selection import train_test_split
DATA_PATH
=
"data.json"
DATA_PATH
=
"data.json"
SAVE_MODEL_PATH
=
"model.h5"
SAVE_MODEL_PATH
=
"model.h5"
LEARNING_RATE
=
0.0001
EPOCHS
=
40
BATCH_SIZE
=
32
NUM_KEYWORDS
=
10
def
build_model
(
input_shape
,
learning_rate
,
error
=
"sparse_categorical_crossentropy"
):
# build network
model
=
keras
.
Sequential
()
# copy layer 1
model
.
add
(
keras
.
layers
.
Conv2D
(
64
,
(
3
,
3
),
activation
=
"relu"
,
input_shape
=
input_shape
,
kernel_regularizer
=
keras
.
regularizers
.
l2
(
0.001
)))
model
.
add
(
keras
.
layers
.
BatchNormalization
())
model
.
add
(
keras
.
layers
.
MaxPool2D
((
3
,
3
),
strides
=
(
2
,
2
),
padding
=
"same"
))
# copy layer 2
model
.
add
(
keras
.
layers
.
Conv2D
(
32
,
(
3
,
3
),
activation
=
"relu"
,
kernel_regularizer
=
keras
.
regularizers
.
l2
(
0.001
)))
model
.
add
(
keras
.
layers
.
BatchNormalization
())
model
.
add
(
keras
.
layers
.
MaxPool2D
((
3
,
3
),
strides
=
(
2
,
2
),
padding
=
"same"
))
# copy layer 3
model
.
add
(
keras
.
layers
.
Conv2D
(
32
,
(
2
,
2
),
activation
=
"relu"
,
kernel_regularizer
=
keras
.
regularizers
.
l2
(
0.001
)))
model
.
add
(
keras
.
layers
.
BatchNormalization
())
model
.
add
(
keras
.
layers
.
MaxPool2D
((
2
,
2
),
strides
=
(
2
,
2
),
padding
=
"same"
))
# flatten the output feed it into a dense layer
model
.
add
(
keras
.
layers
.
Flatten
())
model
.
add
(
keras
.
layers
.
Dense
(
64
,
activation
=
"relu"
))
model
.
add
(
keras
.
layers
.
Dropout
(
0.3
))
# softmax classifier
model
.
add
(
keras
.
layers
.
Dense
(
NUM_KEYWORDS
,
activation
=
"softmax"
))
# compile the model
optimiser
=
keras
.
optimizers
.
Adam
(
learning_rate
=
learning_rate
)
model
.
compile
(
optimizer
=
optimiser
,
loss
=
error
,
metrics
=
[
"accuracy"
])
# print model overview
model
.
summary
()
return
model
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