Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IA_Image classsification_TD1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Delorme Antonin
IA_Image classsification_TD1
Commits
e1fb51cb
Commit
e1fb51cb
authored
1 year ago
by
Delorme Antonin
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
1efa16bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mlp.py
+38
-0
38 additions, 0 deletions
mlp.py
with
38 additions
and
0 deletions
mlp.py
0 → 100644
+
38
−
0
View file @
e1fb51cb
import
pickle
import
numpy
as
np
import
random
as
rd
import
read_cifar
as
rd
from
math
import
*
import
matplotlib.pyplot
as
plt
N
=
30
# number of input data
d_in
=
3
# input dimension
d_h
=
3
# number of neurons in the hidden layer
d_out
=
2
# output dimension (number of neurons of the output layer)
# Random initialization of the network weights and biaises
w1
=
2
*
np
.
random
.
rand
(
d_in
,
d_h
)
-
1
# first layer weights
b1
=
np
.
zeros
((
1
,
d_h
))
# first layer biaises
w2
=
2
*
np
.
random
.
rand
(
d_h
,
d_out
)
-
1
# second layer weights
b2
=
np
.
zeros
((
1
,
d_out
))
# second layer biaises
data
=
np
.
random
.
rand
(
N
,
d_in
)
# create a random data
targets
=
np
.
random
.
rand
(
N
,
d_out
)
# create a random targets
# Forward pass
a0
=
data
# the data are the input of the first layer
z1
=
np
.
matmul
(
a0
,
w1
)
+
b1
# input of the hidden layer
a1
=
1
/
(
1
+
np
.
exp
(
-
z1
))
# output of the hidden layer (sigmoid activation function)
z2
=
np
.
matmul
(
a1
,
w2
)
+
b2
# input of the output layer
a2
=
1
/
(
1
+
np
.
exp
(
-
z2
))
# output of the output layer (sigmoid activation function)
predictions
=
a2
# the predicted values are the outputs of the output layer
# Compute loss (MSE)
loss
=
np
.
mean
(
np
.
square
(
predictions
-
targets
))
print
(
loss
)
if
__name__
==
"
__main__
"
:
print
(
""
)
\ 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