/** * Returns a XGBoost model loader given the serialized model stored in the model URI. * * @param supplier {@link XGBoostModel} supplier. */ static XGBoostLoader create( final ThrowableSupplier<XGBoostModel> supplier, final Executor executor) { return ModelLoader.load(supplier, executor)::get; } }
/** * Returns a blocking {@link PreLoader}. Blocks till the model is loaded or a {@link Duration} * is met. * * @param loader model loader. * @param duration Amount of time that it should wait, if necessary, for model to be loaded. * @param <M> Underlying model instance. */ static <M extends Model<?>> PreLoader<M> preload( final ModelLoader<M> loader, final Duration duration) throws InterruptedException, ExecutionException, TimeoutException { return ModelLoader.loaded(loader.get(duration))::get; }
/** * Returns a Google Cloud ML Engine model loader that references the default model. * * @param projectId Google project id. * @param modelId model id. */ static MlEngineLoader create(final String projectId, final String modelId) throws IOException, GeneralSecurityException { return ModelLoader.loaded(MlEngineModel.create(projectId, modelId))::get; }
/** * Returns a TensorFlow model loader based on a saved model. * * @param supplier {@link TensorFlowModel} supplier. */ static TensorFlowLoader create(final ThrowableSupplier<TensorFlowModel> supplier) { final ModelLoader<TensorFlowModel> loader = ModelLoader .lift(supplier) .with(ModelMemoizer::memoize) .with(Preloader.preloadAsync()); return loader::get; }
/** * Get's the underlying model instance. * * @return Model instance */ default M get(final Duration duration) throws InterruptedException, ExecutionException, TimeoutException { return get().toCompletableFuture().get(duration.toMillis(), TimeUnit.MILLISECONDS); }
/** * Returns a Google Cloud ML Engine model loader. * * @param id {@link Model.Id} needs to be created with the following format: * <pre> * "projects/{PROJECT_ID}/models/{MODEL_ID}/versions/{MODEL_VERSION}" * </pre> */ static MlEngineLoader create(final Model.Id id) throws IOException, GeneralSecurityException { return ModelLoader.loaded(MlEngineModel.create(id))::get; } }
/** * Returns a TensorFlow model loader based on a serialized TensorFlow {@link Graph}. * * @param supplier {@link TensorFlowGraphModel} supplier. */ static TensorFlowGraphLoader create(final ThrowableSupplier<TensorFlowGraphModel> supplier) { final ModelLoader<TensorFlowGraphModel> loader = ModelLoader .lift(supplier) .with(ModelMemoizer::memoize) .with(Preloader.preloadAsync()); return loader::get; }
final CompletableFuture<List<Prediction<InputT, ValueT>>> future = modelLoader .get() .thenCompose( model -> {
/** * Returns a TensorFlow model loader based on a saved model. * * @param supplier {@link TensorFlowModel} supplier. * @param executor the executor to use for asynchronous execution. */ static TensorFlowLoader create( final ThrowableSupplier<TensorFlowModel> supplier, final Executor executor) { return ModelLoader.load(supplier, executor)::get; } }
/** * Returns a Google Cloud ML Engine model loader. * * @param projectId Google project id. * @param modelId model id. * @param versionId model version id. */ static MlEngineLoader create(final String projectId, final String modelId, final String versionId) throws IOException, GeneralSecurityException { return ModelLoader.loaded(MlEngineModel.create(projectId, modelId, versionId))::get; }
/** * Returns a TensorFlow model loader based on a serialized TensorFlow {@link Graph}. * * @param supplier {@link TensorFlowGraphModel} supplier. * @param executor the executor to use for asynchronous execution. */ static TensorFlowGraphLoader create( final ThrowableSupplier<TensorFlowGraphModel> supplier, final Executor executor) { return ModelLoader.load(supplier, executor)::get; } }
/** * Returns a blocking {@link ModelLoader}. Blocks till the model is loaded or a {@link Duration} * is met. * * @param supplier model supplier. * @param duration Amount of time that it should wait, if necessary, for model to be loaded. * @param executor the executor to use for asynchronous execution. * @param <M> Underlying model instance. */ static <M extends Model<?>> PreLoader<M> preload( final ThrowableSupplier<M> supplier, final Duration duration, final Executor executor) throws InterruptedException, ExecutionException, TimeoutException { return preload(ModelLoader.load(supplier, executor), duration)::get; }