공개 최종 클래스 초기화
상수
끈 | DEFAULT_NAME |
공개 방법
정적 공백 | |
정적 초기화 |
상속된 메서드
상수
공개 정적 최종 문자열 DEFAULT_NAME
상수 값: "초기화"
공개 방법
public static Init create ( 범위 범위)
그래프의 모든 초기화 프로그램을 실행하는 작업을 생성하는 팩토리 메서드입니다.
tf.initAdd
통해 그래프에 추가된 모든 초기화 프로그램은 그래프에서 단일 계산 단위로 그룹화됩니다. 그런 다음 이 작업을 하나 이상의 variables
사용하여 그래프에 추가하고 그래프를 실행하기 전에 한 번 실행하여 변수 상태가 올바르게 초기화되도록 해야 합니다.
세션을 실행하는 동일한 프로세스에 의해 그래프가 작성되면 이 단일 끝점을 실행하여 이니셜라이저를 호출할 수 있습니다. 예를 들어:
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());
}
}
}
그래프가 별도의 프로세스에 의해 빌드되면 초기화 작업을 해당 이름으로 실행하여 초기화 프로그램을 호출할 수 있으며 기본값은 DEFAULT_NAME
입니다. 예를 들어:
// 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());
}
}
}
매개변수
범위 | 현재 범위 |
---|
보고
- 그래프에 추가된 모든 초기화 프로그램을 그룹화하는 작업
던지기
IllegalArgumentException | 범위 내의 실행 환경이 그래프가 아닌 경우 |
---|