FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/benchmark/mnist/seq.cpp at master · cppwanderboy/cpp-taskflow · GitHub
cppwanderboy
/
cpp-taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-taskflow
/
benchmark
/
mnist
/
seq.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (39 loc) · 1.1 KB
Breadcrumbs
cpp-taskflow
/
benchmark
/
mnist
/
seq.cpp
Copy path
File metadata and controls
47 lines (39 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
include
"
dnn.hpp
"
void
run_sequential
(
MNIST
& D,
unsigned
num_threads) {
const
auto
iter_num = D.
images
.
rows
()/D.
batch_size
;
for
(
auto
e=
0u
; e<D.
epoch
; e++) {
for
(
auto
it=
0u
; it<iter_num; it++) {
//
Foward propagation
for
(
size_t
i=
0
; i<D.
acts
.
size
(); i++) {
if
(i ==
0
){
D.
forward
(i, D.
images
.
middleRows
(D.
beg_row
, D.
batch_size
));
}
else
{
D.
forward
(i, D.
Ys
[i-
1
]);
}
}
//
Calculate loss
D.
loss
(D.
labels
);
//
Backward propagation
for
(
int
i=D.
acts
.
size
()-
1
; i>=
0
; i--) {
if
(i >
0
) {
D.
backward
(i, D.
Ys
[i-
1
].
transpose
());
}
else
{
D.
backward
(i, D.
images
.
middleRows
(D.
beg_row
, D.
batch_size
).
transpose
());
}
}
//
Update parameters
for
(
int
i=D.
acts
.
size
()-
1
; i>=
0
; i--) {
D.
update
(i);
}
//
Get next batch
D.
beg_row
+= D.
batch_size
;
if
(D.
beg_row
>= D.
images
.
rows
()) {
D.
beg_row
=
0
;
}
}
//
End of iterations
//
Shuffle input
D.
shuffle
(D.
images
, D.
labels
, D.
images
.
rows
());
}
//
End of epoch
}
Back
|
FazBrowse Home
|
New Git URL