FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/test/TensorFlowNET.Graph.UnitTest/ImageTest.cs at master · mishun/TensorFlow.NET · GitHub
mishun
/
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
/
test
/
TensorFlowNET.Graph.UnitTest
/
ImageTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (85 loc) · 3.53 KB
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.Graph.UnitTest
/
ImageTest.cs
Copy path
File metadata and controls
96 lines (85 loc) · 3.53 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
86
87
88
89
90
91
92
93
94
95
96
using
Microsoft
.
VisualStudio
.
TestTools
.
UnitTesting
;
using
Tensorflow
.
NumPy
;
using
System
.
Linq
;
using
Tensorflow
;
using
static
Tensorflow
.
Binding
;
namespace
TensorFlowNET
.
UnitTest
{
/// <summary>
/// Find more examples in https://www.programcreek.com/python/example/90444/tensorflow.read_file
/// </summary>
[
TestClass
]
public
class
ImageTest
:
GraphModeTestBase
{
string
imgPath
=
"shasta-daisy.jpg"
;
Tensor
contents
;
[
TestInitialize
]
public
void
Initialize
(
)
{
imgPath
=
TestHelper
.
GetFullPathFromDataDir
(
imgPath
)
;
contents
=
tf
.
io
.
read_file
(
imgPath
)
;
}
[
TestMethod
]
public
void
decode_image
(
)
{
var
img
=
tf
.
image
.
decode_image
(
contents
)
;
Assert
.
AreEqual
(
img
.
name
,
"decode_image/DecodeImage:0"
)
;
}
[
TestMethod
]
public
void
resize_image
(
)
{
tf
.
enable_eager_execution
(
)
;
var
image
=
tf
.
constant
(
new
int
[
5
,
5
]
{
{
1
,
0
,
0
,
0
,
0
}
,
{
0
,
1
,
0
,
0
,
0
}
,
{
0
,
0
,
1
,
0
,
0
}
,
{
0
,
0
,
0
,
1
,
0
}
,
{
0
,
0
,
0
,
0
,
1
}
}
)
;
image
=
image
[
tf
.
newaxis
,
tf
.
ellipsis
,
tf
.
newaxis
]
;
image
=
tf
.
image
.
resize
(
image
,
(
3
,
5
)
)
;
image
=
image
[
0
,
tf
.
ellipsis
,
0
]
;
Assert
.
IsTrue
(
Enumerable
.
SequenceEqual
(
new
float
[
]
{
0.6666667f
,
0.3333333f
,
0
,
0
,
0
}
,
image
[
0
]
.
ToArray
<
float
>
(
)
)
)
;
Assert
.
IsTrue
(
Enumerable
.
SequenceEqual
(
new
float
[
]
{
0
,
0
,
1
,
0
,
0
}
,
image
[
1
]
.
ToArray
<
float
>
(
)
)
)
;
Assert
.
IsTrue
(
Enumerable
.
SequenceEqual
(
new
float
[
]
{
0
,
0
,
0
,
0.3333335f
,
0.6666665f
}
,
image
[
2
]
.
ToArray
<
float
>
(
)
)
)
;
tf
.
compat
.
v1
.
disable_eager_execution
(
)
;
}
[
TestMethod
]
public
void
TestCropAndResize
(
)
{
var
graph
=
tf
.
Graph
(
)
.
as_default
(
)
;
// 3x3 'Image' with numbered coordinates
var
input
=
np
.
array
(
0f
,
1f
,
2f
,
3f
,
4f
,
5f
,
6f
,
7f
,
8f
)
;
var
image
=
tf
.
reshape
(
input
,
new
int
[
]
{
1
,
3
,
3
,
1
}
)
;
// 4x4 'Image' with numbered coordinates
var
input2
=
np
.
array
(
0f
,
1f
,
2f
,
3f
,
4f
,
5f
,
6f
,
7f
,
8f
,
9f
,
10f
,
11f
,
12f
,
13f
,
14f
,
15f
)
;
var
image2
=
tf
.
reshape
(
input2
,
new
int
[
]
{
1
,
4
,
4
,
1
}
)
;
// create one box over the full image that flips it (y1 > y2)
var
box
=
tf
.
reshape
(
np
.
array
(
1f
,
0f
,
0f
,
1f
)
,
new
int
[
]
{
1
,
4
}
)
;
var
boxInd
=
tf
.
Variable
(
np
.
array
(
0
)
)
;
// crop first 3x3 imageto size 1x1
var
cropSize1_1
=
tf
.
Variable
(
np
.
array
(
1
,
1
)
)
;
// don't crop second 4x4 image
var
cropSize2_2
=
tf
.
Variable
(
np
.
array
(
4
,
4
)
)
;
var
init
=
tf
.
global_variables_initializer
(
)
;
using
(
Session
sess
=
tf
.
Session
(
)
)
{
sess
.
run
(
init
)
;
var
cropped
=
tf
.
image
.
crop_and_resize
(
image
,
box
,
boxInd
,
cropSize1_1
)
;
var
result
=
sess
.
run
(
cropped
)
;
// check if cropped to 1x1 center was succesfull
Assert
.
AreEqual
(
result
.
size
,
1ul
)
;
Assert
.
AreEqual
(
result
[
0
,
0
,
0
,
0
]
,
4f
)
;
cropped
=
tf
.
image
.
crop_and_resize
(
image2
,
box
,
boxInd
,
cropSize2_2
)
;
result
=
sess
.
run
(
cropped
)
;
// check if flipped and no cropping occured
Assert
.
AreEqual
(
result
.
size
,
16ul
)
;
Assert
.
AreEqual
(
result
[
0
,
0
,
0
,
0
]
,
12f
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL