本文整理汇总了Java中org.tensorflow.DataType类的典型用法代码示例。如果您正苦于以下问题:Java DataType类的具体用法?Java DataType怎么用?Java DataType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataType类属于org.tensorflow包,在下文中一共展示了DataType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Inception
import org.tensorflow.DataType; //导入依赖的package包/类
public Inception(String graphPath, String labelsPath) throws IOException{
graphDef = Files.readAllBytes(Paths.get(graphPath));
labels = Files.readAllLines(Paths.get(labelsPath));
Graph g = new Graph();
s = new Session(g);
GraphBuilder b = new GraphBuilder(g);
// - The model was trained with images scaled to 224x224 pixels.
// - The colors, represented as R, G, B in 1-byte each were converted to
// float using (value - Mean)/Scale.
final int H = 224;
final int W = 224;
final float mean = 117f;
final float scale = 1f;
output = b.div(
b.sub(
b.resizeBilinear(
b.expandDims(
b.cast(b.decodeJpeg(b.placeholder("input", DataType.STRING), 3), DataType.FLOAT),
b.constant("make_batch", 0)),
b.constant("size", new int[] {H, W})),
b.constant("mean", mean)),
b.constant("scale", scale));
}
示例2: LabelImageTensorflowInputConverter
import org.tensorflow.DataType; //导入依赖的package包/类
public LabelImageTensorflowInputConverter() {
graph = new Graph();
GraphBuilder b = new GraphBuilder(graph);
// Some constants specific to the pre-trained model at:
// https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
// - The model was trained with images scaled to 224x224 pixels.
// - The colors, represented as R, G, B in 1-byte each were converted to
// float using (value - Mean)/Scale.
final int H = 224;
final int W = 224;
final float mean = 117f;
final float scale = 1f;
final Output input = b.placeholder("input", DataType.STRING);
graphOutput =
b.div(
b.sub(
b.resizeBilinear(
b.expandDims(
b.cast(b.decodeJpeg(input, 3), DataType.FLOAT),
b.constant("make_batch", 0)),
b.constant("size", new int[] {H, W})),
b.constant("mean", mean)),
b.constant("scale", scale));
}
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:27,代码来源:LabelImageTensorflowInputConverter.java
示例3: constructAndExecuteGraphToNormalizeImage
import org.tensorflow.DataType; //导入依赖的package包/类
private Tensor constructAndExecuteGraphToNormalizeImage(byte[] imageBytes) {
try (Graph g = new Graph()) {
GraphBuilder b = new GraphBuilder(g);
// Some constants specific to the pre-trained model at:
// https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
//
// - The model was trained with images scaled to 224x224 pixels.
// - The colors, represented as R, G, B in 1-byte each were
// converted to
// float using (value - Mean)/Scale.
final int H = 224;
final int W = 224;
final float mean = 117f;
final float scale = 1f;
// Since the graph is being constructed once per execution here, we
// can use a constant for the
// input image. If the graph were to be re-used for multiple input
// images, a placeholder would
// have been more appropriate.
final Output input = b.constant("input", imageBytes);
final Output output = b
.div(b.sub(
b.resizeBilinear(b.expandDims(b.cast(b.decodeJpeg(input, 3), DataType.FLOAT),
b.constant("make_batch", 0)), b.constant("size", new int[] { H, W })),
b.constant("mean", mean)), b.constant("scale", scale));
try (Session s = new Session(g)) {
return s.runner().fetch(output.op().name()).run().get(0);
}
}
}
示例4: constructAndExecuteGraphToNormalizeImage
import org.tensorflow.DataType; //导入依赖的package包/类
private static Tensor constructAndExecuteGraphToNormalizeImage(byte[] imageBytes) {
try (Graph g = new Graph()) {
GraphBuilder b = new GraphBuilder(g);
// Some constants specific to the pre-trained model at:
// https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
//
// - The model was trained with images scaled to 224x224 pixels.
// - The colors, represented as R, G, B in 1-byte each were converted to
// float using (value - Mean)/Scale.
final int H = 224;
final int W = 224;
final float mean = 117f;
final float scale = 1f;
// Since the graph is being constructed once per execution here, we can use a
// constant for the
// input image. If the graph were to be re-used for multiple input images, a
// placeholder would
// have been more appropriate.
final Output input = b.constant("input", imageBytes);
final Output output = b
.div(b.sub(
b.resizeBilinear(b.expandDims(b.cast(b.decodeJpeg(input, 3), DataType.FLOAT),
b.constant("make_batch", 0)), b.constant("size", new int[] { H, W })),
b.constant("mean", mean)), b.constant("scale", scale));
try (Session s = new Session(g)) {
return s.runner().fetch(output.op().name()).run().get(0);
}
}
}
示例5: testImgToTensorMapping
import org.tensorflow.DataType; //导入依赖的package包/类
/** Tests the tensor(RAI, int[]) function */
@Test
public void testImgToTensorMapping() {
assertEquals(1, 1);
final long[] dims = new long[] { 5, 4, 3, 2 };
final int[] mapping = new int[] { 1, 3, 0, 2 }; // A strange mapping
final long[] shape = new long[] { 3, 5, 2, 4 };
final int n = dims.length;
// ByteType
testImg2TensorMappingForType(new ArrayImgFactory<ByteType>().create(dims, new ByteType()), mapping, n, shape,
DataType.UINT8);
// DoubleType
testImg2TensorMappingForType(new ArrayImgFactory<DoubleType>().create(dims, new DoubleType()), mapping, n,
shape, DataType.DOUBLE);
// FloatType
testImg2TensorMappingForType(new ArrayImgFactory<FloatType>().create(dims, new FloatType()), mapping, n, shape,
DataType.FLOAT);
// IntType
testImg2TensorMappingForType(new ArrayImgFactory<IntType>().create(dims, new IntType()), mapping, n, shape,
DataType.INT32);
// LongType
testImg2TensorMappingForType(new ArrayImgFactory<LongType>().create(dims, new LongType()), mapping, n, shape,
DataType.INT64);
}
示例6: constructGraphToNormalizeImage
import org.tensorflow.DataType; //导入依赖的package包/类
private Graph constructGraphToNormalizeImage() {
Graph graph = new Graph();
GraphBuilder b = new GraphBuilder(graph);
// - The model was trained with images scaled to 150x150 pixels.
// - The colors, represented as R, G, B in 1-byte each were converted to
// float using value/Scale.
final int H = 150;
final int W = 150;
final float scale = 255f;
final Output input = b.placeholder("input", DataType.STRING);
final Output output =
b.div(
b.resizeBilinear(
b.expandDims(
b.cast(b.decodeJpeg(input, 3), DataType.FLOAT),
b.constant("make_batch", 0)),
b.constant("size", new int[] {H, W})),
b.constant("scale", scale));
normalizationOutputOperationName = output.op().name();
return graph;
}
示例7: getValues
import org.tensorflow.DataType; //导入依赖的package包/类
static
public List<?> getValues(Tensor tensor){
DataType dataType = tensor.dataType();
switch(dataType){
case FLOAT:
return Floats.asList(TensorUtil.toFloatArray(tensor));
case DOUBLE:
return Doubles.asList(TensorUtil.toDoubleArray(tensor));
case INT32:
return Ints.asList(TensorUtil.toIntArray(tensor));
case INT64:
return Longs.asList(TensorUtil.toLongArray(tensor));
case STRING:
return Arrays.asList(TensorUtil.toStringArray(tensor));
case BOOL:
return Booleans.asList(TensorUtil.toBooleanArray(tensor));
default:
throw new IllegalArgumentException();
}
}
示例8: constructAndExecuteGraphToNormalizeImage
import org.tensorflow.DataType; //导入依赖的package包/类
private static Tensor constructAndExecuteGraphToNormalizeImage(byte[] imageBytes) {
//Graph construction: using the OperationBuilder class to construct a graph to decode, resize and normalize a JPEG image.
try (Graph g = new Graph()) {
GraphBuilder b = new GraphBuilder(g);
// Some constants specific to the pre-trained model at:
// https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
//
// - The model was trained with images scaled to 224x224 pixels.
// - The colors, represented as R, G, B in 1-byte each were
// converted to
// float using (value - Mean)/Scale.
final int H = 224;
final int W = 224;
final float mean = 117f;
final float scale = 1f;
// Since the graph is being constructed once per execution here, we
// can use a constant for the
// input image. If the graph were to be re-used for multiple input
// images, a placeholder would
// have been more appropriate.
final Output input = b.constant("input", imageBytes);
final Output output = b
.div(b.sub(
b.resizeBilinear(b.expandDims(b.cast(b.decodeJpeg(input, 3), DataType.FLOAT),
b.constant("make_batch", 0)), b.constant("size", new int[] { H, W })),
b.constant("mean", mean)), b.constant("scale", scale));
try (Session s = new Session(g)) {
return s.runner().fetch(output.op().name()).run().get(0);
}
}
}
开发者ID:kaiwaehner,项目名称:kafka-streams-machine-learning-examples,代码行数:34,代码来源:Kafka_Streams_TensorFlow_Image_Recognition_Example.java
示例9: constructAndExecuteGraphToNormalizeImage
import org.tensorflow.DataType; //导入依赖的package包/类
private static Tensor constructAndExecuteGraphToNormalizeImage(byte[] imageBytes) {
try (Graph g = new Graph()) {
GraphBuilder b = new GraphBuilder(g);
// Some constants specific to the pre-trained model at:
// https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
//
// - The model was trained with images scaled to 224x224 pixels.
// - The colors, represented as R, G, B in 1-byte each were
// converted to
// float using (value - Mean)/Scale.
final int H = 224;
final int W = 224;
final float mean = 117f;
final float scale = 1f;
// Since the graph is being constructed once per execution here, we
// can use a constant for the
// input image. If the graph were to be re-used for multiple input
// images, a placeholder would
// have been more appropriate.
final Output input = b.constant("input", imageBytes);
final Output output = b
.div(b.sub(
b.resizeBilinear(b.expandDims(b.cast(b.decodeJpeg(input, 3), DataType.FLOAT),
b.constant("make_batch", 0)), b.constant("size", new int[] { H, W })),
b.constant("mean", mean)), b.constant("scale", scale));
try (Session s = new Session(g)) {
return s.runner().fetch(output.op().name()).run().get(0);
}
}
}
开发者ID:kaiwaehner,项目名称:kafka-streams-machine-learning-examples,代码行数:32,代码来源:Kafka_Streams_TensorFlow_Image_Recognition_Example_IntegrationTest.java
示例10: toTensor
import org.tensorflow.DataType; //导入依赖的package包/类
public static Tensor toTensor(Tuple tuple) {
DataType dataType = DataType.valueOf(tuple.getString(TF_DATA_TYPE));
long[] shape = (long[]) tuple.getValue(TF_SHAPE);
byte[] bytes = (byte[]) tuple.getValue(TF_VALUE);
return Tensor.create(dataType, shape, ByteBuffer.wrap(bytes));
}
示例11: testImgToTensorReverse
import org.tensorflow.DataType; //导入依赖的package包/类
/** Tests the tensor(RAI) function */
@Test
public void testImgToTensorReverse() {
assertEquals(1, 1);
final long[] dims = new long[] { 20, 10, 3 };
final long[] shape = new long[] { 3, 10, 20 };
final int n = dims.length;
// ByteType
testImg2TensorReverseForType(new ArrayImgFactory<ByteType>().create(dims, new ByteType()), n, shape,
DataType.UINT8);
// DoubleType
testImg2TensorReverseForType(new ArrayImgFactory<DoubleType>().create(dims, new DoubleType()), n, shape,
DataType.DOUBLE);
// FloatType
testImg2TensorReverseForType(new ArrayImgFactory<FloatType>().create(dims, new FloatType()), n, shape,
DataType.FLOAT);
// IntType
testImg2TensorReverseForType(new ArrayImgFactory<IntType>().create(dims, new IntType()), n, shape,
DataType.INT32);
// LongType
testImg2TensorReverseForType(new ArrayImgFactory<LongType>().create(dims, new LongType()), n, shape,
DataType.INT64);
}
示例12: testImgToTensorDirect
import org.tensorflow.DataType; //导入依赖的package包/类
/** Tests the tensorDirect(RAI) function */
@Test
public void testImgToTensorDirect() {
assertEquals(1, 1);
final long[] dims = new long[] { 20, 10, 3 };
final int n = dims.length;
// ByteType
testImg2TensorDirectForType(new ArrayImgFactory<ByteType>().create(dims, new ByteType()), n, dims,
DataType.UINT8);
// DoubleType
testImg2TensorDirectForType(new ArrayImgFactory<DoubleType>().create(dims, new DoubleType()), n, dims,
DataType.DOUBLE);
// FloatType
testImg2TensorDirectForType(new ArrayImgFactory<FloatType>().create(dims, new FloatType()), n, dims,
DataType.FLOAT);
// IntType
testImg2TensorDirectForType(new ArrayImgFactory<IntType>().create(dims, new IntType()), n, dims,
DataType.INT32);
// LongType
testImg2TensorDirectForType(new ArrayImgFactory<LongType>().create(dims, new LongType()), n, dims,
DataType.INT64);
}
示例13: testImg2TensorReverseForType
import org.tensorflow.DataType; //导入依赖的package包/类
/** Tests the tensor(RAI) function for one image */
private <T extends RealType<T>> void testImg2TensorReverseForType(final Img<T> img, final int n, final long[] shape,
final DataType t) {
// Put some values to check into the image
List<Point> points = createTestPoints(n);
markPoints(img, points);
Tensor tensor = Tensors.tensor(img);
assertArrayEquals(shape, tensor.shape());
assertEquals(n, tensor.numDimensions());
assertEquals(t, tensor.dataType());
checkPointsTensor(tensor, IntStream.range(0, n).map(i -> n - 1 - i).toArray(), points);
}
示例14: testImg2TensorDirectForType
import org.tensorflow.DataType; //导入依赖的package包/类
/** Tests the tensorDirect(RAI) function for one image */
private <T extends RealType<T>> void testImg2TensorDirectForType(final Img<T> img, final int n, final long[] shape,
final DataType t) {
// Put some values to check into the image
List<Point> points = createTestPoints(n);
markPoints(img, points);
Tensor tensor = Tensors.tensorDirect(img);
assertArrayEquals(shape, tensor.shape());
assertEquals(n, tensor.numDimensions());
assertEquals(t, tensor.dataType());
checkPointsTensor(tensor, IntStream.range(0, n).toArray(), points);
}
示例15: testImg2TensorMappingForType
import org.tensorflow.DataType; //导入依赖的package包/类
/** Tests the tensor(RAI, int[]) function for one image */
private <T extends RealType<T>> void testImg2TensorMappingForType(final Img<T> img, final int[] mapping,
final int n, final long[] shape, final DataType t) {
// Put some values to check into the image
List<Point> points = createTestPoints(n);
markPoints(img, points);
Tensor tensor = Tensors.tensor(img, mapping);
assertArrayEquals(shape, tensor.shape());
assertEquals(n, tensor.numDimensions());
assertEquals(t, tensor.dataType());
checkPointsTensor(tensor, mapping, points);
}