FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/src/TensorFlowNET.Core/Data/MnistDataSet.cs at master · ehtick/TensorFlow.NET · GitHub
ehtick
/
TensorFlow.NET
Public
forked from
SciSharp/TensorFlow.NET
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
TensorFlow.NET
/
src
/
TensorFlowNET.Core
/
Data
/
MnistDataSet.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (74 loc) · 2.96 KB
Breadcrumbs
TensorFlow.NET
/
src
/
TensorFlowNET.Core
/
Data
/
MnistDataSet.cs
Copy path
File metadata and controls
85 lines (74 loc) · 2.96 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using
Tensorflow
.
NumPy
;
using
System
;
using
System
.
Diagnostics
;
namespace
Tensorflow
{
public
class
MnistDataSet
:
DataSetBase
{
public
int
NumOfExamples
{
get
;
private
set
;
}
public
int
EpochsCompleted
{
get
;
private
set
;
}
public
int
IndexInEpoch
{
get
;
private
set
;
}
public
MnistDataSet
(
NDArray
images
,
NDArray
labels
,
TF_DataType
dataType
,
bool
reshape
)
{
EpochsCompleted
=
0
;
IndexInEpoch
=
0
;
NumOfExamples
=
(
int
)
images
.
dims
[
0
]
;
// images = images.reshape((images.dims[0], images.dims[1] * images.dims[2]));
images
=
images
.
astype
(
dataType
)
;
// for debug np.multiply performance
var
sw
=
new
Stopwatch
(
)
;
sw
.
Start
(
)
;
images
=
np
.
multiply
(
images
,
1.0f
/
255.0f
)
;
sw
.
Stop
(
)
;
Binding
.
tf_output_redirect
.
WriteLine
(
$
"
{
sw
.
ElapsedMilliseconds
}
ms"
)
;
Data
=
images
;
labels
=
labels
.
astype
(
dataType
)
;
Labels
=
labels
;
}
public
(
NDArray
,
NDArray
)
GetNextBatch
(
int
batch_size
,
bool
fake_data
=
false
,
bool
shuffle
=
true
)
{
if
(
IndexInEpoch
>=
NumOfExamples
)
IndexInEpoch
=
0
;
var
start
=
IndexInEpoch
;
// Shuffle for the first epoch
if
(
EpochsCompleted
==
0
&&
start
==
0
&&
shuffle
)
{
var
perm0
=
np
.
arange
(
NumOfExamples
)
;
np
.
random
.
shuffle
(
perm0
)
;
Data
=
Data
[
perm0
]
;
Labels
=
Labels
[
perm0
]
;
}
// Go to the next epoch
if
(
start
+
batch_size
>
NumOfExamples
)
{
// Finished epoch
EpochsCompleted
+=
1
;
// Get the rest examples in this epoch
var
rest_num_examples
=
NumOfExamples
-
start
;
var
images_rest_part
=
Data
[
np
.
arange
(
start
,
NumOfExamples
)
]
;
var
labels_rest_part
=
Labels
[
np
.
arange
(
start
,
NumOfExamples
)
]
;
// Shuffle the data
if
(
shuffle
)
{
var
perm
=
np
.
arange
(
NumOfExamples
)
;
np
.
random
.
shuffle
(
perm
)
;
Data
=
Data
[
perm
]
;
Labels
=
Labels
[
perm
]
;
}
start
=
0
;
IndexInEpoch
=
batch_size
-
rest_num_examples
;
var
end
=
IndexInEpoch
;
var
images_new_part
=
Data
[
np
.
arange
(
start
,
end
)
]
;
var
labels_new_part
=
Labels
[
np
.
arange
(
start
,
end
)
]
;
return
(
np
.
concatenate
(
new
[
]
{
images_rest_part
,
images_new_part
}
,
axis
:
0
)
,
np
.
concatenate
(
new
[
]
{
labels_rest_part
,
labels_new_part
}
,
axis
:
0
)
)
;
}
else
{
IndexInEpoch
+=
batch_size
;
var
end
=
IndexInEpoch
;
return
(
Data
[
np
.
arange
(
start
,
end
)
]
,
Labels
[
np
.
arange
(
start
,
end
)
]
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL