/** * Note: Please use Models from zoltar-models module. * * <p>Creates a TensorFlow model based on a frozen, serialized TensorFlow {@link Graph}.</p> * * @param id model id @{link Model.Id}. * @param graphDef byte array representing the TensorFlow {@link Graph} definition. * @param config ConfigProto config for TensorFlow {@link Session}. * @param prefix a prefix that will be prepended to names in graphDef. */ public static TensorFlowGraphModel create(final Model.Id id, final byte[] graphDef, @Nullable final ConfigProto config, @Nullable final String prefix) throws IOException { final Graph graph = new Graph(); final Session session = new Session(graph, config != null ? config.toByteArray() : null); final long loadStart = System.currentTimeMillis(); if (prefix == null) { LOG.debug("Loading graph definition without prefix"); graph.importGraphDef(graphDef); } else { LOG.debug("Loading graph definition with prefix: {}", prefix); graph.importGraphDef(graphDef, prefix); } LOG.info("TensorFlow graph loaded in {} ms", System.currentTimeMillis() - loadStart); return new AutoValue_TensorFlowGraphModel(id, graph, session); }
/** * Note: Please use Models from zoltar-models module. * * <p>Creates a TensorFlow model based on a frozen, serialized TensorFlow {@link Graph}. * * @param id model id @{link Model.Id}. * @param graphDef byte array representing the TensorFlow {@link Graph} definition. * @param config ConfigProto config for TensorFlow {@link Session}. * @param prefix a prefix that will be prepended to names in graphDef. */ public static TensorFlowGraphModel create( final Model.Id id, final byte[] graphDef, @Nullable final ConfigProto config, @Nullable final String prefix) throws IOException { final Graph graph = new Graph(); final Session session = new Session(graph, config != null ? config.toByteArray() : null); final long loadStart = System.currentTimeMillis(); if (prefix == null) { LOG.debug("Loading graph definition without prefix"); graph.importGraphDef(graphDef); } else { LOG.debug("Loading graph definition with prefix: {}", prefix); graph.importGraphDef(graphDef, prefix); } LOG.info("TensorFlow graph loaded in {} ms", System.currentTimeMillis() - loadStart); return new AutoValue_TensorFlowGraphModel(id, graph, session); }
private void initOptionsIfNeeded() { //setup the status object to be used for all tensorflow calls if(status == null) { status = TF_NewStatus(); } if (options == null) { options = TF_NewSessionOptions(); if(protoBufConfigProto != null) { BytePointer bytePointer = new BytePointer(protoBufConfigProto.toByteArray()); TF_SetConfig(options,bytePointer,bytePointer.getStringBytes().length,status); if (TF_GetCode(status) != TF_OK) { throw new IllegalStateException("ERROR: Unable to set value configuration:" + TF_Message(status).getString()); } } } }