Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imagej-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
imagej-elphel
Commits
4a29b844
Commit
4a29b844
authored
Sep 15, 2018
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+links
parent
68b38496
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
29 deletions
+98
-29
TensorflowExamplePlugin.java
src/main/java/TensorflowExamplePlugin.java
+98
-29
No files found.
src/main/java/TensorflowExamplePlugin.java
View file @
4a29b844
...
@@ -7,40 +7,109 @@ import org.tensorflow.Graph;
...
@@ -7,40 +7,109 @@ import org.tensorflow.Graph;
import
org.tensorflow.Session
;
import
org.tensorflow.Session
;
import
org.tensorflow.Tensor
;
import
org.tensorflow.Tensor
;
import
org.tensorflow.TensorFlow
;
import
org.tensorflow.TensorFlow
;
import
org.tensorflow.SavedModelBundle
;
/**
Note 0: articles & examples:
- https://divis.io/2017/11/enterprise-tensorflow-1/
- https://divis.io/2018/01/enterprise-tensorflow-code-examples/
- https://divis.io/2018/01/enterprise-tensorflow-2-saving-a-trained-model/
- https://divis.io/2018/01/enterprise-tensorflow-3-loading-a-savedmodel-in-java/
- https://divis.io/2018/01/enterprise-tensorflow-4-executing-a-tensorflow-session-in-java/
- https://www.programcreek.com/java-api-examples/?api=org.tensorflow.SavedModelBundle
- https://github.com/imagej/imagej-tensorflow
Note 1: How to feed:
a. https://divis.io/2018/01/enterprise-tensorflow-4-executing-a-tensorflow-session-in-java/
b. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java
Note 2: https://divis.io/2018/01/enterprise-tensorflow-4-executing-a-tensorflow-session-in-java/
...
Two types of objects will need manual closing for proper resource handling:
Sessions and Tensors
...
*/
public
class
TensorflowExamplePlugin
public
class
TensorflowExamplePlugin
{
{
public
void
run
()
public
final
static
String
EXPORTDIR
=
"/home/oleg/GIT/python3-imagej-tiff/data_sets/tf_data_5x5_main_13_heur/exportdir"
;
public
final
static
String
PB_TAG
=
"model_pb"
;
public
static
void
run
()
{
{
System
.
out
.
println
(
"TensorflowExamplePlugin run"
);
System
.
out
.
println
(
"TensorflowExamplePlugin run"
);
try
{
try
{
main
();
main
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
// TODO Auto-generated catch block
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
public
static
void
main
()
throws
Exception
{
public
static
void
main
()
throws
Exception
{
final
Graph
smpb
;
float
[][]
img_corr2d
=
new
float
[
78408
][
324
];
float
[][]
img_target
=
new
float
[
78408
][
1
];
int
[]
img_ntile
=
new
int
[
78408
];
// init ntile
for
(
int
i
=
0
;
i
<
img_ntile
.
length
;
i
++){
img_ntile
[
i
]
=
i
;
}
try
(
SavedModelBundle
b
=
SavedModelBundle
.
load
(
EXPORTDIR
,
PB_TAG
)){
System
.
out
.
println
(
"Alright"
);
smpb
=
b
.
graph
();
}
try
(
Graph
g
=
new
Graph
())
{
try
(
Graph
g
=
new
Graph
())
{
final
String
value
=
"Hello from "
+
TensorFlow
.
version
();
final
String
value
=
"Hello from "
+
TensorFlow
.
version
();
// Construct the computation graph with a single operation, a constant
// Construct the computation graph with a single operation, a constant
// named "MyConst" with a value "value".
// named "MyConst" with a value "value".
try
(
Tensor
t
=
Tensor
.
create
(
value
.
getBytes
(
"UTF-8"
)))
{
try
(
Tensor
t
=
Tensor
.
create
(
value
.
getBytes
(
"UTF-8"
)))
{
// The Java API doesn't yet include convenience functions for adding operations.
// The Java API doesn't yet include convenience functions for adding operations.
g
.
opBuilder
(
"Const"
,
"MyConst"
).
setAttr
(
"dtype"
,
t
.
dataType
()).
setAttr
(
"value"
,
t
).
build
();
g
.
opBuilder
(
"Const"
,
"MyConst"
).
setAttr
(
"dtype"
,
t
.
dataType
()).
setAttr
(
"value"
,
t
).
build
();
}
}
// Execute the "MyConst" operation in a Session.
// Execute the "MyConst" operation in a Session.
try
(
Session
s
=
new
Session
(
g
);
try
(
Session
s
=
new
Session
(
g
);
// Generally, there may be multiple output tensors, all of them must be closed to prevent resource leaks.
// Generally, there may be multiple output tensors, all of them must be closed to prevent resource leaks.
Tensor
output
=
s
.
runner
().
fetch
(
"MyConst"
).
run
().
get
(
0
))
{
Tensor
output
=
s
.
runner
().
fetch
(
"MyConst"
).
run
().
get
(
0
))
{
System
.
out
.
println
(
new
String
(
output
.
bytesValue
(),
"UTF-8"
));
System
.
out
.
println
(
new
String
(
output
.
bytesValue
(),
"UTF-8"
));
s
.
close
();
s
.
close
();
}
output
.
close
();
}
}
}
}
}
}
}
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