From 997f7871e50633170de9741b95c64cf9a08912b2 Mon Sep 17 00:00:00 2001 From: Asim Shankar Date: Fri, 12 Jan 2018 18:35:20 -0800 Subject: [PATCH 1/5] [samples]: Samples using the Java API. --- samples/java/README.md | 3 + samples/java/docker/Dockerfile | 7 + samples/java/docker/README.md | 12 + samples/java/label_image/.gitignore | 3 + samples/java/label_image/README.md | 23 + samples/java/label_image/download.py | 93 + samples/java/label_image/download.sh | 4 + .../label_image/download_sample_images.sh | 10 + samples/java/label_image/pom.xml | 26 + .../label_image/src/main/java/LabelImage.java | 98 + samples/java/object_detection/.gitignore | 5 + samples/java/object_detection/README.md | 57 + samples/java/object_detection/download.sh | 18 + samples/java/object_detection/pom.xml | 25 + .../src/main/java/DetectObjects.java | 184 ++ .../protos/StringIntLabelMapOuterClass.java | 1785 +++++++++++++++++ samples/java/training/.gitignore | 2 + samples/java/training/README.md | 37 + samples/java/training/model/create_graph.py | 36 + samples/java/training/model/graph.pb | Bin 0 -> 11064 bytes samples/java/training/pom.xml | 20 + .../java/training/src/main/java/Train.java | 91 + 22 files changed, 2539 insertions(+) create mode 100644 samples/java/README.md create mode 100644 samples/java/docker/Dockerfile create mode 100644 samples/java/docker/README.md create mode 100644 samples/java/label_image/.gitignore create mode 100644 samples/java/label_image/README.md create mode 100644 samples/java/label_image/download.py create mode 100755 samples/java/label_image/download.sh create mode 100755 samples/java/label_image/download_sample_images.sh create mode 100644 samples/java/label_image/pom.xml create mode 100644 samples/java/label_image/src/main/java/LabelImage.java create mode 100644 samples/java/object_detection/.gitignore create mode 100644 samples/java/object_detection/README.md create mode 100755 samples/java/object_detection/download.sh create mode 100644 samples/java/object_detection/pom.xml create mode 100644 samples/java/object_detection/src/main/java/DetectObjects.java create mode 100644 samples/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java create mode 100644 samples/java/training/.gitignore create mode 100644 samples/java/training/README.md create mode 100644 samples/java/training/model/create_graph.py create mode 100644 samples/java/training/model/graph.pb create mode 100644 samples/java/training/pom.xml create mode 100644 samples/java/training/src/main/java/Train.java diff --git a/samples/java/README.md b/samples/java/README.md new file mode 100644 index 00000000000..66017ed87fb --- /dev/null +++ b/samples/java/README.md @@ -0,0 +1,3 @@ +# TensorFlow for Java: Examples + +Examples using the TensorFlow Java API. diff --git a/samples/java/docker/Dockerfile b/samples/java/docker/Dockerfile new file mode 100644 index 00000000000..7f71f8314b1 --- /dev/null +++ b/samples/java/docker/Dockerfile @@ -0,0 +1,7 @@ +FROM tensorflow/tensorflow:1.4.0 +WORKDIR / +RUN apt-get update +RUN apt-get -y install maven openjdk-8-jdk +RUN mvn dependency:get -Dartifact=org.tensorflow:tensorflow:1.4.0 +RUN mvn dependency:get -Dartifact=org.tensorflow:proto:1.4.0 +CMD ["/bin/bash", "-l"] diff --git a/samples/java/docker/README.md b/samples/java/docker/README.md new file mode 100644 index 00000000000..0dfdd759b29 --- /dev/null +++ b/samples/java/docker/README.md @@ -0,0 +1,12 @@ +Dockerfile for building an image suitable for running the Java examples. + +Typical usage: + +``` +docker build -t java-tensorflow . +docker run -it --rm -v ${PWD}/..:/examples java-tensorflow +``` + +That second command will pop you into a shell which has all +the dependencies required to execute the scripts and Java +examples. diff --git a/samples/java/label_image/.gitignore b/samples/java/label_image/.gitignore new file mode 100644 index 00000000000..9aeb6ae6b6b --- /dev/null +++ b/samples/java/label_image/.gitignore @@ -0,0 +1,3 @@ +images +src/main/resources +target diff --git a/samples/java/label_image/README.md b/samples/java/label_image/README.md new file mode 100644 index 00000000000..b2dbef4a464 --- /dev/null +++ b/samples/java/label_image/README.md @@ -0,0 +1,23 @@ +# Image Classification Example + +1. Download the model: + - If you have [TensorFlow 1.4+ for Python installed](https://www.tensorflow.org/install/), + run `python ./download.py` + - If not, but you have [docker](https://www.docker.com/get-docker) installed, + run `download.sh`. + +2. Compile [`LabelImage.java`](src/main/java/LabelImage.java): + + ``` + mvn compile + ``` + +3. Download some sample images: + If you already have some images, great. Otherwise `download_sample_images.sh` + gets a few. + +3. Classify! + + ``` + mvn -q exec:java -Dexec.args="" + ``` diff --git a/samples/java/label_image/download.py b/samples/java/label_image/download.py new file mode 100644 index 00000000000..c9082c24222 --- /dev/null +++ b/samples/java/label_image/download.py @@ -0,0 +1,93 @@ +"""Create an image classification graph. + +Script to download a pre-trained image classifier and tweak it so that +the model accepts raw bytes of an encoded image. + +Doing so involves some model-specific normalization of an image. +Ideally, this would have been part of the image classifier model, +but the particular model being used didn't include this normalization, +so this script does the necessary tweaking. +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from six.moves import urllib +import os +import zipfile +import tensorflow as tf + +URL = 'https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip' +LABELS_FILE = 'imagenet_comp_graph_label_strings.txt' +GRAPH_FILE = 'tensorflow_inception_graph.pb' + +GRAPH_INPUT_TENSOR = 'input:0' +GRAPH_PROBABILITIES_TENSOR = 'output:0' + +IMAGE_HEIGHT = 224 +IMAGE_WIDTH = 224 +MEAN = 117 +SCALE = 1 + +LOCAL_DIR = 'src/main/resources' + + +def download(): + print('Downloading %s' % URL) + zip_filename, _ = urllib.request.urlretrieve(URL) + with zipfile.ZipFile(zip_filename) as zip: + zip.extract(LABELS_FILE) + zip.extract(GRAPH_FILE) + os.rename(LABELS_FILE, os.path.join(LOCAL_DIR, 'labels.txt')) + os.rename(GRAPH_FILE, os.path.join(LOCAL_DIR, 'graph.pb')) + + +def create_graph_to_decode_and_normalize_image(): + """See file docstring. + + Returns: + input: The placeholder to feed the raw bytes of an encoded image. + y: A Tensor (the decoded, normalized image) to be fed to the graph. + """ + image = tf.placeholder(tf.string, shape=(), name='encoded_image_bytes') + with tf.name_scope("preprocess"): + y = tf.image.decode_image(image, channels=3) + y = tf.cast(y, tf.float32) + y = tf.expand_dims(y, axis=0) + y = tf.image.resize_bilinear(y, (IMAGE_HEIGHT, IMAGE_WIDTH)) + y = (y - MEAN) / SCALE + return (image, y) + + +def patch_graph(): + """Create graph.pb that applies the model in URL to raw image bytes.""" + with tf.Graph().as_default() as g: + input_image, image_normalized = create_graph_to_decode_and_normalize_image() + original_graph_def = tf.GraphDef() + with open(os.path.join(LOCAL_DIR, 'graph.pb')) as f: + original_graph_def.ParseFromString(f.read()) + softmax = tf.import_graph_def( + original_graph_def, + name='inception', + input_map={GRAPH_INPUT_TENSOR: image_normalized}, + return_elements=[GRAPH_PROBABILITIES_TENSOR]) + # We're constructing a graph that accepts a single image (as opposed to a + # batch of images), so might as well make the output be a vector of + # probabilities, instead of a batch of vectors with batch size 1. + output_probabilities = tf.squeeze(softmax, name='probabilities') + # Overwrite the graph. + with open(os.path.join(LOCAL_DIR, 'graph.pb'), 'w') as f: + f.write(g.as_graph_def().SerializeToString()) + print('------------------------------------------------------------') + print('MODEL GRAPH : graph.pb') + print('LABELS : labels.txt') + print('INPUT TENSOR : %s' % input_image.op.name) + print('OUTPUT TENSOR: %s' % output_probabilities.op.name) + + +if __name__ == '__main__': + if not os.path.exists(LOCAL_DIR): + os.makedirs(LOCAL_DIR) + download() + patch_graph() diff --git a/samples/java/label_image/download.sh b/samples/java/label_image/download.sh new file mode 100755 index 00000000000..22ca88b1fb0 --- /dev/null +++ b/samples/java/label_image/download.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +DIR="$(cd "$(dirname "$0")" && pwd -P)" +docker run -it -v ${DIR}:/x -w /x --rm tensorflow/tensorflow:1.4.0 python download.py diff --git a/samples/java/label_image/download_sample_images.sh b/samples/java/label_image/download_sample_images.sh new file mode 100755 index 00000000000..17deb84cddf --- /dev/null +++ b/samples/java/label_image/download_sample_images.sh @@ -0,0 +1,10 @@ +#!/bin/bash +DIR=$(dirname $0) +mkdir -p ${DIR}/images +cd ${DIR}/images + +# Some random images +curl -o "porcupine.jpg" -L "https://cdn.pixabay.com/photo/2014/11/06/12/46/porcupines-519145_960_720.jpg" +curl -o "whale.jpg" -L "https://static.pexels.com/photos/417196/pexels-photo-417196.jpeg" +curl -o "terrier1u.jpg" -L "https://upload.wikimedia.org/wikipedia/commons/3/34/Australian_Terrier_Melly_%282%29.JPG" +curl -o "terrier2.jpg" -L "https://cdn.pixabay.com/photo/2014/05/13/07/44/yorkshire-terrier-343198_960_720.jpg" diff --git a/samples/java/label_image/pom.xml b/samples/java/label_image/pom.xml new file mode 100644 index 00000000000..96ace380bf4 --- /dev/null +++ b/samples/java/label_image/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + org.myorg + label-image + 1.0-SNAPSHOT + + LabelImage + + + 1.7 + 1.7 + + + + org.tensorflow + tensorflow + 1.4.0 + + + + com.google.guava + guava + 23.6-jre + + + diff --git a/samples/java/label_image/src/main/java/LabelImage.java b/samples/java/label_image/src/main/java/LabelImage.java new file mode 100644 index 00000000000..1bcd906c5b9 --- /dev/null +++ b/samples/java/label_image/src/main/java/LabelImage.java @@ -0,0 +1,98 @@ +/* Copyright 2018 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. +==============================================================================*/ + +import com.google.common.io.ByteStreams; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import org.tensorflow.Graph; +import org.tensorflow.Session; +import org.tensorflow.Tensor; +import org.tensorflow.Tensors; + +/** + * Simplified version of + * https://github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/java/src/main/java/org/tensorflow/examples/LabelImage.java + */ +public class LabelImage { + public static void main(String[] args) throws Exception { + if (args.length < 1) { + System.err.println("USAGE: Provide a list of image filenames"); + System.exit(1); + } + final List labels = loadLabels(); + try (Graph graph = new Graph(); + Session session = new Session(graph)) { + graph.importGraphDef(loadGraphDef()); + + float[] probabilities = null; + for (String filename : args) { + byte[] bytes = Files.readAllBytes(Paths.get(filename)); + try (Tensor input = Tensors.create(bytes); + Tensor output = + session + .runner() + .feed("encoded_image_bytes", input) + .fetch("probabilities") + .run() + .get(0) + .expect(Float.class)) { + if (probabilities == null) { + probabilities = new float[(int) output.shape()[0]]; + } + output.copyTo(probabilities); + int label = argmax(probabilities); + System.out.printf( + "%-30s --> %-15s (%.2f%% likely)\n", + filename, labels.get(label), probabilities[label] * 100.0); + } + } + } + } + + private static byte[] loadGraphDef() throws IOException { + try (InputStream is = LabelImage.class.getClassLoader().getResourceAsStream("graph.pb")) { + return ByteStreams.toByteArray(is); + } + } + + private static ArrayList loadLabels() throws IOException { + ArrayList labels = new ArrayList(); + String line; + final InputStream is = LabelImage.class.getClassLoader().getResourceAsStream("labels.txt"); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + while ((line = reader.readLine()) != null) { + labels.add(line); + } + } + return labels; + } + + private static int argmax(float[] probabilities) { + int best = 0; + for (int i = 1; i < probabilities.length; ++i) { + if (probabilities[i] > probabilities[best]) { + best = i; + } + } + return best; + } +} diff --git a/samples/java/object_detection/.gitignore b/samples/java/object_detection/.gitignore new file mode 100644 index 00000000000..81497884294 --- /dev/null +++ b/samples/java/object_detection/.gitignore @@ -0,0 +1,5 @@ +images +labels +models +src/main/protobuf +target diff --git a/samples/java/object_detection/README.md b/samples/java/object_detection/README.md new file mode 100644 index 00000000000..76baa1b6d23 --- /dev/null +++ b/samples/java/object_detection/README.md @@ -0,0 +1,57 @@ +# Object Detection in Java + +Example of using pre-trained models of the [TensorFlow Object Detection +API](https://github.com/tensorflow/models/tree/master/research/object_detection) +in Java. + +## Quickstart + +1. Download some metadata files: + ``` + ./download.sh + ``` + +2. Download a model from the [object detection API model + zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md). + For example: + ``` + mkdir -p models + curl -L \ + http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2017_11_17.tar.gz \ + | tar -xz -C models/ + ``` + +3. Locate the corresponding labels file in the `data/` directory. + +3. Have some test images handy. For example: + ``` + mkdir -p images + curl -L -o images/test.jpg \ + https://pixnio.com/free-images/people/mother-father-and-children-washing-dog-labrador-retriever-outside-in-the-fresh-air-725x483.jpg + ``` + +4. Compile and run! + ``` + mvn -q compile exec:java \ + -Dexec.args="models/ssd_inception_v2_coco_2017_11_17/saved_model labels/mscoco_label_map.pbtxt images/test.jpg" + ``` + +## Notes + +- This example demonstrates the use of the TensorFlow [SavedModel + format](https://www.tensorflow.org/programmers_guide/saved_model). If you have + TensorFlow for Python installed, you could explore the model to get the names + of the tensors using `saved_model_cli` command. For example: + ``` + saved_model_cli show --dir models/ssd_inception_v2_coco_2017_11_17/saved_model/ --all + ``` + +- The file in `src/main/object_detection/protos/` was generated using: + + ``` + ./download.sh + protoc -Isrc/main/protobuf --java_out=src/main/java src/main/protobuf/string_int_label_map.proto + ``` + + Where `protoc` was downloaded from + https://github.com/google/protobuf/releases/tag/v3.5.1 diff --git a/samples/java/object_detection/download.sh b/samples/java/object_detection/download.sh new file mode 100755 index 00000000000..f301af2e582 --- /dev/null +++ b/samples/java/object_detection/download.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -ex + +DIR="$(cd "$(dirname "$0")" && pwd -P)" +cd "${DIR}" + +# The protobuf file needed for mapping labels to human readable names. +# From: +# https://github.com/tensorflow/models/blob/f87a58c/research/object_detection/protos/string_int_label_map.proto +mkdir -p src/main/protobuf +curl -L -o src/main/protobuf/string_int_label_map.proto "https://raw.githubusercontent.com/tensorflow/models/f87a58cd96d45de73c9a8330a06b2ab56749a7fa/research/object_detection/protos/string_int_label_map.proto" + +# Labels from: +# https://github.com/tensorflow/models/tree/865c14c/research/object_detection/data +mkdir -p labels +curl -L -o labels/mscoco_label_map.pbtxt "https://raw.githubusercontent.com/tensorflow/models/865c14c1209cb9ae188b2a1b5f0883c72e050d4c/research/object_detection/data/mscoco_label_map.pbtxt" +curl -L -o labels/oid_bbox_trainable_label_map.pbtxt "https://raw.githubusercontent.com/tensorflow/models/865c14c1209cb9ae188b2a1b5f0883c72e050d4c/research/object_detection/data/oid_bbox_trainable_label_map.pbtxt" diff --git a/samples/java/object_detection/pom.xml b/samples/java/object_detection/pom.xml new file mode 100644 index 00000000000..c9123dae044 --- /dev/null +++ b/samples/java/object_detection/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + org.myorg + detect-objects + 1.0-SNAPSHOT + + DetectObjects + + + 1.7 + 1.7 + + + + org.tensorflow + tensorflow + 1.4.0 + + + org.tensorflow + proto + 1.4.0 + + + diff --git a/samples/java/object_detection/src/main/java/DetectObjects.java b/samples/java/object_detection/src/main/java/DetectObjects.java new file mode 100644 index 00000000000..bf865e933d4 --- /dev/null +++ b/samples/java/object_detection/src/main/java/DetectObjects.java @@ -0,0 +1,184 @@ +/* Copyright 2018 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. +==============================================================================*/ + +import static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap; +import static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem; + +import com.google.protobuf.TextFormat; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferByte; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; +import javax.imageio.ImageIO; +import org.tensorflow.SavedModelBundle; +import org.tensorflow.Tensor; +import org.tensorflow.framework.MetaGraphDef; +import org.tensorflow.framework.SignatureDef; +import org.tensorflow.framework.TensorInfo; +import org.tensorflow.types.UInt8; + +/** + * Java inference for the Object Detection API at: + * https://github.com/tensorflow/models/blob/master/research/object_detection/ + */ +public class DetectObjects { + public static void main(String[] args) throws Exception { + if (args.length < 3) { + printUsage(System.err); + System.exit(1); + } + final String[] labels = loadLabels(args[1]); + try (SavedModelBundle model = SavedModelBundle.load(args[0], "serve")) { + printSignature(model); + for (int arg = 2; arg < args.length; arg++) { + final String filename = args[arg]; + List> outputs = null; + try (Tensor input = makeImageTensor(filename)) { + outputs = + model + .session() + .runner() + .feed("image_tensor", input) + .fetch("detection_scores") + .fetch("detection_classes") + .fetch("detection_boxes") + .run(); + } + try (Tensor scoresT = outputs.get(0).expect(Float.class); + Tensor classesT = outputs.get(1).expect(Float.class); + Tensor boxesT = outputs.get(2).expect(Float.class)) { + // All these tensors have: + // - 1 as the first dimension + // - maxObjects as the second dimension + // While boxesT will have 4 as the third dimension (2 sets of (x, y) coordinates). + // This can be verified by looking at scoresT.shape() etc. + int maxObjects = (int) scoresT.shape()[1]; + float[] scores = scoresT.copyTo(new float[1][maxObjects])[0]; + float[] classes = classesT.copyTo(new float[1][maxObjects])[0]; + float[][] boxes = boxesT.copyTo(new float[1][maxObjects][4])[0]; + // Print all objects whose score is at least 0.5. + System.out.printf("* %s\n", filename); + boolean foundSomething = false; + for (int i = 0; i < scores.length; ++i) { + if (scores[i] < 0.5) { + continue; + } + foundSomething = true; + System.out.printf("\tFound %-20s (score: %.4f)\n", labels[(int) classes[i]], scores[i]); + } + if (!foundSomething) { + System.out.println("No objects detected with a high enough score."); + } + } + } + } + } + + private static void printSignature(SavedModelBundle model) throws Exception { + MetaGraphDef m = MetaGraphDef.parseFrom(model.metaGraphDef()); + SignatureDef sig = m.getSignatureDefOrThrow("serving_default"); + int numInputs = sig.getInputsCount(); + int i = 1; + System.out.println("MODEL SIGNATURE"); + System.out.println("Inputs:"); + for (Map.Entry entry : sig.getInputsMap().entrySet()) { + TensorInfo t = entry.getValue(); + System.out.printf( + "%d of %d: %-20s (Node name in graph: %-20s, type: %s)\n", + i++, numInputs, entry.getKey(), t.getName(), t.getDtype()); + } + int numOutputs = sig.getOutputsCount(); + i = 1; + System.out.println("Outputs:"); + for (Map.Entry entry : sig.getOutputsMap().entrySet()) { + TensorInfo t = entry.getValue(); + System.out.printf( + "%d of %d: %-20s (Node name in graph: %-20s, type: %s)\n", + i++, numOutputs, entry.getKey(), t.getName(), t.getDtype()); + } + System.out.println("-----------------------------------------------"); + } + + private static String[] loadLabels(String filename) throws Exception { + String text = new String(Files.readAllBytes(Paths.get(filename)), StandardCharsets.UTF_8); + StringIntLabelMap.Builder builder = StringIntLabelMap.newBuilder(); + TextFormat.merge(text, builder); + StringIntLabelMap proto = builder.build(); + int maxId = 0; + for (StringIntLabelMapItem item : proto.getItemList()) { + if (item.getId() > maxId) { + maxId = item.getId(); + } + } + String[] ret = new String[maxId + 1]; + for (StringIntLabelMapItem item : proto.getItemList()) { + ret[item.getId()] = item.getDisplayName(); + } + return ret; + } + + private static void bgr2rgb(byte[] data) { + for (int i = 0; i < data.length; i += 3) { + byte tmp = data[i]; + data[i] = data[i + 2]; + data[i + 2] = tmp; + } + } + + private static Tensor makeImageTensor(String filename) throws IOException { + BufferedImage img = ImageIO.read(new File(filename)); + if (img.getType() != BufferedImage.TYPE_3BYTE_BGR) { + throw new IOException( + String.format( + "Expected 3-byte BGR encoding in BufferedImage, found %d (file: %s). This code could be made more robust", + img.getType(), filename)); + } + byte[] data = ((DataBufferByte) img.getData().getDataBuffer()).getData(); + // ImageIO.read seems to produce BGR-encoded images, but the model expects RGB. + bgr2rgb(data); + final long BATCH_SIZE = 1; + final long CHANNELS = 3; + long[] shape = new long[] {BATCH_SIZE, img.getHeight(), img.getWidth(), CHANNELS}; + return Tensor.create(UInt8.class, shape, ByteBuffer.wrap(data)); + } + + private static void printUsage(PrintStream s) { + s.println("USAGE: [] []"); + s.println(""); + s.println("Where"); + s.println(" is the path to the SavedModel directory of the model to use."); + s.println(" For example, the saved_model directory in tarballs from "); + s.println( + " https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md)"); + s.println(""); + s.println( + " is the path to a file containing information about the labels detected by the model."); + s.println(" For example, one of the .pbtxt files from "); + s.println( + " https://github.com/tensorflow/models/tree/master/research/object_detection/data"); + s.println(""); + s.println(" is the path to an image file."); + s.println(" Sample images can be found from the COCO, Kitti, or Open Images dataset."); + s.println( + " See: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md"); + } +} diff --git a/samples/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java b/samples/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java new file mode 100644 index 00000000000..a6808ced389 --- /dev/null +++ b/samples/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java @@ -0,0 +1,1785 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: string_int_label_map.proto + +package object_detection.protos; + +public final class StringIntLabelMapOuterClass { + private StringIntLabelMapOuterClass() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + public interface StringIntLabelMapItemOrBuilder extends + // @@protoc_insertion_point(interface_extends:object_detection.protos.StringIntLabelMapItem) + com.google.protobuf.MessageOrBuilder { + + /** + *
+     * String name. The most common practice is to set this to a MID or synsets
+     * id.
+     * 
+ * + * optional string name = 1; + */ + boolean hasName(); + /** + *
+     * String name. The most common practice is to set this to a MID or synsets
+     * id.
+     * 
+ * + * optional string name = 1; + */ + java.lang.String getName(); + /** + *
+     * String name. The most common practice is to set this to a MID or synsets
+     * id.
+     * 
+ * + * optional string name = 1; + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + *
+     * Integer id that maps to the string name above. Label ids should start from
+     * 1.
+     * 
+ * + * optional int32 id = 2; + */ + boolean hasId(); + /** + *
+     * Integer id that maps to the string name above. Label ids should start from
+     * 1.
+     * 
+ * + * optional int32 id = 2; + */ + int getId(); + + /** + *
+     * Human readable string label.
+     * 
+ * + * optional string display_name = 3; + */ + boolean hasDisplayName(); + /** + *
+     * Human readable string label.
+     * 
+ * + * optional string display_name = 3; + */ + java.lang.String getDisplayName(); + /** + *
+     * Human readable string label.
+     * 
+ * + * optional string display_name = 3; + */ + com.google.protobuf.ByteString + getDisplayNameBytes(); + } + /** + * Protobuf type {@code object_detection.protos.StringIntLabelMapItem} + */ + public static final class StringIntLabelMapItem extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:object_detection.protos.StringIntLabelMapItem) + StringIntLabelMapItemOrBuilder { + private static final long serialVersionUID = 0L; + // Use StringIntLabelMapItem.newBuilder() to construct. + private StringIntLabelMapItem(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private StringIntLabelMapItem() { + name_ = ""; + id_ = 0; + displayName_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private StringIntLabelMapItem( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000001; + name_ = bs; + break; + } + case 16: { + bitField0_ |= 0x00000002; + id_ = input.readInt32(); + break; + } + case 26: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000004; + displayName_ = bs; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMapItem_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMapItem_fieldAccessorTable + .ensureFieldAccessorsInitialized( + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.class, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder.class); + } + + private int bitField0_; + public static final int NAME_FIELD_NUMBER = 1; + private volatile java.lang.Object name_; + /** + *
+     * String name. The most common practice is to set this to a MID or synsets
+     * id.
+     * 
+ * + * optional string name = 1; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + *
+     * String name. The most common practice is to set this to a MID or synsets
+     * id.
+     * 
+ * + * optional string name = 1; + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } + } + /** + *
+     * String name. The most common practice is to set this to a MID or synsets
+     * id.
+     * 
+ * + * optional string name = 1; + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int ID_FIELD_NUMBER = 2; + private int id_; + /** + *
+     * Integer id that maps to the string name above. Label ids should start from
+     * 1.
+     * 
+ * + * optional int32 id = 2; + */ + public boolean hasId() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + *
+     * Integer id that maps to the string name above. Label ids should start from
+     * 1.
+     * 
+ * + * optional int32 id = 2; + */ + public int getId() { + return id_; + } + + public static final int DISPLAY_NAME_FIELD_NUMBER = 3; + private volatile java.lang.Object displayName_; + /** + *
+     * Human readable string label.
+     * 
+ * + * optional string display_name = 3; + */ + public boolean hasDisplayName() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + *
+     * Human readable string label.
+     * 
+ * + * optional string display_name = 3; + */ + public java.lang.String getDisplayName() { + java.lang.Object ref = displayName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + displayName_ = s; + } + return s; + } + } + /** + *
+     * Human readable string label.
+     * 
+ * + * optional string display_name = 3; + */ + public com.google.protobuf.ByteString + getDisplayNameBytes() { + java.lang.Object ref = displayName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + displayName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeInt32(2, id_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, displayName_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(2, id_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, displayName_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem)) { + return super.equals(obj); + } + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem other = (object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem) obj; + + boolean result = true; + result = result && (hasName() == other.hasName()); + if (hasName()) { + result = result && getName() + .equals(other.getName()); + } + result = result && (hasId() == other.hasId()); + if (hasId()) { + result = result && (getId() + == other.getId()); + } + result = result && (hasDisplayName() == other.hasDisplayName()); + if (hasDisplayName()) { + result = result && getDisplayName() + .equals(other.getDisplayName()); + } + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasName()) { + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + } + if (hasId()) { + hash = (37 * hash) + ID_FIELD_NUMBER; + hash = (53 * hash) + getId(); + } + if (hasDisplayName()) { + hash = (37 * hash) + DISPLAY_NAME_FIELD_NUMBER; + hash = (53 * hash) + getDisplayName().hashCode(); + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code object_detection.protos.StringIntLabelMapItem} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:object_detection.protos.StringIntLabelMapItem) + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMapItem_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMapItem_fieldAccessorTable + .ensureFieldAccessorsInitialized( + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.class, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder.class); + } + + // Construct using object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + name_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0; + bitField0_ = (bitField0_ & ~0x00000002); + displayName_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMapItem_descriptor; + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem getDefaultInstanceForType() { + return object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.getDefaultInstance(); + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem build() { + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem buildPartial() { + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem result = new object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.name_ = name_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.id_ = id_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.displayName_ = displayName_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem) { + return mergeFrom((object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem other) { + if (other == object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.getDefaultInstance()) return this; + if (other.hasName()) { + bitField0_ |= 0x00000001; + name_ = other.name_; + onChanged(); + } + if (other.hasId()) { + setId(other.getId()); + } + if (other.hasDisplayName()) { + bitField0_ |= 0x00000004; + displayName_ = other.displayName_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private java.lang.Object name_ = ""; + /** + *
+       * String name. The most common practice is to set this to a MID or synsets
+       * id.
+       * 
+ * + * optional string name = 1; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + *
+       * String name. The most common practice is to set this to a MID or synsets
+       * id.
+       * 
+ * + * optional string name = 1; + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + *
+       * String name. The most common practice is to set this to a MID or synsets
+       * id.
+       * 
+ * + * optional string name = 1; + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + *
+       * String name. The most common practice is to set this to a MID or synsets
+       * id.
+       * 
+ * + * optional string name = 1; + */ + public Builder setName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + name_ = value; + onChanged(); + return this; + } + /** + *
+       * String name. The most common practice is to set this to a MID or synsets
+       * id.
+       * 
+ * + * optional string name = 1; + */ + public Builder clearName() { + bitField0_ = (bitField0_ & ~0x00000001); + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + *
+       * String name. The most common practice is to set this to a MID or synsets
+       * id.
+       * 
+ * + * optional string name = 1; + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + name_ = value; + onChanged(); + return this; + } + + private int id_ ; + /** + *
+       * Integer id that maps to the string name above. Label ids should start from
+       * 1.
+       * 
+ * + * optional int32 id = 2; + */ + public boolean hasId() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + *
+       * Integer id that maps to the string name above. Label ids should start from
+       * 1.
+       * 
+ * + * optional int32 id = 2; + */ + public int getId() { + return id_; + } + /** + *
+       * Integer id that maps to the string name above. Label ids should start from
+       * 1.
+       * 
+ * + * optional int32 id = 2; + */ + public Builder setId(int value) { + bitField0_ |= 0x00000002; + id_ = value; + onChanged(); + return this; + } + /** + *
+       * Integer id that maps to the string name above. Label ids should start from
+       * 1.
+       * 
+ * + * optional int32 id = 2; + */ + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000002); + id_ = 0; + onChanged(); + return this; + } + + private java.lang.Object displayName_ = ""; + /** + *
+       * Human readable string label.
+       * 
+ * + * optional string display_name = 3; + */ + public boolean hasDisplayName() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + *
+       * Human readable string label.
+       * 
+ * + * optional string display_name = 3; + */ + public java.lang.String getDisplayName() { + java.lang.Object ref = displayName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + displayName_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + *
+       * Human readable string label.
+       * 
+ * + * optional string display_name = 3; + */ + public com.google.protobuf.ByteString + getDisplayNameBytes() { + java.lang.Object ref = displayName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + displayName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + *
+       * Human readable string label.
+       * 
+ * + * optional string display_name = 3; + */ + public Builder setDisplayName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + displayName_ = value; + onChanged(); + return this; + } + /** + *
+       * Human readable string label.
+       * 
+ * + * optional string display_name = 3; + */ + public Builder clearDisplayName() { + bitField0_ = (bitField0_ & ~0x00000004); + displayName_ = getDefaultInstance().getDisplayName(); + onChanged(); + return this; + } + /** + *
+       * Human readable string label.
+       * 
+ * + * optional string display_name = 3; + */ + public Builder setDisplayNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + displayName_ = value; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:object_detection.protos.StringIntLabelMapItem) + } + + // @@protoc_insertion_point(class_scope:object_detection.protos.StringIntLabelMapItem) + private static final object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem(); + } + + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public StringIntLabelMapItem parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new StringIntLabelMapItem(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + public interface StringIntLabelMapOrBuilder extends + // @@protoc_insertion_point(interface_extends:object_detection.protos.StringIntLabelMap) + com.google.protobuf.MessageOrBuilder { + + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + java.util.List + getItemList(); + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem getItem(int index); + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + int getItemCount(); + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + java.util.List + getItemOrBuilderList(); + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder getItemOrBuilder( + int index); + } + /** + * Protobuf type {@code object_detection.protos.StringIntLabelMap} + */ + public static final class StringIntLabelMap extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:object_detection.protos.StringIntLabelMap) + StringIntLabelMapOrBuilder { + private static final long serialVersionUID = 0L; + // Use StringIntLabelMap.newBuilder() to construct. + private StringIntLabelMap(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private StringIntLabelMap() { + item_ = java.util.Collections.emptyList(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private StringIntLabelMap( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { + item_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000001; + } + item_.add( + input.readMessage(object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.PARSER, extensionRegistry)); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { + item_ = java.util.Collections.unmodifiableList(item_); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMap_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMap_fieldAccessorTable + .ensureFieldAccessorsInitialized( + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.class, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.Builder.class); + } + + public static final int ITEM_FIELD_NUMBER = 1; + private java.util.List item_; + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public java.util.List getItemList() { + return item_; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public java.util.List + getItemOrBuilderList() { + return item_; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public int getItemCount() { + return item_.size(); + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem getItem(int index) { + return item_.get(index); + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder getItemOrBuilder( + int index) { + return item_.get(index); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + for (int i = 0; i < item_.size(); i++) { + output.writeMessage(1, item_.get(i)); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + for (int i = 0; i < item_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(1, item_.get(i)); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap)) { + return super.equals(obj); + } + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap other = (object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap) obj; + + boolean result = true; + result = result && getItemList() + .equals(other.getItemList()); + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (getItemCount() > 0) { + hash = (37 * hash) + ITEM_FIELD_NUMBER; + hash = (53 * hash) + getItemList().hashCode(); + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code object_detection.protos.StringIntLabelMap} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:object_detection.protos.StringIntLabelMap) + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMap_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMap_fieldAccessorTable + .ensureFieldAccessorsInitialized( + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.class, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.Builder.class); + } + + // Construct using object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + getItemFieldBuilder(); + } + } + public Builder clear() { + super.clear(); + if (itemBuilder_ == null) { + item_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + } else { + itemBuilder_.clear(); + } + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return object_detection.protos.StringIntLabelMapOuterClass.internal_static_object_detection_protos_StringIntLabelMap_descriptor; + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap getDefaultInstanceForType() { + return object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.getDefaultInstance(); + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap build() { + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap buildPartial() { + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap result = new object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap(this); + int from_bitField0_ = bitField0_; + if (itemBuilder_ == null) { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + item_ = java.util.Collections.unmodifiableList(item_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.item_ = item_; + } else { + result.item_ = itemBuilder_.build(); + } + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap) { + return mergeFrom((object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap other) { + if (other == object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap.getDefaultInstance()) return this; + if (itemBuilder_ == null) { + if (!other.item_.isEmpty()) { + if (item_.isEmpty()) { + item_ = other.item_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureItemIsMutable(); + item_.addAll(other.item_); + } + onChanged(); + } + } else { + if (!other.item_.isEmpty()) { + if (itemBuilder_.isEmpty()) { + itemBuilder_.dispose(); + itemBuilder_ = null; + item_ = other.item_; + bitField0_ = (bitField0_ & ~0x00000001); + itemBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + getItemFieldBuilder() : null; + } else { + itemBuilder_.addAllMessages(other.item_); + } + } + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private java.util.List item_ = + java.util.Collections.emptyList(); + private void ensureItemIsMutable() { + if (!((bitField0_ & 0x00000001) == 0x00000001)) { + item_ = new java.util.ArrayList(item_); + bitField0_ |= 0x00000001; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder> itemBuilder_; + + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public java.util.List getItemList() { + if (itemBuilder_ == null) { + return java.util.Collections.unmodifiableList(item_); + } else { + return itemBuilder_.getMessageList(); + } + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public int getItemCount() { + if (itemBuilder_ == null) { + return item_.size(); + } else { + return itemBuilder_.getCount(); + } + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem getItem(int index) { + if (itemBuilder_ == null) { + return item_.get(index); + } else { + return itemBuilder_.getMessage(index); + } + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder setItem( + int index, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem value) { + if (itemBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureItemIsMutable(); + item_.set(index, value); + onChanged(); + } else { + itemBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder setItem( + int index, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder builderForValue) { + if (itemBuilder_ == null) { + ensureItemIsMutable(); + item_.set(index, builderForValue.build()); + onChanged(); + } else { + itemBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder addItem(object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem value) { + if (itemBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureItemIsMutable(); + item_.add(value); + onChanged(); + } else { + itemBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder addItem( + int index, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem value) { + if (itemBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureItemIsMutable(); + item_.add(index, value); + onChanged(); + } else { + itemBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder addItem( + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder builderForValue) { + if (itemBuilder_ == null) { + ensureItemIsMutable(); + item_.add(builderForValue.build()); + onChanged(); + } else { + itemBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder addItem( + int index, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder builderForValue) { + if (itemBuilder_ == null) { + ensureItemIsMutable(); + item_.add(index, builderForValue.build()); + onChanged(); + } else { + itemBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder addAllItem( + java.lang.Iterable values) { + if (itemBuilder_ == null) { + ensureItemIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, item_); + onChanged(); + } else { + itemBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder clearItem() { + if (itemBuilder_ == null) { + item_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + } else { + itemBuilder_.clear(); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public Builder removeItem(int index) { + if (itemBuilder_ == null) { + ensureItemIsMutable(); + item_.remove(index); + onChanged(); + } else { + itemBuilder_.remove(index); + } + return this; + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder getItemBuilder( + int index) { + return getItemFieldBuilder().getBuilder(index); + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder getItemOrBuilder( + int index) { + if (itemBuilder_ == null) { + return item_.get(index); } else { + return itemBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public java.util.List + getItemOrBuilderList() { + if (itemBuilder_ != null) { + return itemBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(item_); + } + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder addItemBuilder() { + return getItemFieldBuilder().addBuilder( + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.getDefaultInstance()); + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder addItemBuilder( + int index) { + return getItemFieldBuilder().addBuilder( + index, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.getDefaultInstance()); + } + /** + * repeated .object_detection.protos.StringIntLabelMapItem item = 1; + */ + public java.util.List + getItemBuilderList() { + return getItemFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilderV3< + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder> + getItemFieldBuilder() { + if (itemBuilder_ == null) { + itemBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< + object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItem.Builder, object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMapItemOrBuilder>( + item_, + ((bitField0_ & 0x00000001) == 0x00000001), + getParentForChildren(), + isClean()); + item_ = null; + } + return itemBuilder_; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:object_detection.protos.StringIntLabelMap) + } + + // @@protoc_insertion_point(class_scope:object_detection.protos.StringIntLabelMap) + private static final object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap(); + } + + public static object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @java.lang.Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public StringIntLabelMap parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new StringIntLabelMap(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public object_detection.protos.StringIntLabelMapOuterClass.StringIntLabelMap getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_object_detection_protos_StringIntLabelMapItem_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_object_detection_protos_StringIntLabelMapItem_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_object_detection_protos_StringIntLabelMap_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_object_detection_protos_StringIntLabelMap_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\032string_int_label_map.proto\022\027object_det" + + "ection.protos\"G\n\025StringIntLabelMapItem\022\014" + + "\n\004name\030\001 \001(\t\022\n\n\002id\030\002 \001(\005\022\024\n\014display_name" + + "\030\003 \001(\t\"Q\n\021StringIntLabelMap\022<\n\004item\030\001 \003(" + + "\0132..object_detection.protos.StringIntLab" + + "elMapItem" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_object_detection_protos_StringIntLabelMapItem_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_object_detection_protos_StringIntLabelMapItem_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_object_detection_protos_StringIntLabelMapItem_descriptor, + new java.lang.String[] { "Name", "Id", "DisplayName", }); + internal_static_object_detection_protos_StringIntLabelMap_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_object_detection_protos_StringIntLabelMap_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_object_detection_protos_StringIntLabelMap_descriptor, + new java.lang.String[] { "Item", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/samples/java/training/.gitignore b/samples/java/training/.gitignore new file mode 100644 index 00000000000..e8448ec98f3 --- /dev/null +++ b/samples/java/training/.gitignore @@ -0,0 +1,2 @@ +target +checkpoint diff --git a/samples/java/training/README.md b/samples/java/training/README.md new file mode 100644 index 00000000000..29d77afbda4 --- /dev/null +++ b/samples/java/training/README.md @@ -0,0 +1,37 @@ +# Training models in Java + +Example of training a model (and saving and restoring checkpoints) using the +TensorFlow Java API. + +## Quickstart + +1. Train for a few steps: + ``` + mvn -q compile exec:java -Dexec.args="model/graph.pb checkpoint" + ``` + +2. Resume training from previous checkpoint and train some more: + ``` + mvn -q exec:java -Dexec.args="model/graph.pb checkpoint" + ``` + +3. Delete checkpoint: + ``` + rm -rf checkpoint + ``` + + +## Details + +The model in `model/graph.pb` represents a very simple linear model: + +``` +y = x * W + b +``` + +The `graph.pb` file is generated by executing `create_graph.py` in Python. + +The training is orchestrated by `src/main/java/Train.java`, which generates +training data of the form `y = 3.0 * x + 2.0` and over time, using gradient +descent, the model should "learn" and the value of `W` should converge to 3.0, +and `b` to 2.0. diff --git a/samples/java/training/model/create_graph.py b/samples/java/training/model/create_graph.py new file mode 100644 index 00000000000..7e043a94b85 --- /dev/null +++ b/samples/java/training/model/create_graph.py @@ -0,0 +1,36 @@ +from __future__ import print_function + +import tensorflow as tf + +x = tf.placeholder(tf.float32, name='input') +y_ = tf.placeholder(tf.float32, name='target') + +W = tf.Variable(5., name='W') +b = tf.Variable(3., name='b') + +y = x * W + b +y = tf.identity(y, name='output') + +loss = tf.reduce_mean(tf.square(y - y_)) +optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01) +train_op = optimizer.minimize(loss, name='train') + +init = tf.global_variables_initializer() + +# Creating a tf.train.Saver adds operations to the graph to save and +# restore variables from checkpoints. +saver_def = tf.train.Saver().as_saver_def() + +print('Operation to initialize variables: ', init.name) +print('Tensor to feed as input data: ', x.name) +print('Tensor to feed as training targets: ', y_.name) +print('Tensor to fetch as prediction: ', y.name) +print('Operation to train one step: ', train_op.name) +print('Tensor to be fed for checkpoint filename:', saver_def.filename_tensor_name) +print('Operation to save a checkpoint: ', saver_def.save_tensor_name) +print('Operation to restore a checkpoint: ', saver_def.restore_op_name) +print('Tensor to read value of W ', W.value().name) +print('Tensor to read value of b ', b.value().name) + +with open('graph.pb', 'w') as f: + f.write(tf.get_default_graph().as_graph_def().SerializeToString()) diff --git a/samples/java/training/model/graph.pb b/samples/java/training/model/graph.pb new file mode 100644 index 0000000000000000000000000000000000000000..51d946dafd01d403dbe30287c0630a9cbda59707 GIT binary patch literal 11064 zcmb_iTW=gm6`r1+n~xJG>CJAul{hyCDQZ|I_HvW8(mG?at5tAVt*saYa;s;ichX9G zX12S>8zUZ82wp(&goK0;@C%SYNbpa1;LmWXFV$7ur+Y5sWjvm$I`y6J)cNXkb-@#8 zy5s3AG}b@$?1A%g;td_&T!-c`yqr2l{fTB?g=X;5#(x@n^-T?SpcUHw$XQ~@2XO7Q z>yF*fwLR;?_GXUJJeZ7wP@U*)XvU3KdeG5~n%St;{<;rGpq(1R4a%^R?e zfP80YjqP*9h&>g+*I;ch8HctzcKoz8_MpC3gE4eYyHA6_9gU4v{FiB`ERT@SG7B8b zn+#sLb`Tf<9ixSP_V!QBo3MfS-Ju;iRx;mX4Za1f)2{E> zL!4qrc!~4Pu?0w3e?`jnBg*=3ma=|CJbi<%|Oi;-|2bbB~7^ryoi_Pl3>T@9{AGMl*1iRe&+PFlBl=`XpRD=YuJ!KP)mTI+`2M!Pr=d zGU+@?vVoDHq%KoZ^3{j3*BT<<$VPwUdY;kXpG>kDqmX`xRV&p2IDmIE6PyN%|Ev0t zk8Qz=UudvNT5*4dntP0&tbCS~9Nqke(4>cO-?$rT5^0tbTmW$ax2Vn{S>k}QQlKm1 zfZuBL#OD*#%a6Rt#6Ox0SsAuBkLQ;f+@^?#R)V!-Bny)SgqT;Pp%9KQ;U0y8&;)7c zTXqc)asrhTE2^^GdMnPA)1ZHAbS^2vG>??>^}s5I7DR2iT!IU@O9hLINw=)p`Tt|3 z!S73iL(;OUwan(AUU4nMe>HeO@o{*G<(fM<#tLZg(zvSpODkLydph|s*XS{^WRp6@ zd0EjZKJ2+s->kz7wkYS0?APx3?7VxK?m%xeFE#i}i7qAc8tvo@n@>Hfc3?$@;13$y zp_uuci}=vJNaXy`y{HNtxnL9DRz)_YCH*reh-!^?@`dHffd!~c5ozWXXr097cu{mg z@8~D4hdVm|WTc-dkV+oS>i{QMx`yu5bFivJQ!{gl zvoC2qSIV?+ikjsSJT&fC*DThq`A%8@U+t}90o*X^9j#CV|E)w8KlQPuXz)*({e&fY zb;gC?BK53pF6k9q(sV~t@{%K-dr7N{arF-k7?re~C7gOLTkq3UCeRnE|5xFQ+{_b| zuy!&LUY4`DRmz{WO8H01gb-KoN*5y%{xqYP=jKluU5unEj0oehn(HvROGXJ&wMAGv ztHb*dEsO_t5E>2sNf#vU+0b* z6lQXraXCciC6c-9F*ZRg3u10~#!OERES_}4v_z7c?ia~fi5OFO=sA?NNVS1DlP9nI zNlU@XR~kId_!nk+{=^;*Fq$7HM-5N?QDD4H{wybkFcA5|q^wq3q^y8nYw!*M;dpk= zPmRuH&CC&M?XZQxFQl#-o_A813&l?f;BqRmII6YJ@09H~BWZTd7u#I-O@cTwNP9aA z60lDO`2L?O5h4~%=cLNM+ux&h;gB#iY zP}WI2T_bdopG#-Vz8WeGHX)SOks(1CgZiLlvg!VSgg`a(TNM3R7qsNN5`(|$#E{(v8*J= zWSY4Y9g>EM`AIrZLj|HrLPA*qg-t>MOWlw)P#9Q71I3`ciVzwo`lfOuYhb>ypn;-8 zJkz2YD2Anz%32~C^XRhxRBNCxkXX-YplB|`T&96ypa`a-fugw_ceMrz1HwMOc#&2K ziXEYW@%y`sn@SZ_O=K#l9KjVOF{gsU3YjSjsGu-VP(igtR>7ahwTbA4U*fV{%6h?L zS%8Z#JAb7}tgtT1P^nrGjrc`YQ}H`VN*13=@lYyIVKG?`Wbq_A<ug!El$M(l~>&5c%E=yWeN^+_Zrx@^`?GNCe z8f?cVX4B{%3|_UFPQA;IlZWm@Cm7&se&Z(fE5C+A0bo+CFHo1$S-gf)%Qzu#?i69; zb(bYz_vgZ%tKPUN6fPXif!&86Lo*^fNwi023s8@XNa;m;ikE2`{K8gZdF?E{GR4-; z(yKu5J%GTzaJtbmN4iRsBl@;c>oxIJo#V;pTW$CRHlvZpIQ+$KH+06q#E))s1*x5P z(?^)=y^T&gI_j_Yw9}r}S4};GJF=;OZw!__9$JCt4)Fa*@uFGVyp`JC=v@)EYrPtL zfj7&zM=>tEx)b4JlAEj)IIG0L*ET}G4z1{7U0}4Jv0K+PaNt%nWo4Bq1GsV~K};8R z+uRaQqHn{}Qi`|L7YK0#G>icJ0Pf{XEkwFXho_jAD_#VA23xA9_@;td`3nT0 z56|I2!B|-sXy(;4`Z-+B+bau1wHItYu3|7kxEjqK2LpFRaWS*c3b>XINZB>R?<79^ caZXq^zXBGWrzJU-+z#D{GcE=9u-@7HAH!`(X8-^I literal 0 HcmV?d00001 diff --git a/samples/java/training/pom.xml b/samples/java/training/pom.xml new file mode 100644 index 00000000000..39dda07e74b --- /dev/null +++ b/samples/java/training/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + org.myorg + training + 1.0-SNAPSHOT + + Train + + + 1.7 + 1.7 + + + + org.tensorflow + tensorflow + 1.4.0 + + + diff --git a/samples/java/training/src/main/java/Train.java b/samples/java/training/src/main/java/Train.java new file mode 100644 index 00000000000..4c73a779c83 --- /dev/null +++ b/samples/java/training/src/main/java/Train.java @@ -0,0 +1,91 @@ +/* Copyright 2018 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. +==============================================================================*/ + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Random; +import org.tensorflow.Graph; +import org.tensorflow.Session; +import org.tensorflow.Tensor; +import org.tensorflow.Tensors; + +/** + * Training a trivial linear model. + */ +public class Train { + public static void main(String[] args) throws Exception { + if (args.length != 2) { + System.err.println("Require two arguments: The GraphDef file and checkpoint directory"); + System.exit(1); + } + + final byte[] graphDef = Files.readAllBytes(Paths.get(args[0])); + final String checkpointDir = args[1]; + final boolean checkpointExists = Files.exists(Paths.get(checkpointDir)); + + try (Graph graph = new Graph(); + Session sess = new Session(graph); + Tensor checkpointPrefix = + Tensors.create(Paths.get(checkpointDir, "ckpt").toString())) { + graph.importGraphDef(graphDef); + + // Initialize or restore + if (checkpointExists) { + sess.runner().feed("save/Const", checkpointPrefix).addTarget("save/restore_all").run(); + } else { + sess.runner().addTarget("init").run(); + } + System.out.print("Starting from : "); + printVariables(sess); + + // Train a bunch of times. + // (Will be much more efficient if we sent batches instead of individual values). + final Random r = new Random(); + final int NUM_EXAMPLES = 500; + for (int i = 1; i <= 5; i++) { + for (int n = 0; n < NUM_EXAMPLES; n++) { + float in = r.nextFloat(); + try (Tensor input = Tensors.create(in); + Tensor target = Tensors.create(3 * in + 2)) { + sess.runner().feed("input", input).feed("target", target).addTarget("train").run(); + } + } + System.out.printf("After %5d examples: ", i*NUM_EXAMPLES); + printVariables(sess); + } + + // Checkpoint + sess.runner().feed("save/Const", checkpointPrefix).addTarget("save/control_dependency").run(); + + // Example of "inference" in the same graph: + try (Tensor input = Tensors.create(1.0f); + Tensor output = + sess.runner().feed("input", input).fetch("output").run().get(0).expect(Float.class)) { + System.out.printf( + "For input %f, produced %f (ideally would produce 3*%f + 2)\n", + input.floatValue(), output.floatValue(), input.floatValue()); + } + } + } + + private static void printVariables(Session sess) { + List> values = sess.runner().fetch("W/read").fetch("b/read").run(); + System.out.printf("W = %f\tb = %f\n", values.get(0).floatValue(), values.get(1).floatValue()); + for (Tensor t : values) { + t.close(); + } + } +} From 553334f37ffb331fdf44aed0f78684a5e4a16514 Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 16 Jan 2018 12:13:16 -0500 Subject: [PATCH 2/5] Update README.md There is no `data` directory, these instructions work without this line. --- samples/java/object_detection/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/java/object_detection/README.md b/samples/java/object_detection/README.md index 76baa1b6d23..20804270669 100644 --- a/samples/java/object_detection/README.md +++ b/samples/java/object_detection/README.md @@ -21,8 +21,6 @@ in Java. | tar -xz -C models/ ``` -3. Locate the corresponding labels file in the `data/` directory. - 3. Have some test images handy. For example: ``` mkdir -p images From 91c72cdf520dc9d2b4614771a6fdc98f29f250e2 Mon Sep 17 00:00:00 2001 From: Mark Daoust Date: Tue, 16 Jan 2018 12:14:15 -0500 Subject: [PATCH 3/5] Update README.md set `/examples` as the working directory --- samples/java/docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/java/docker/README.md b/samples/java/docker/README.md index 0dfdd759b29..3c60b423452 100644 --- a/samples/java/docker/README.md +++ b/samples/java/docker/README.md @@ -4,7 +4,7 @@ Typical usage: ``` docker build -t java-tensorflow . -docker run -it --rm -v ${PWD}/..:/examples java-tensorflow +docker run -it --rm -v ${PWD}/..:/examples -w /examples java-tensorflow ``` That second command will pop you into a shell which has all From 0652d8660694d83a267a6153e74845638a90ff04 Mon Sep 17 00:00:00 2001 From: Asim Shankar Date: Tue, 16 Jan 2018 11:39:07 -0800 Subject: [PATCH 4/5] Move from samples/java to samples/languages/java --- samples/{ => languages}/java/README.md | 0 samples/{ => languages}/java/docker/Dockerfile | 0 samples/{ => languages}/java/docker/README.md | 0 samples/{ => languages}/java/label_image/.gitignore | 0 samples/{ => languages}/java/label_image/README.md | 0 .../{ => languages}/java/label_image/download.py | 0 .../{ => languages}/java/label_image/download.sh | 0 .../java/label_image/download_sample_images.sh | 0 samples/{ => languages}/java/label_image/pom.xml | 0 .../java/label_image/src/main/java/LabelImage.java | 0 .../java/object_detection/.gitignore | 0 .../{ => languages}/java/object_detection/README.md | 0 .../java/object_detection/download.sh | 0 .../{ => languages}/java/object_detection/pom.xml | 0 .../src/main/java/DetectObjects.java | 0 .../protos/StringIntLabelMapOuterClass.java | 0 samples/{ => languages}/java/training/.gitignore | 0 samples/{ => languages}/java/training/README.md | 0 .../java/training/model/create_graph.py | 0 .../{ => languages}/java/training/model/graph.pb | Bin samples/{ => languages}/java/training/pom.xml | 0 .../java/training/src/main/java/Train.java | 0 22 files changed, 0 insertions(+), 0 deletions(-) rename samples/{ => languages}/java/README.md (100%) rename samples/{ => languages}/java/docker/Dockerfile (100%) rename samples/{ => languages}/java/docker/README.md (100%) rename samples/{ => languages}/java/label_image/.gitignore (100%) rename samples/{ => languages}/java/label_image/README.md (100%) rename samples/{ => languages}/java/label_image/download.py (100%) rename samples/{ => languages}/java/label_image/download.sh (100%) rename samples/{ => languages}/java/label_image/download_sample_images.sh (100%) rename samples/{ => languages}/java/label_image/pom.xml (100%) rename samples/{ => languages}/java/label_image/src/main/java/LabelImage.java (100%) rename samples/{ => languages}/java/object_detection/.gitignore (100%) rename samples/{ => languages}/java/object_detection/README.md (100%) rename samples/{ => languages}/java/object_detection/download.sh (100%) rename samples/{ => languages}/java/object_detection/pom.xml (100%) rename samples/{ => languages}/java/object_detection/src/main/java/DetectObjects.java (100%) rename samples/{ => languages}/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java (100%) rename samples/{ => languages}/java/training/.gitignore (100%) rename samples/{ => languages}/java/training/README.md (100%) rename samples/{ => languages}/java/training/model/create_graph.py (100%) rename samples/{ => languages}/java/training/model/graph.pb (100%) rename samples/{ => languages}/java/training/pom.xml (100%) rename samples/{ => languages}/java/training/src/main/java/Train.java (100%) diff --git a/samples/java/README.md b/samples/languages/java/README.md similarity index 100% rename from samples/java/README.md rename to samples/languages/java/README.md diff --git a/samples/java/docker/Dockerfile b/samples/languages/java/docker/Dockerfile similarity index 100% rename from samples/java/docker/Dockerfile rename to samples/languages/java/docker/Dockerfile diff --git a/samples/java/docker/README.md b/samples/languages/java/docker/README.md similarity index 100% rename from samples/java/docker/README.md rename to samples/languages/java/docker/README.md diff --git a/samples/java/label_image/.gitignore b/samples/languages/java/label_image/.gitignore similarity index 100% rename from samples/java/label_image/.gitignore rename to samples/languages/java/label_image/.gitignore diff --git a/samples/java/label_image/README.md b/samples/languages/java/label_image/README.md similarity index 100% rename from samples/java/label_image/README.md rename to samples/languages/java/label_image/README.md diff --git a/samples/java/label_image/download.py b/samples/languages/java/label_image/download.py similarity index 100% rename from samples/java/label_image/download.py rename to samples/languages/java/label_image/download.py diff --git a/samples/java/label_image/download.sh b/samples/languages/java/label_image/download.sh similarity index 100% rename from samples/java/label_image/download.sh rename to samples/languages/java/label_image/download.sh diff --git a/samples/java/label_image/download_sample_images.sh b/samples/languages/java/label_image/download_sample_images.sh similarity index 100% rename from samples/java/label_image/download_sample_images.sh rename to samples/languages/java/label_image/download_sample_images.sh diff --git a/samples/java/label_image/pom.xml b/samples/languages/java/label_image/pom.xml similarity index 100% rename from samples/java/label_image/pom.xml rename to samples/languages/java/label_image/pom.xml diff --git a/samples/java/label_image/src/main/java/LabelImage.java b/samples/languages/java/label_image/src/main/java/LabelImage.java similarity index 100% rename from samples/java/label_image/src/main/java/LabelImage.java rename to samples/languages/java/label_image/src/main/java/LabelImage.java diff --git a/samples/java/object_detection/.gitignore b/samples/languages/java/object_detection/.gitignore similarity index 100% rename from samples/java/object_detection/.gitignore rename to samples/languages/java/object_detection/.gitignore diff --git a/samples/java/object_detection/README.md b/samples/languages/java/object_detection/README.md similarity index 100% rename from samples/java/object_detection/README.md rename to samples/languages/java/object_detection/README.md diff --git a/samples/java/object_detection/download.sh b/samples/languages/java/object_detection/download.sh similarity index 100% rename from samples/java/object_detection/download.sh rename to samples/languages/java/object_detection/download.sh diff --git a/samples/java/object_detection/pom.xml b/samples/languages/java/object_detection/pom.xml similarity index 100% rename from samples/java/object_detection/pom.xml rename to samples/languages/java/object_detection/pom.xml diff --git a/samples/java/object_detection/src/main/java/DetectObjects.java b/samples/languages/java/object_detection/src/main/java/DetectObjects.java similarity index 100% rename from samples/java/object_detection/src/main/java/DetectObjects.java rename to samples/languages/java/object_detection/src/main/java/DetectObjects.java diff --git a/samples/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java b/samples/languages/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java similarity index 100% rename from samples/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java rename to samples/languages/java/object_detection/src/main/java/object_detection/protos/StringIntLabelMapOuterClass.java diff --git a/samples/java/training/.gitignore b/samples/languages/java/training/.gitignore similarity index 100% rename from samples/java/training/.gitignore rename to samples/languages/java/training/.gitignore diff --git a/samples/java/training/README.md b/samples/languages/java/training/README.md similarity index 100% rename from samples/java/training/README.md rename to samples/languages/java/training/README.md diff --git a/samples/java/training/model/create_graph.py b/samples/languages/java/training/model/create_graph.py similarity index 100% rename from samples/java/training/model/create_graph.py rename to samples/languages/java/training/model/create_graph.py diff --git a/samples/java/training/model/graph.pb b/samples/languages/java/training/model/graph.pb similarity index 100% rename from samples/java/training/model/graph.pb rename to samples/languages/java/training/model/graph.pb diff --git a/samples/java/training/pom.xml b/samples/languages/java/training/pom.xml similarity index 100% rename from samples/java/training/pom.xml rename to samples/languages/java/training/pom.xml diff --git a/samples/java/training/src/main/java/Train.java b/samples/languages/java/training/src/main/java/Train.java similarity index 100% rename from samples/java/training/src/main/java/Train.java rename to samples/languages/java/training/src/main/java/Train.java From 28bd85d1d87707a0b0978407f9b2f2f13ae0a333 Mon Sep 17 00:00:00 2001 From: Asim Shankar Date: Tue, 16 Jan 2018 11:43:24 -0800 Subject: [PATCH 5/5] Sanity test: Make sure the examples compile. --- samples/languages/java/docker/README.md | 3 +++ samples/languages/java/docker/sanity_test.sh | 7 +++++++ .../languages/java/docker/test_inside_container.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100755 samples/languages/java/docker/sanity_test.sh create mode 100644 samples/languages/java/docker/test_inside_container.sh diff --git a/samples/languages/java/docker/README.md b/samples/languages/java/docker/README.md index 3c60b423452..eaa3ca33e6d 100644 --- a/samples/languages/java/docker/README.md +++ b/samples/languages/java/docker/README.md @@ -10,3 +10,6 @@ docker run -it --rm -v ${PWD}/..:/examples -w /examples java-tensorflow That second command will pop you into a shell which has all the dependencies required to execute the scripts and Java examples. + +The script `sanity_test.sh` builds this container and runs a compilation +check on all the maven projects. diff --git a/samples/languages/java/docker/sanity_test.sh b/samples/languages/java/docker/sanity_test.sh new file mode 100755 index 00000000000..a4343f287df --- /dev/null +++ b/samples/languages/java/docker/sanity_test.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# +# Silly sanity test +DIR="$(cd "$(dirname "$0")" && pwd -P)" + +docker build -t java-tensorflow . +docker run -it --rm -v ${PWD}/..:/examples java-tensorflow bash /examples/docker/test_inside_container.sh diff --git a/samples/languages/java/docker/test_inside_container.sh b/samples/languages/java/docker/test_inside_container.sh new file mode 100644 index 00000000000..221a0233450 --- /dev/null +++ b/samples/languages/java/docker/test_inside_container.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -ex + +cd /examples/label_image +mvn compile + +cd /examples/object_detection +mvn compile + +cd /examples/training +mvn compile