CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-tensorflow--proto

Generated Java code for TensorFlow protocol buffers, providing type-safe access to TensorFlow's structured data formats including MetaGraphDef, ConfigProto, and other core TensorFlow data structures.

Overview
Eval results
Files

core-framework.mddocs/

Core Framework

The core framework types provide the fundamental data structures for TensorFlow graphs, tensors, operations, and computational definitions. These are the primary building blocks for representing TensorFlow computation graphs and tensor data.

Capabilities

TensorProto

Protocol buffer representing a tensor with data and metadata.

/**
 * Protocol buffer representing a tensor with data and metadata
 */
class TensorProto {
  /** Get the tensor data type */
  DataType getDtype();
  
  /** Get the shape of the tensor */
  TensorShapeProto getTensorShape(); 
  
  /** Get version number for compatibility */
  int getVersionNumber();
  
  /** Get serialized raw tensor content */
  ByteString getTensorContent();
  
  /** Get float values for DT_FLOAT tensors */
  List<Float> getFloatValList();
  
  /** Get integer values for DT_INT32 tensors */
  List<Integer> getIntValList();
  
  /** Get double values for DT_DOUBLE tensors */
  List<Double> getDoubleValList();
  
  /** Get string values for DT_STRING tensors */
  List<ByteString> getStringValList();
  
  /** Get boolean values for DT_BOOL tensors */
  List<Boolean> getBoolValList();
  
  /** Get long values for DT_INT64 tensors */
  List<Long> getInt64ValList();
  
  /** Get half precision values for DT_HALF tensors */
  List<Integer> getHalfValList();
  
  /** Get single-precision complex values for DT_COMPLEX64 tensors */
  List<Float> getSComplexValList();
  
  /** Get double-precision complex values for DT_COMPLEX128 tensors */
  List<Double> getDComplexValList();
  
  /** Get unsigned 32-bit integer values for DT_UINT32 tensors */
  List<Integer> getUint32ValList();
  
  /** Get unsigned 64-bit integer values for DT_UINT64 tensors */
  List<Long> getUint64ValList();
  
  /** Get resource handle values for DT_RESOURCE tensors */
  List<ResourceHandleProto> getResourceHandleValList();
  
  /** Get variant tensor data for DT_VARIANT tensors */
  List<VariantTensorDataProto> getVariantValList();
  
  /** Create a new builder for constructing TensorProto */
  static Builder newBuilder();
  
  /** Builder for constructing TensorProto instances */
  static class Builder {
    Builder setDtype(DataType dtype);
    Builder setTensorShape(TensorShapeProto shape);
    Builder setVersionNumber(int version);
    Builder setTensorContent(ByteString content);
    Builder addFloatVal(float value);
    Builder addIntVal(int value);
    Builder addDoubleVal(double value);
    Builder addStringVal(ByteString value);
    Builder addBoolVal(boolean value);
    Builder addInt64Val(long value);
    Builder addHalfVal(int value);
    Builder addSComplexVal(float value);
    Builder addDComplexVal(double value);
    Builder addUint32Val(int value);
    Builder addUint64Val(long value);
    Builder addResourceHandleVal(ResourceHandleProto value);
    Builder addVariantVal(VariantTensorDataProto value);
    TensorProto build();
  }
}

Usage Examples:

import org.tensorflow.framework.*;

// Create a float tensor with shape [3]
TensorProto floatTensor = TensorProto.newBuilder()
    .setDtype(DataType.DT_FLOAT)
    .setTensorShape(TensorShapeProto.newBuilder()
        .addDim(TensorShapeProto.Dim.newBuilder().setSize(3)))
    .addFloatVal(1.0f)
    .addFloatVal(2.0f)
    .addFloatVal(3.0f)
    .build();

// Create a string tensor
TensorProto stringTensor = TensorProto.newBuilder()
    .setDtype(DataType.DT_STRING)
    .setTensorShape(TensorShapeProto.newBuilder()
        .addDim(TensorShapeProto.Dim.newBuilder().setSize(2)))
    .addStringVal(ByteString.copyFromUtf8("hello"))
    .addStringVal(ByteString.copyFromUtf8("world"))
    .build();

// Create tensor from raw bytes (more efficient for large tensors)
ByteString rawData = ByteString.copyFrom(new byte[]{1, 2, 3, 4});
TensorProto rawTensor = TensorProto.newBuilder()
    .setDtype(DataType.DT_UINT8)
    .setTensorShape(TensorShapeProto.newBuilder()
        .addDim(TensorShapeProto.Dim.newBuilder().setSize(4)))
    .setTensorContent(rawData)
    .build();

GraphDef

Represents the complete computation graph of operations.

/**
 * Represents the computation graph of operations
 */
class GraphDef {
  /** Get list of nodes in the graph */
  List<NodeDef> getNodeList();
  
  /** Get compatibility version information */
  VersionDef getVersions();
  
  /** Get deprecated single version field */
  @Deprecated
  int getVersion();
  
  /** Get user-defined functions library */
  FunctionDefLibrary getLibrary();
  
  /** Create a new builder for constructing GraphDef */
  static Builder newBuilder();
  
  /** Builder for constructing GraphDef instances */
  static class Builder {
    Builder addNode(NodeDef node);
    Builder addAllNode(Iterable<NodeDef> nodes);
    Builder setVersions(VersionDef versions);
    Builder setLibrary(FunctionDefLibrary library);
    GraphDef build();
  }
}

Usage Examples:

import org.tensorflow.framework.*;

// Create a simple graph with input and operation nodes
GraphDef graph = GraphDef.newBuilder()
    .addNode(NodeDef.newBuilder()
        .setName("input")
        .setOp("Placeholder")
        .putAttr("dtype", AttrValue.newBuilder()
            .setType(DataType.DT_FLOAT).build())
        .putAttr("shape", AttrValue.newBuilder()
            .setShape(TensorShapeProto.newBuilder()
                .addDim(TensorShapeProto.Dim.newBuilder().setSize(-1))
                .addDim(TensorShapeProto.Dim.newBuilder().setSize(784)))
            .build()))
    .addNode(NodeDef.newBuilder()
        .setName("weights")
        .setOp("Variable")
        .putAttr("dtype", AttrValue.newBuilder()
            .setType(DataType.DT_FLOAT).build())
        .putAttr("shape", AttrValue.newBuilder()
            .setShape(TensorShapeProto.newBuilder()
                .addDim(TensorShapeProto.Dim.newBuilder().setSize(784))
                .addDim(TensorShapeProto.Dim.newBuilder().setSize(10)))
            .build()))
    .addNode(NodeDef.newBuilder()
        .setName("matmul")
        .setOp("MatMul")
        .addInput("input")
        .addInput("weights"))
    .setVersions(VersionDef.newBuilder()
        .setProducer(26)
        .setMinConsumer(12))
    .build();

NodeDef

Defines a single node (operation) in the computation graph.

/**
 * Defines a single node (operation) in the computation graph
 */
class NodeDef {
  /** Get unique name of the node */
  String getName();
  
  /** Get operation name */
  String getOp();
  
  /** Get list of input tensor names */
  List<String> getInputList();
  
  /** Get device specification */
  String getDevice();
  
  /** Get operation attributes */
  Map<String, AttrValue> getAttrMap();
  
  /** Create a new builder for constructing NodeDef */
  static Builder newBuilder();
  
  /** Builder for constructing NodeDef instances */
  static class Builder {
    Builder setName(String name);
    Builder setOp(String op);
    Builder addInput(String input);
    Builder addAllInput(Iterable<String> inputs);
    Builder setDevice(String device);
    Builder putAttr(String key, AttrValue value);
    Builder putAllAttr(Map<String, AttrValue> attrs);
    NodeDef build();
  }
}

Usage Examples:

import org.tensorflow.framework.*;

// Create a placeholder node
NodeDef placeholder = NodeDef.newBuilder()
    .setName("input_data")
    .setOp("Placeholder")
    .putAttr("dtype", AttrValue.newBuilder()
        .setType(DataType.DT_FLOAT).build())
    .putAttr("shape", AttrValue.newBuilder()
        .setShape(TensorShapeProto.newBuilder()
            .addDim(TensorShapeProto.Dim.newBuilder().setSize(-1))
            .addDim(TensorShapeProto.Dim.newBuilder().setSize(256)))
        .build())
    .build();

// Create a constant node  
NodeDef constant = NodeDef.newBuilder()
    .setName("learning_rate")
    .setOp("Const")
    .putAttr("dtype", AttrValue.newBuilder()
        .setType(DataType.DT_FLOAT).build())
    .putAttr("value", AttrValue.newBuilder()
        .setTensor(TensorProto.newBuilder()
            .setDtype(DataType.DT_FLOAT)
            .addFloatVal(0.001f)
            .setTensorShape(TensorShapeProto.newBuilder()))
        .build())
    .build();

// Create a binary operation node with inputs
NodeDef multiply = NodeDef.newBuilder()
    .setName("scaled_output")
    .setOp("Mul")
    .addInput("dense_output")
    .addInput("learning_rate")
    .setDevice("/gpu:0")  // Specify device
    .build();

OpDef

Defines the interface for an operation type.

/**
 * Defines the interface for an operation type
 */
class OpDef {
  /** Get operation name */
  String getName();
  
  /** Get input argument specifications */
  List<ArgDef> getInputArgList();
  
  /** Get output argument specifications */
  List<ArgDef> getOutputArgList();
  
  /** Get attribute definitions */
  List<AttrDef> getAttrList();
  
  /** Get one-line description */
  String getSummary();
  
  /** Get detailed description */
  String getDescription();
  
  /** Check if operation is stateful (has side effects) */
  boolean getIsStateful();
  
  /** Check if operation is commutative */
  boolean getIsCommutative();
  
  /** Check if operation is aggregate (like Sum, Max) */
  boolean getIsAggregate();
  
  /**
   * Argument definition for inputs and outputs
   */
  static class ArgDef {
    String getName();
    String getDescription();
    DataType getType();
    String getTypeAttr();
    String getNumberAttr();
    String getTypeListAttr();
    boolean getIsRef();
  }
  
  /**
   * Attribute definition
   */
  static class AttrDef {
    String getName();
    String getType();
    String getDescription();
    AttrValue getDefaultValue();
    boolean getHasMinimum();
    long getMinimum();
    AttrValue getAllowedValues();
  }
}

FunctionDef

Defines a reusable function in TensorFlow.

/**
 * Defines a reusable function in TensorFlow
 */
class FunctionDef {
  /** Get function signature */
  OpDef getSignature();
  
  /** Get function body nodes */
  List<NodeDef> getNodeDefList();
  
  /** Get return value mapping from output name to node:output */
  Map<String, String> getRetMap();
  
  /** Get function attributes */
  Map<String, AttrValue> getAttrMap();
  
  /** Get argument attributes */
  Map<String, ArgAttrs> getArgAttrMap();
  
  /** Attributes for function arguments */
  static class ArgAttrs {
    Map<String, AttrValue> getAttrMap();
  }
}

FunctionDefLibrary

Library of function definitions for reusable operations.

/**
 * Library of function definitions
 */
class FunctionDefLibrary {
  /** Get list of function definitions */
  List<FunctionDef> getFunctionList();
  
  /** Get list of gradient definitions */
  List<GradientDef> getGradientList();
  
  /** Create a new builder */
  static Builder newBuilder();
  
  static class Builder {
    Builder addFunction(FunctionDef function);
    Builder addAllFunction(Iterable<FunctionDef> functions);
    Builder addGradient(GradientDef gradient);
    FunctionDefLibrary build();
  }
}

GradientDef

Defines gradient computation for a function.

/**
 * Gradient definition for a function
 */
class GradientDef {
  /** Get function name this gradient applies to */
  String getFunctionName();
  
  /** Get gradient function name */
  String getGradientFunc();
  
  /** Create a new builder */
  static Builder newBuilder();
  
  static class Builder {
    Builder setFunctionName(String name);
    Builder setGradientFunc(String func);
    GradientDef build();
  }
}

VersionDef

Version compatibility information for graphs.

/**
 * Version compatibility information
 */
class VersionDef {
  /** Producer version that created this graph */
  int getProducer();
  
  /** Minimum consumer version that can read this graph */
  int getMinConsumer();
  
  /** Consumer versions with known incompatibilities */
  List<Integer> getBadConsumersList();
}

Device and Performance Types

/**
 * Device attributes and capabilities
 */
class DeviceAttributes {
  String getName();
  String getDeviceType();
  long getMemoryLimit();
  DeviceLocality getLocality();
  long getIncarnation();
  String getPhysicalDeviceDesc();
}

/**
 * Step execution statistics
 */
class StepStats {
  List<DeviceStepStats> getDevStatssList();
  
  static class DeviceStepStats {
    String getDevice();
    List<NodeExecStats> getNodeStatsList();
  }
  
  /** Execution statistics for a single node */
  static class NodeExecStats {
    String getNodeName();
    long getAllStartMicros();
    long getOpStartRelMicros();
    long getOpEndRelMicros();
    long getAllEndRelMicros();
    List<AllocatorMemoryUsed> getMemoryList();
    List<NodeOutput> getOutputList();
    String getTimelineLabel();
    long getScheduledMicros();
    int getThreadId();
  }
}

VariantTensorDataProto

Protocol buffer representing variant tensor data for DT_VARIANT tensors.

/**
 * Serialization format for DT_VARIANT tensors
 */
class VariantTensorDataProto {
  /** Get the type name of objects being serialized */
  String getTypeName();
  
  /** Get serialized metadata (non-tensor portions) */
  ByteString getMetadata();
  
  /** Get tensors contained within the variant */
  List<TensorProto> getTensorsList();
  
  /** Create a new builder */
  static Builder newBuilder();
  
  static class Builder {
    Builder setTypeName(String typeName);
    Builder setMetadata(ByteString metadata);
    Builder addTensors(TensorProto tensor);
    Builder addAllTensors(Iterable<TensorProto> tensors);
    VariantTensorDataProto build();
  }
}

ResourceHandleProto

Protocol buffer representing a handle to a TensorFlow resource.

/**
 * Handle to a TensorFlow resource (not valid across executions)
 */
class ResourceHandleProto {
  /** Get device containing the resource */
  String getDevice();
  
  /** Get container in which resource is placed */
  String getContainer();
  
  /** Get unique name of this resource */
  String getName();
  
  /** Get hash code for the resource type */
  long getHashCode();
  
  /** Get debug type name (if available) */
  String getMaybeTypeName();
  
  /** Create a new builder */
  static Builder newBuilder();
  
  static class Builder {
    Builder setDevice(String device);
    Builder setContainer(String container);
    Builder setName(String name);
    Builder setHashCode(long hashCode);
    Builder setMaybeTypeName(String typeName);
    ResourceHandleProto build();
  }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-tensorflow--proto

docs

config-persistence.md

core-framework.md

data-examples.md

distributed-runtime.md

index.md

utilities.md

tile.json