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

data-examples.mddocs/

Data Examples

Normalized data formats for representing training examples, feature vectors, and structured data inputs for machine learning models. These types are essential for data preprocessing, model training, and inference workflows.

Capabilities

Example

The primary data structure for representing training/inference examples with named features.

/**
 * Normalized data format for training/inference examples
 */
class Example {
  /** Get the features map */
  Features getFeatures();
  
  /** Create a new builder for constructing Example */
  static Builder newBuilder();
  
  /** Builder for constructing Example instances */
  static class Builder {
    Builder setFeatures(Features features);
    Example build();
  }
}

Usage Examples:

import org.tensorflow.example.*;

// Create a simple example with numeric and string features
Example userExample = Example.newBuilder()
    .setFeatures(Features.newBuilder()
        .putFeature("age", Feature.newBuilder()
            .setInt64List(Int64List.newBuilder().addValue(25))
            .build())
        .putFeature("height", Feature.newBuilder()
            .setFloatList(FloatList.newBuilder().addValue(175.5f))
            .build())
        .putFeature("name", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFromUtf8("Alice")))
            .build())
        .putFeature("interests", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFromUtf8("reading"))
                .addValue(ByteString.copyFromUtf8("hiking"))
                .addValue(ByteString.copyFromUtf8("coding")))
            .build()))
    .build();

// Create an image classification example
Example imageExample = Example.newBuilder()
    .setFeatures(Features.newBuilder()
        .putFeature("image_raw", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFrom(imageBytes)))
            .build())
        .putFeature("label", Feature.newBuilder()
            .setInt64List(Int64List.newBuilder().addValue(7))  // digit 7
            .build())
        .putFeature("height", Feature.newBuilder()
            .setInt64List(Int64List.newBuilder().addValue(28))
            .build())
        .putFeature("width", Feature.newBuilder()
            .setInt64List(Int64List.newBuilder().addValue(28))
            .build()))
    .build();

SequenceExample

Example representing sequences with context features (time-independent) and sequence features (time-dependent).

/**
 * Example representing sequences with context and sequence features
 */
class SequenceExample {
  /** Get time-independent context features */
  Features getContext();
  
  /** Get sequence features (time-dependent) */
  FeatureLists getFeatureLists();
  
  /** Create a new builder for constructing SequenceExample */
  static Builder newBuilder();
  
  /** Builder for constructing SequenceExample instances */
  static class Builder {
    Builder setContext(Features context);
    Builder setFeatureLists(FeatureLists featureLists);
    SequenceExample build();
  }
}

Usage Examples:

import org.tensorflow.example.*;

// Create a sequence example for text processing
SequenceExample textSequence = SequenceExample.newBuilder()
    .setContext(Features.newBuilder()
        .putFeature("document_id", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFromUtf8("doc_123")))
            .build())
        .putFeature("language", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFromUtf8("en")))
            .build()))
    .setFeatureLists(FeatureLists.newBuilder()
        .putFeatureList("tokens", FeatureList.newBuilder()
            .addFeature(Feature.newBuilder()
                .setBytesList(BytesList.newBuilder()
                    .addValue(ByteString.copyFromUtf8("hello")))
                .build())
            .addFeature(Feature.newBuilder()
                .setBytesList(BytesList.newBuilder()
                    .addValue(ByteString.copyFromUtf8("world")))
                .build())
            .build())
        .putFeatureList("pos_tags", FeatureList.newBuilder()
            .addFeature(Feature.newBuilder()
                .setBytesList(BytesList.newBuilder()
                    .addValue(ByteString.copyFromUtf8("INTJ")))
                .build())
            .addFeature(Feature.newBuilder()
                .setBytesList(BytesList.newBuilder()
                    .addValue(ByteString.copyFromUtf8("NOUN")))
                .build())
            .build()))
    .build();

// Create a time series example
SequenceExample timeSeriesExample = SequenceExample.newBuilder()
    .setContext(Features.newBuilder()
        .putFeature("series_id", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFromUtf8("sensor_001")))
            .build())
        .putFeature("location", Feature.newBuilder()
            .setBytesList(BytesList.newBuilder()
                .addValue(ByteString.copyFromUtf8("building_A")))
            .build()))
    .setFeatureLists(FeatureLists.newBuilder()
        .putFeatureList("temperature", FeatureList.newBuilder()
            .addFeature(Feature.newBuilder()
                .setFloatList(FloatList.newBuilder().addValue(20.1f))
                .build())
            .addFeature(Feature.newBuilder()
                .setFloatList(FloatList.newBuilder().addValue(20.3f))
                .build())
            .addFeature(Feature.newBuilder()
                .setFloatList(FloatList.newBuilder().addValue(20.0f))
                .build())
            .build())
        .putFeatureList("timestamp", FeatureList.newBuilder()
            .addFeature(Feature.newBuilder()
                .setInt64List(Int64List.newBuilder().addValue(1634567890))
                .build())
            .addFeature(Feature.newBuilder()
                .setInt64List(Int64List.newBuilder().addValue(1634567950))
                .build())
            .addFeature(Feature.newBuilder()
                .setInt64List(Int64List.newBuilder().addValue(1634568010))
                .build())
            .build()))
    .build();

Feature

Individual feature containing typed data (bytes, floats, or integers).

/**
 * Individual feature containing typed data
 */
class Feature {
  /** Get list of byte string values */
  BytesList getBytesList();
  
  /** Get list of float values */
  FloatList getFloatList();
  
  /** Get list of integer values */
  Int64List getInt64List();
  
  /** Get which kind of value is set */
  KindCase getKindCase();
  
  /** Create a new builder for constructing Feature */
  static Builder newBuilder();
  
  /** Builder for constructing Feature instances */
  static class Builder {
    Builder setBytesList(BytesList bytesList);
    Builder setFloatList(FloatList floatList);
    Builder setInt64List(Int64List int64List);
    Feature build();
  }
  
  /** Enum indicating which value type is set */
  enum KindCase {
    BYTES_LIST,
    FLOAT_LIST,
    INT64_LIST,
    KIND_NOT_SET
  }
}

BytesList, FloatList, Int64List

Typed lists for different data types within features.

/**
 * List of byte string values
 */
class BytesList {
  List<ByteString> getValueList();
  
  static Builder newBuilder();
  
  static class Builder {
    Builder addValue(ByteString value);
    Builder addAllValue(Iterable<ByteString> values);
    BytesList build();
  }
}

/**
 * List of float values
 */
class FloatList {
  List<Float> getValueList();
  
  static Builder newBuilder();
  
  static class Builder {
    Builder addValue(float value);
    Builder addAllValue(Iterable<Float> values);
    FloatList build();
  }
}

/**
 * List of 64-bit integer values
 */
class Int64List {
  List<Long> getValueList();
  
  static Builder newBuilder();
  
  static class Builder {
    Builder addValue(long value);
    Builder addAllValue(Iterable<Long> values);
    Int64List build();
  }
}

Features

Map from feature name to Feature objects.

/**
 * Map from feature name to Feature
 */
class Features {
  /** Get feature name to Feature mapping */
  Map<String, Feature> getFeatureMap();
  
  /** Create a new builder for constructing Features */
  static Builder newBuilder();
  
  /** Builder for constructing Features instances */
  static class Builder {
    Builder putFeature(String key, Feature value);
    Builder putAllFeature(Map<String, Feature> features);
    Features build();
  }
}

FeatureLists and FeatureList

For sequence examples, these represent time-series or sequential features.

/**
 * Map from feature list name to FeatureList
 */
class FeatureLists {
  /** Get feature list name to FeatureList mapping */
  Map<String, FeatureList> getFeatureListMap();
  
  /** Create a new builder for constructing FeatureLists */
  static Builder newBuilder();
  
  /** Builder for constructing FeatureLists instances */
  static class Builder {
    Builder putFeatureList(String key, FeatureList value);
    Builder putAllFeatureList(Map<String, FeatureList> featureLists);
    FeatureLists build();
  }
}

/**
 * Sequence of features for time-series data
 */
class FeatureList {
  /** Get list of features in sequence */
  List<Feature> getFeatureList();
  
  /** Create a new builder for constructing FeatureList */
  static Builder newBuilder();
  
  /** Builder for constructing FeatureList instances */
  static class Builder {
    Builder addFeature(Feature feature);
    Builder addAllFeature(Iterable<Feature> features);
    FeatureList build();
  }
}

ExampleParserConfiguration

Configuration for parsing Example protos efficiently.

/**
 * Configuration for parsing Example protos
 */
class ExampleParserConfiguration {
  Map<String, FeatureConfiguration> getFeatureMapMap();
  
  /**
   * Configuration for individual features
   */
  static class FeatureConfiguration {
    ConfigCase getConfigCase();
    FixedLenFeature getFixedLenFeature();
    VarLenFeature getVarLenFeature();
    
    enum ConfigCase {
      FIXED_LEN_FEATURE,
      VAR_LEN_FEATURE,
      CONFIG_NOT_SET
    }
  }
  
  /**
   * Configuration for fixed-length features
   */
  static class FixedLenFeature {
    List<Long> getShapeList();
    DataType getDtype();
    TensorProto getDefaultValue();
  }
  
  /**
   * Configuration for variable-length features
   */
  static class VarLenFeature {
    DataType getDtype();
  }
}

Usage Examples:

import org.tensorflow.example.*;

// Working with different feature types
Feature stringFeature = Feature.newBuilder()
    .setBytesList(BytesList.newBuilder()
        .addValue(ByteString.copyFromUtf8("category_a"))
        .addValue(ByteString.copyFromUtf8("category_b")))
    .build();

Feature numericFeature = Feature.newBuilder()
    .setFloatList(FloatList.newBuilder()
        .addValue(1.5f)
        .addValue(2.3f)
        .addValue(0.8f))
    .build();

Feature idFeature = Feature.newBuilder()
    .setInt64List(Int64List.newBuilder()
        .addValue(12345L))
    .build();

// Check feature type
switch (feature.getKindCase()) {
    case BYTES_LIST:
        List<ByteString> strings = feature.getBytesList().getValueList();
        break;
    case FLOAT_LIST:
        List<Float> floats = feature.getFloatList().getValueList();
        break;
    case INT64_LIST:
        List<Long> integers = feature.getInt64List().getValueList();
        break;
    case KIND_NOT_SET:
        // Handle empty feature
        break;
}

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