File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -1280,8 +1280,27 @@ def test_get_image_segmentation_results(self):
1280
1280
target = prediction_service_client .PredictionServiceClient ,
1281
1281
attribute = "predict" ,
1282
1282
return_value = gca_prediction_response ,
1283
- ):
1284
- segmentation_response = model .segment_image (base_image = image )
1283
+ ) as mock_predict :
1284
+ binary_color_threshold = 48
1285
+ segmentation_response = model .segment_image (
1286
+ base_image = image ,
1287
+ confidence_threshold = 0.1 ,
1288
+ binary_color_threshold = binary_color_threshold ,
1289
+ )
1290
+ mock_predict .assert_called_once_with (
1291
+ endpoint = "projects/123456789/locations/us-central1/publishers/google/models/image-segmentation-001" ,
1292
+ instances = [
1293
+ {
1294
+ "base64EncodedImage" : image ._image_bytes ,
1295
+ "parameters" : {
1296
+ "mode" : "foreground" ,
1297
+ "confidenceThreshold" : 0.1 ,
1298
+ "binaryColorThreshold" : 48 ,
1299
+ },
1300
+ }
1301
+ ],
1302
+ retry = base ._DEFAULT_RETRY ,
1303
+ )
1285
1304
assert len (segmentation_response ) == 1
1286
1305
1287
1306
Original file line number Diff line number Diff line change @@ -1938,6 +1938,7 @@ def segment_image(
1938
1938
max_predictions : Optional [int ] = None ,
1939
1939
confidence_threshold : Optional [float ] = 0.1 ,
1940
1940
mask_dilation : Optional [float ] = None ,
1941
+ binary_color_threshold : Optional [float ] = None ,
1941
1942
) -> ImageSegmentationResponse :
1942
1943
"""Segments an image.
1943
1944
@@ -1967,6 +1968,10 @@ def segment_image(
1967
1968
mask_dilation: A value to dilate the masks by. The value must be in the
1968
1969
range of 0.0 (no dilation) and 1.0 (the whole image will be masked).
1969
1970
The default is 0.0.
1971
+ binary_color_threshold: The threshold to convert the grayscale soft
1972
+ mask to a binary color black and white mask. The value must be
1973
+ in the range of 0 and 255, or -1 to disable the thresholding.
1974
+ The default is 96.
1970
1975
1971
1976
Returns:
1972
1977
An `ImageSegmentationResponse` object with the generated masks,
@@ -2000,6 +2005,8 @@ def segment_image(
2000
2005
parameters ["confidenceThreshold" ] = confidence_threshold
2001
2006
if mask_dilation :
2002
2007
parameters ["maskDilation" ] = mask_dilation
2008
+ if binary_color_threshold :
2009
+ parameters ["binaryColorThreshold" ] = binary_color_threshold
2003
2010
2004
2011
response = self ._endpoint .predict (
2005
2012
instances = [instance ],
You can’t perform that action at this time.
0 commit comments