Skip to content

Commit

Permalink
Releasing 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
karllessard authored Aug 30, 2021
2 parents 2744e6c + 1ce2dda commit 307b672
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 168 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ systems, you should add the following dependencies:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<classifier>linux-x86_64${javacpp.platform.extension}</classifier>
</dependency>
```
Expand All @@ -77,24 +77,24 @@ native dependencies as follows:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<classifier>linux-x86_64${javacpp.platform.extension}</classifier>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<classifier>macosx-x86_64${javacpp.platform.extension}</classifier>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-api</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<classifier>windows-x86_64${javacpp.platform.extension}</classifier>
</dependency>
```
Expand All @@ -107,7 +107,7 @@ artifact includes transitively all the artifacts above as a single dependency:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-platform${javacpp.platform.extension}</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</dependency>
```

Expand Down Expand Up @@ -152,6 +152,7 @@ This table shows the mapping between different version of TensorFlow for Java an
| 0.3.0 | 2.4.1 |
| 0.3.1 | 2.4.1 |
| 0.3.2 | 2.4.1 |
| 0.3.3 | 2.4.1 |

## How to Contribute?

Expand Down
2 changes: 1 addition & 1 deletion ndarray/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To import the NdArray library in your project, simply add the following dependen
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>ndarray</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ndarray/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</parent>
<artifactId>ndarray</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
<packaging>pom</packaging>

<name>TensorFlow Java Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion tensorflow-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</parent>
<artifactId>tensorflow-core</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion tensorflow-core/tensorflow-core-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core</artifactId>
<version>0.3.2</version>
<version>0.3.3</version>
</parent>
<artifactId>tensorflow-core-api</artifactId>
<packaging>jar</packaging>
Expand Down
11 changes: 0 additions & 11 deletions tensorflow-core/tensorflow-core-api/pom.xml.asc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,18 @@ public Output<?>[] whileLoop(
synchronized SaverDef saverDef() {
if (saverDef == null) {
// Check to see if this graph has a restore operation
if (operation("save/restore_all") == null) {
if (operation(SAVER_DEF_SCOPE + "/" + SAVER_DEF_RESTORE_OP) == null) {
// No saver, create one by mutating the graph
saverDef = addVariableSaver(this);
} else {
// This graph already has saving/restoring operations,
// regenerate SaverDef without mutating. The names mirror
// the python implementation for compatibility.
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/training/saver.py
saverDef = SaverDef.newBuilder()
.setFilenameTensorName("save/filename")
.setSaveTensorName("save/control_dependency")
.setRestoreOpName("save/restore_all")
.build();
// regenerate SaverDef without mutating.
saverDef =
SaverDef.newBuilder()
.setFilenameTensorName(SAVER_DEF_SCOPE + "/" + SAVER_DEF_FILENAME_OP + ":0")
.setSaveTensorName(SAVER_DEF_SCOPE + "/" + SAVER_DEF_SAVE_OP)
.setRestoreOpName(SAVER_DEF_SCOPE + "/" + SAVER_DEF_RESTORE_OP)
.build();
}
}
return saverDef;
Expand Down Expand Up @@ -570,6 +569,13 @@ public void remove() {
private int position;
}

// These names mirror the python implementation, to reduce the risk of incompatibility.
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/training/saver.py
private static final String SAVER_DEF_SCOPE = "save";
private static final String SAVER_DEF_FILENAME_OP = "filename";
private static final String SAVER_DEF_SAVE_OP = "control_dependency";
private static final String SAVER_DEF_RESTORE_OP = "restore_all";

private static TF_Graph allocate() {
return TF_NewGraph();
}
Expand Down Expand Up @@ -797,7 +803,7 @@ private static Object[] whileLoop(
}

private static SaverDef addVariableSaver(Graph graph) {
Ops tf = Ops.create(graph).withSubScope("save");
Ops tf = Ops.create(graph).withSubScope(SAVER_DEF_SCOPE);

List<String> varNames = new ArrayList<>();
List<Operand<?>> varOutputs = new ArrayList<>();
Expand All @@ -812,36 +818,35 @@ private static SaverDef addVariableSaver(Graph graph) {
}
}

// FIXME Need an easier way to initialize an NdArray from a list
String[] tmp = new String[varNames.size()];
Constant<TString> varNamesTensor = tf.constant(StdArrays.ndCopyOf(varNames.toArray(tmp)));
Operand<TString> varSlices = tf.zerosLike(varNamesTensor);

Placeholder<TString> saveFilename = tf.withName("filename").placeholder(TString.class);
Save saveVariables = tf.train.save(
saveFilename,
varNamesTensor,
varSlices,
varOutputs
);
Identity<TString> id = tf.withControlDependencies(Arrays.asList(saveFilename,saveVariables))
.withName("control_dependency").identity(saveFilename);
Restore restoreVariables = tf.train.restore(
saveFilename,
varNamesTensor,
varSlices,
varTypes
);
List<Op> restoreOps = new ArrayList<>(varOutputs.size());
for (int i = 0; i < varOutputs.size(); ++i) {
restoreOps.add(tf.assign(varOutputs.get(i), (Operand) restoreVariables.tensors().get(i)));
Placeholder<TString> filename = tf.withName(SAVER_DEF_FILENAME_OP).placeholder(TString.class);
Identity<TString> save = null;
NoOp restore = null;

if (varNames.isEmpty()) {
save = tf.withName(SAVER_DEF_SAVE_OP).identity(filename);
restore = tf.withName(SAVER_DEF_RESTORE_OP).noOp();
} else {
String[] tmp = new String[varNames.size()];
Constant<TString> varNamesTensor = tf.constant(StdArrays.ndCopyOf(varNames.toArray(tmp)));
Operand<TString> varSlices = tf.zerosLike(varNamesTensor);
Save saveVars = tf.train.save(filename, varNamesTensor, varSlices, varOutputs);
List<Op> saveDeps = Arrays.asList(filename, saveVars);
Restore restoreVars = tf.train.restore(filename, varNamesTensor, varSlices, varTypes);
List<Op> restoreDeps = new ArrayList<>(varOutputs.size());
for (int i = 0; i < varOutputs.size(); ++i) {
restoreDeps.add(tf.assign(varOutputs.get(i), (Operand) restoreVars.tensors().get(i)));
}
save = tf.withControlDependencies(saveDeps).withName(SAVER_DEF_SAVE_OP).identity(filename);
restore = tf.withControlDependencies(restoreDeps).withName(SAVER_DEF_RESTORE_OP).noOp();
}
NoOp restoreAll = tf.withControlDependencies(restoreOps).withName("restore_all").noOp();

// 'Filename' must be the name of a tensor (i.e. with output index)
// 'Save' must be an operation name, even if the field name is confusing (see SaverDef doc)
// 'Restore' must be an operation name
return SaverDef.newBuilder()
.setFilenameTensorName(saveFilename.op().name())
.setSaveTensorName(id.op().name())
.setRestoreOpName(restoreAll.op().name())
.setFilenameTensorName(filename.output().name())
.setSaveTensorName(save.op().name())
.setRestoreOpName(restore.op().name())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public int index() {
return index;
}

/** Returns the full name of this Output (a.k.a. tensor name) */
public String name() {
return op().name() + ":" + index;
}

/** Returns the DataType of the tensor referred to by this Output. */
@SuppressWarnings("unchecked")
public DataType dataType() {
Expand All @@ -48,7 +53,7 @@ public DataType dataType() {
@SuppressWarnings("unchecked")
@Override
public Class<T> type() {
return (Class<T>)TensorTypeRegistry.find(dataType()).type();
return (Class<T>) TensorTypeRegistry.find(dataType()).type();
}

/**
Expand All @@ -63,7 +68,10 @@ public Class<T> type() {
public <U extends TType> Output<U> expect(Class<U> type) {
if (type != type()) {
throw new IllegalArgumentException(
"Cannot cast from output of " + this.type().getSimpleName() + " to output of " + type.getSimpleName());
"Cannot cast from output of "
+ this.type().getSimpleName()
+ " to output of "
+ type.getSimpleName());
}
return ((Output<U>) this);
}
Expand All @@ -80,17 +88,16 @@ public <U extends TType> Output<U> expect(Class<U> type) {
*
* @return tensor
* @throws IllegalStateException if this output results from a graph
* @throws ClassCastException if the type of the tensor and this output are unexpectedly incompatible
* @throws ClassCastException if the type of the tensor and this output are unexpectedly
* incompatible
* @see EagerSession
*/
@SuppressWarnings("unchecked")
public T asTensor() {
return (T)operation.tensor(index);
return (T) operation.tensor(index);
}

/**
* Returns the (possibly partially known) shape of the tensor referred to by this output.
*/
/** Returns the (possibly partially known) shape of the tensor referred to by this output. */
@Override
public Shape shape() {
return operation.shape(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.PointerScope;
Expand Down Expand Up @@ -432,7 +433,7 @@ private static SavedModelBundle load(
}

private static void validateTags(String[] tags) {
if (tags == null || Arrays.stream(tags).anyMatch(t -> t == null || t.isEmpty())) {
if (tags == null || Arrays.stream(tags).anyMatch(Objects::isNull)) {
throw new IllegalArgumentException("Invalid tags: " + Arrays.toString(tags));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* Copyright 2020 The TensorFlow Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Copyright 2020-2021 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=======================================================================
*/
package org.tensorflow;

import java.util.HashMap;
Expand Down Expand Up @@ -171,7 +171,7 @@ public Set<String> outputNames() {

@Override
public String toString() {
StringBuilder strBuilder = new StringBuilder("Signature for \"" + key +"\":\n");
StringBuilder strBuilder = new StringBuilder("Signature for \"" + key + "\":\n");
String methodName = methodName();
if (methodName != null && !methodName.isEmpty()) {
strBuilder.append("\tMethod: \"").append(methodName).append("\"\n");
Expand Down
Loading

0 comments on commit 307b672

Please sign in to comment.