Java Code Examples for org.tensorflow.framework.AttrValue#getValueCase()
The following examples show how to use
org.tensorflow.framework.AttrValue#getValueCase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConverter.java From vespa with Apache License 2.0 | 6 votes |
private static TensorShapeProto tensorFlowShape(NodeDef node) { // Use specific shape if available... AttrValue attrShape = node.getAttrMap().get("shape"); if (attrShape != null && attrShape.getValueCase() == AttrValue.ValueCase.SHAPE) { return attrShape.getShape(); } // ... else use inferred shape AttrValue attrOutputShapes = node.getAttrMap().get("_output_shapes"); if (attrOutputShapes == null) throw new IllegalArgumentException("_output_shapes attribute of '" + node.getName() + "' " + "does not exist"); if (attrOutputShapes.getValueCase() != AttrValue.ValueCase.LIST) throw new IllegalArgumentException("_output_shapes attribute of '" + node.getName() + "' " + "is not of expected type"); return attrOutputShapes.getList().getShape(0); // support multiple outputs? }
Example 2
Source File: AttributeConverter.java From vespa with Apache License 2.0 | 6 votes |
@Override public Optional<Value> get(String key) { if (attributeMap.containsKey(key)) { AttrValue attrValue = attributeMap.get(key); if (attrValue.getValueCase() == AttrValue.ValueCase.TENSOR) { return Optional.empty(); // requires type } if (attrValue.getValueCase() == AttrValue.ValueCase.B) { return Optional.of(new BooleanValue(attrValue.getB())); } if (attrValue.getValueCase() == AttrValue.ValueCase.I) { return Optional.of(new DoubleValue(attrValue.getI())); } if (attrValue.getValueCase() == AttrValue.ValueCase.F) { return Optional.of(new DoubleValue(attrValue.getF())); } } return Optional.empty(); }
Example 3
Source File: AttributeConverter.java From vespa with Apache License 2.0 | 6 votes |
@Override public Optional<List<Value>> getList(String key) { if (attributeMap.containsKey(key)) { AttrValue attrValue = attributeMap.get(key); if (attrValue.getValueCase() == AttrValue.ValueCase.LIST) { AttrValue.ListValue listValue = attrValue.getList(); if ( ! listValue.getBList().isEmpty()) { return Optional.of(listValue.getBList().stream().map(BooleanValue::new).collect(Collectors.toList())); } if ( ! listValue.getIList().isEmpty()) { return Optional.of(listValue.getIList().stream().map(DoubleValue::new).collect(Collectors.toList())); } if ( ! listValue.getFList().isEmpty()) { return Optional.of(listValue.getFList().stream().map(DoubleValue::new).collect(Collectors.toList())); } // add the rest } } return Optional.empty(); }
Example 4
Source File: LoadTensorFlow.java From neo4j-ml-procedures with Apache License 2.0 | 5 votes |
private Object getValue(AttrValue v) { switch (v.getValueCase()) { case S: return v.getS().toStringUtf8(); case I: return v.getI(); case F: return v.getF(); case B: return v.getB(); case TYPE: return v.getType().name(); // todo case SHAPE: return v.getShape().toString(); // tdo case TENSOR: return v.getTensor().toString(); // todo handle with prefxied properties case LIST: return v.getList().toString(); // todo getType/Count(idx) and then handle each type with prefixed property case FUNC: return v.getFunc().getAttrMap().toString(); // todo handle recursively case PLACEHOLDER: break; case VALUE_NOT_SET: return null; default: return null; } return null; }
Example 5
Source File: TypeConverter.java From vespa with Apache License 2.0 | 5 votes |
private static DataType tensorFlowValueType(NodeDef node) { AttrValue attrValueList = node.getAttrMap().get("dtypes"); if (attrValueList == null) return DataType.DT_DOUBLE; // default. This will usually (always?) be used. TODO: How can we do better? if (attrValueList.getValueCase() != AttrValue.ValueCase.LIST) return DataType.DT_DOUBLE; // default return attrValueList.getList().getType(0); // support multiple outputs? }
Example 6
Source File: AttributeConverter.java From vespa with Apache License 2.0 | 5 votes |
@Override public Optional<Value> get(String key, OrderedTensorType type) { if (attributeMap.containsKey(key)) { AttrValue attrValue = attributeMap.get(key); if (attrValue.getValueCase() == AttrValue.ValueCase.TENSOR) { return Optional.of(new TensorValue(TensorConverter.toVespaTensor(attrValue.getTensor(), type))); } } return get(key); }