コード例 #1
0
        public async Task <IEnumerable <Detection> > Predict(Bitmap bmp)
        {
            if (_client == null)
            {
                throw new ApplicationException(nameof(_client));
            }

            // Desired image format
            const int         channels = 3;
            const int         width    = 300;
            const int         height   = 300;
            const PixelFormat format   = PixelFormat.Format24bppRgb;

            var shape = new TensorShapeProto
            {
                Dim = { new []
                        {
                            new TensorShapeProto.Types.Dim {
                                Name = "", Size = 1
                            },
                            new TensorShapeProto.Types.Dim {
                                Name = nameof(height), Size = height
                            },
                            new TensorShapeProto.Types.Dim {
                                Name = nameof(width), Size = width
                            },
                            new TensorShapeProto.Types.Dim {
                                Name = nameof(channels), Size = channels
                            },
                        } }
            };

            var proto = new TensorProto
            {
                TensorShape   = shape,
                Dtype         = Tensorflow.DataType.DtUint8,
                TensorContent = ToByteString(bmp, channels, width, height, format)
            };

            var request = new PredictRequest
            {
                ModelSpec = new ModelSpec {
                    Name = _model
                }
            };

            request.Inputs.Add("data", proto);

            // Send requenst for inference
            PredictResponse response = await _client.PredictAsync(request);

            return(ToDetections(response));
        }
コード例 #2
0
        /// <summary>Snippet for PredictAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task PredictResourceNamesAsync()
        {
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            ModelName      name    = ModelName.FromProjectLocationModel("[PROJECT]", "[LOCATION]", "[MODEL]");
            ExamplePayload payload = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string> {
                { "", "" },
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(name, payload, @params);
        }
        /// <summary>Snippet for PredictAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task PredictAsync()
        {
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            string         name    = "projects/[PROJECT]/locations/[LOCATION]/models/[MODEL]";
            ExamplePayload payload = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string> {
                { "", "" },
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(name, payload, @params);
        }
コード例 #4
0
        /// <summary>Snippet for PredictAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task PredictRequestObjectAsync()
        {
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            PredictRequest request = new PredictRequest
            {
                ModelName = ModelName.FromProjectLocationModel("[PROJECT]", "[LOCATION]", "[MODEL]"),
                Payload   = new ExamplePayload(),
                Params    = { { "", "" }, },
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(request);
        }
コード例 #5
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictAsync()
        {
            // Snippet: PredictAsync(ModelName,ExamplePayload,IDictionary<string, string>,CallSettings)
            // Additional: PredictAsync(ModelName,ExamplePayload,IDictionary<string, string>,CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            ModelName      name    = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]");
            ExamplePayload payload = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string>();
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(name, payload, @params);

            // End snippet
        }
コード例 #6
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictAsync()
        {
            // Snippet: PredictAsync(string, IEnumerable<Value>, Value, CallSettings)
            // Additional: PredictAsync(string, IEnumerable<Value>, Value, CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            string endpoint = "projects/[PROJECT]/locations/[LOCATION]/endpoints/[ENDPOINT]";
            IEnumerable <Value> instances = new Value[] { new Value(), };
            Value parameters = new Value();
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(endpoint, instances, parameters);

            // End snippet
        }
コード例 #7
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictResourceNamesAsync()
        {
            // Snippet: PredictAsync(EndpointName, IEnumerable<Value>, Value, CallSettings)
            // Additional: PredictAsync(EndpointName, IEnumerable<Value>, Value, CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            EndpointName        endpoint  = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]");
            IEnumerable <Value> instances = new Value[] { new Value(), };
            Value parameters = new Value();
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(endpoint, instances, parameters);

            // End snippet
        }
コード例 #8
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictAsync_RequestObject()
        {
            // Snippet: PredictAsync(PredictRequest,CallSettings)
            // Additional: PredictAsync(PredictRequest,CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            PredictRequest request = new PredictRequest
            {
                ModelName = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"),
                Payload   = new ExamplePayload(),
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(request);

            // End snippet
        }
コード例 #9
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictRequestObjectAsync()
        {
            // Snippet: PredictAsync(PredictRequest, CallSettings)
            // Additional: PredictAsync(PredictRequest, CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            PredictRequest request = new PredictRequest
            {
                EndpointAsEndpointName = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"),
                Instances  = { new Value(), },
                Parameters = new Value(),
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(request);

            // End snippet
        }
コード例 #10
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictRequestObjectAsync()
        {
            // Snippet: PredictAsync(PredictRequest, CallSettings)
            // Additional: PredictAsync(PredictRequest, CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            PredictRequest request = new PredictRequest
            {
                Name    = "",
                Payload = new ExamplePayload(),
                Params  = { { "", "" }, },
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(request);

            // End snippet
        }
コード例 #11
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictRequestObjectAsync()
        {
            // Snippet: PredictAsync(PredictRequest, CallSettings)
            // Additional: PredictAsync(PredictRequest, CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            PredictRequest request = new PredictRequest
            {
                Placement    = "",
                UserEvent    = new UserEvent(),
                PageSize     = 0,
                PageToken    = "",
                Filter       = "",
                ValidateOnly = false,
                Params       = { { "", new Value() }, },
                Labels       = { { "", "" }, },
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(request);

            // End snippet
        }
        /// <summary>Snippet for Predict</summary>
        public async Task PredictRequestObjectAsync()
        {
            // Snippet: PredictAsync(PredictRequest, CallSettings)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            PredictRequest request = new PredictRequest
            {
                PlacementName = PlacementName.FromProjectLocationCatalogEventStorePlacement("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]"),
                UserEvent     = new UserEvent(),
                Filter        = "",
                DryRun        = false,
                Params        = { { "", new Value() }, },
                Labels        = { { "", "" }, },
            };
            // Make the request
            PagedAsyncEnumerable <PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.PredictAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((PredictResponse.Types.PredictionResult item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((PredictResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (PredictResponse.Types.PredictionResult item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <PredictResponse.Types.PredictionResult> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (PredictResponse.Types.PredictionResult item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        /// <summary>Snippet for Predict</summary>
        public async Task PredictAsync()
        {
            // Snippet: PredictAsync(string, UserEvent, string, int?, CallSettings)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            string    name      = "projects/[PROJECT]/locations/[LOCATION]/catalogs/[CATALOG]/eventStores/[EVENT_STORE]/placements/[PLACEMENT]";
            UserEvent userEvent = new UserEvent();
            // Make the request
            PagedAsyncEnumerable <PredictResponse, PredictResponse.Types.PredictionResult> response = predictionServiceClient.PredictAsync(name, userEvent);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((PredictResponse.Types.PredictionResult item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((PredictResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (PredictResponse.Types.PredictionResult item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <PredictResponse.Types.PredictionResult> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (PredictResponse.Types.PredictionResult item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }