Init
Stay organized with collections
Save and categorize content based on your preferences.
Public Methods
static
void
|
add( Scope scope, Op initializer)
Register an op as an initializer of the graph.
|
static
Init
|
create( Scope scope)
Factory method to create an operation executing all initializers of a graph.
|
Inherited Methods
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Constants
public
static
final
String
DEFAULT_NAME
Public Methods
public
static
void
add
(Scope scope, Op initializer)
Register an op as an initializer of the graph.
Registered initializers are then grouped as a single unit of computation by adding
and executing an init
operation from a graph
session. This is a no-op if executed in an eager session.
public
static
Init
create
(Scope scope)
Factory method to create an operation executing all initializers of a graph.
All initializers added to a graph via
tf.initAdd
are grouped together as a single
unit of computation in the graph. This operation must then be added to any graph using one or
more variables
and executed once before running the graph so the variable
states are initialized properly.
When the graph is built by the same process that is running the session, the initializers
can be invoked by executing this single endpoint. For example:
try (Graph g = new Graph()) {
Variable<TInt32> x = tf.variable(tf.constant(10)); // initAdd is called implicitly
Variable<TInt32> y = tf.variable(tf.constant(20)); // idem
Add<TInt32> z = tf.math.add(x, y);
try (Session s = new Session(g)) {
s.run(tf.init()); // initialize all variables
try (TInt32 t = (TInt32)s.runner().fetch(z).run().get(0)) {
assertEquals(30, t.data().getInt());
}
}
}
When the graph is built by a separate process, the initializers can be invoked by running
the init op by its name, which defaults to DEFAULT_NAME
.
For example:
// Building the model
try (Graph g = new Graph()) {
Variable<TInt32> x = tf.variable(tf.constant(10)); // initAdd is called implicitly
Variable<TInt32> y = tf.variable(tf.constant(20)); // idem
Add<TInt32> z = tf.withName("z").math.add(x, y);
tf.init(); // add variables initializers to the graph, as Init.DEFAULT_NAME
// ...exporting graph as a saved model...
...
// Running the model
try (SavedModelBundle model = SavedModelBundle.load("/path/to/model", "train")) {
model.session().run(Init.DEFAULT_NAME);
try (TInt32 t = (TInt32)s.runner().fetch("z").run().get(0)) {
assertEquals(30, t.data().getInt());
}
}
}
Returns
- an op grouping all initializers added to the graph
Throws
IllegalArgumentException |
if the execution environment in scope is not a graph
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-11-29 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-11-29 UTC."],[],[],null,["# Init\n\npublic final class **Init** \n\n### Constants\n\n|--------|-----------------------------------------------------------------------------|---|\n| String | [DEFAULT_NAME](/jvm/api_docs/java/org/tensorflow/op/core/Init#DEFAULT_NAME) | |\n\n### Public Methods\n\n|---------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static void | [add](/jvm/api_docs/java/org/tensorflow/op/core/Init#add(org.tensorflow.op.Scope, org.tensorflow.op.Op))([Scope](/jvm/api_docs/java/org/tensorflow/op/Scope) scope, [Op](/jvm/api_docs/java/org/tensorflow/op/Op) initializer) Register an op as an initializer of the graph. |\n| static [Init](/jvm/api_docs/java/org/tensorflow/op/core/Init) | [create](/jvm/api_docs/java/org/tensorflow/op/core/Init#create(org.tensorflow.op.Scope))([Scope](/jvm/api_docs/java/org/tensorflow/op/Scope) scope) Factory method to create an operation executing all initializers of a graph. |\n\n### Inherited Methods\n\nFrom class [org.tensorflow.op.RawOp](/jvm/api_docs/java/org/tensorflow/op/RawOp) \n\n|----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| final boolean | [equals](/jvm/api_docs/java/org/tensorflow/op/RawOp#equals(java.lang.Object))(Object obj) |\n| final int | [hashCode](/jvm/api_docs/java/org/tensorflow/op/RawOp#hashCode())() |\n| [Operation](/jvm/api_docs/java/org/tensorflow/Operation) | [op](/jvm/api_docs/java/org/tensorflow/op/RawOp#op())() Return this unit of computation as a single [Operation](/jvm/api_docs/java/org/tensorflow/Operation). |\n| final String | [toString](/jvm/api_docs/java/org/tensorflow/op/RawOp#toString())() |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface [org.tensorflow.op.Op](/jvm/api_docs/java/org/tensorflow/op/Op) \n\n|-----------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [ExecutionEnvironment](/jvm/api_docs/java/org/tensorflow/ExecutionEnvironment) | [env](/jvm/api_docs/java/org/tensorflow/op/Op#env())() Return the execution environment this op was created in. |\n| abstract [Operation](/jvm/api_docs/java/org/tensorflow/Operation) | [op](/jvm/api_docs/java/org/tensorflow/op/Op#op())() Return this unit of computation as a single [Operation](/jvm/api_docs/java/org/tensorflow/Operation). |\n\nConstants\n---------\n\n#### public static final String\n**DEFAULT_NAME**\n\n\u003cbr /\u003e\n\nConstant Value: \"init\"\n\nPublic Methods\n--------------\n\n#### public static void\n**add**\n([Scope](/jvm/api_docs/java/org/tensorflow/op/Scope) scope, [Op](/jvm/api_docs/java/org/tensorflow/op/Op) initializer)\n\nRegister an op as an initializer of the graph.\n\nRegistered initializers are then grouped as a single unit of computation by adding\nand executing an [init](/jvm/api_docs/java/org/tensorflow/op/core/Init#create(org.tensorflow.op.Scope)) operation from a graph\nsession. This is a no-op if executed in an eager session.\n\n\u003cbr /\u003e\n\n##### See Also\n\n- [init](/jvm/api_docs/java/org/tensorflow/op/core/Init#create(org.tensorflow.op.Scope)) \n\n#### public static [Init](/jvm/api_docs/java/org/tensorflow/op/core/Init)\n**create**\n([Scope](/jvm/api_docs/java/org/tensorflow/op/Scope) scope)\n\nFactory method to create an operation executing all initializers of a graph.\n\nAll initializers added to a graph via\n[tf.initAdd](/jvm/api_docs/java/org/tensorflow/op/core/Init#add(org.tensorflow.op.Scope, org.tensorflow.op.Op)) are grouped together as a single\nunit of computation in the graph. This operation must then be added to any graph using one or\nmore [variables](/jvm/api_docs/java/org/tensorflow/op/core/Variable) and executed once before running the graph so the variable\nstates are initialized properly.\n\nWhen the graph is built by the same process that is running the session, the initializers\ncan be invoked by executing this single endpoint. For example: \n\n try (Graph g = new Graph()) {\n Variable\u003cTInt32\u003e x = tf.variable(tf.constant(10)); // initAdd is called implicitly\n Variable\u003cTInt32\u003e y = tf.variable(tf.constant(20)); // idem\n Add\u003cTInt32\u003e z = tf.math.add(x, y);\n\n try (Session s = new Session(g)) {\n s.run(tf.init()); // initialize all variables\n\n try (TInt32 t = (TInt32)s.runner().fetch(z).run().get(0)) {\n assertEquals(30, t.data().getInt());\n \n }\n }\n }\n\nWhen the graph is built by a separate process, the initializers can be invoked by running\nthe init op by its name, which defaults to [DEFAULT_NAME](/jvm/api_docs/java/org/tensorflow/op/core/Init#DEFAULT_NAME).\nFor example: \n\n // Building the model\n try (Graph g = new Graph()) {\n Variable\u003cTInt32\u003e x = tf.variable(tf.constant(10)); // initAdd is called implicitly\n Variable\u003cTInt32\u003e y = tf.variable(tf.constant(20)); // idem\n Add\u003cTInt32\u003e z = tf.withName(\"z\").math.add(x, y);\n\n tf.init(); // add variables initializers to the graph, as Init.DEFAULT_NAME\n // ...exporting graph as a saved model...\n \n\n ...\n\n // Running the model\n try (SavedModelBundle model = SavedModelBundle.load(\"/path/to/model\", \"train\")) {\n model.session().run(Init.DEFAULT_NAME);\n\n try (TInt32 t = (TInt32)s.runner().fetch(\"z\").run().get(0)) {\n assertEquals(30, t.data().getInt());\n }\n }\n }\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| scope | current scope |\n|-------|---------------|\n\n##### Returns\n\n- an op grouping all initializers added to the graph \n\n##### Throws\n\n| IllegalArgumentException | if the execution environment in scope is not a graph |\n|--------------------------|------------------------------------------------------|"]]