Viam C++ SDK current
Loading...
Searching...
No Matches
mlmodel_client.hpp
1// Copyright 2023 Viam Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <viam/api/service/mlmodel/v1/mlmodel.grpc.pb.h>
18
19#include <grpcpp/channel.h>
20
21#include <viam/sdk/services/mlmodel.hpp>
22
23namespace viam {
24namespace sdk {
25namespace impl {
26
33 public:
35 using service_type = viam::service::mlmodel::v1::MLModelService;
36
37 MLModelServiceClient(std::string name, std::shared_ptr<grpc::Channel> channel);
38
39 std::shared_ptr<named_tensor_views> infer(const named_tensor_views& inputs,
40 const ProtoStruct& extra) override;
41 struct metadata metadata(const ProtoStruct& extra) override;
42
43 // the `extra` param is frequently unnecessary but needs to be supported. Ideally, we'd
44 // like to live in a world where implementers of derived classes don't need to go out of
45 // their way to support two versions of a method (an `extra` version and a non-`extra`
46 // version), and users don't need to pass an unnecessary parameters to all method calls.
47 //
48 // To do this, we define in the parent resource class a non-virtual version of the methods
49 // that calls the virtual method and passes a `nullptr` by default in place of the `extra`
50 // param. In order to access these versions of the methods within the client code, however,
51 // we need to include these `using` lines.
54
55 private:
56 std::shared_ptr<grpc::Channel> channel_;
57 std::unique_ptr<service_type::StubInterface> stub_;
58};
59
60} // namespace impl
61} // namespace sdk
62} // namespace viam
Represents a machine trained learning model instance.
Definition mlmodel.hpp:35
std::shared_ptr< named_tensor_views > infer(const named_tensor_views &inputs)
Runs the model against the input tensors and returns inference results as tensors.
Definition mlmodel.hpp:95
virtual std::string name() const
Return the resource's name.
Definition mlmodel_client.hpp:32
std::shared_ptr< named_tensor_views > infer(const named_tensor_views &inputs, const ProtoStruct &extra) override
Runs the model against the input tensors and returns inference results as tensors.
Definition mlmodel.hpp:148