Skip to content

Shape proto fix #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -15,7 +15,7 @@
<description>Platform-dependent native code and pure-Java code for the TensorFlow machine intelligence library.</description>

<properties>
<ndarray.version>1.0.0-rc.1</ndarray.version>
<ndarray.version>1.0.0</ndarray.version>
<truth.version>1.1.5</truth.version>
<test.download.skip>false</test.download.skip>
<test.download.folder>${project.build.directory}/tf-text-download/</test.download.folder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,15 @@ public Signature build() {
return new Signature(key, signatureBuilder.build());
}

private static TensorInfo toTensorInfo(Output<?> operand) {
static TensorInfo toTensorInfo(Output<?> operand) {
Shape shape = operand.shape();
TensorShapeProto.Builder tensorShapeBuilder = TensorShapeProto.newBuilder();
for (int i = 0; i < shape.numDimensions(); ++i) {
tensorShapeBuilder.addDim(Dim.newBuilder().setSize(shape.size(i)));
if (shape.isUnknown()) {
tensorShapeBuilder.setUnknownRank(true);
} else {
for (int i = 0; i < shape.numDimensions(); ++i) {
tensorShapeBuilder.addDim(Dim.newBuilder().setSize(shape.get(i)));
}
}
return TensorInfo.newBuilder()
.setDtype(operand.dataType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.tensorflow.Signature.TensorDescription;
import org.tensorflow.ndarray.Shape;
import org.tensorflow.op.Ops;
import org.tensorflow.op.core.Placeholder;
import org.tensorflow.op.math.Sign;
import org.tensorflow.proto.DataType;
import org.tensorflow.types.TInt32;

public class SignatureTest {

Expand Down Expand Up @@ -80,4 +84,28 @@ public void emptyMethodNameConvertedToNull() {
signature = Signature.builder().key("f").methodName(null).build();
assertNull(signature.methodName());
}

@Test
public void createTensorInfoFromOperandWithUnknownShape() {
try (Graph g = new Graph()) {
var tf = Ops.create(g);
var placeholder = tf.placeholder(TInt32.class);
var tensorInfo = Signature.Builder.toTensorInfo(placeholder.asOutput());
assertTrue(tensorInfo.getTensorShape().getUnknownRank());
assertEquals(0, tensorInfo.getTensorShape().getDimCount());
}
}

@Test
public void createTensorInfoFromOperandWithPartiallyUnknownShape() {
try (Graph g = new Graph()) {
var tf = Ops.create(g);
var placeholder = tf.placeholder(TInt32.class, Placeholder.shape(Shape.of(Shape.UNKNOWN_SIZE, 10)));
var tensorInfo = Signature.Builder.toTensorInfo(placeholder.asOutput());
assertFalse(tensorInfo.getTensorShape().getUnknownRank());
assertEquals(2, tensorInfo.getTensorShape().getDimCount());
assertEquals(-1, tensorInfo.getTensorShape().getDim(0).getSize());
assertEquals(10, tensorInfo.getTensorShape().getDim(1).getSize());
}
}
}
Loading