Reputation: 191
In the official documentation, detect_object
said to be able to use existing Feature Service for the output_name
variable.
output_name
Optional. If not provided, a FeatureLayer is created by the method and used as the output . You can pass in an existing Feature Service Item from your GIS to use that instead. Alternatively, you can pass in the name of the output Feature Service that should be created by this method to be used as the output for the tool. A RuntimeError is raised if a service by that name already exists
However, I got this error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
In [30]:
Line 1: out_objects = detect_objects(
File D:\Program Files\ArcGIS\Pro\bin\Python\envs\arc-big\Lib\site-packages\arcgis\learn\__init__.py, in detect_objects:
Line 347: return gis._tools.rasteranalysis.detect_objects_using_deep_learning(
File D:\Program Files\ArcGIS\Pro\bin\Python\envs\arc-big\Lib\site-packages\arcgis\_impl\tools.py, in detect_objects_using_deep_learning:
Line 11600: output_service_name = output_objects.replace(" ", "_")
File D:\Program Files\ArcGIS\Pro\bin\Python\envs\arc-big\Lib\site-packages\arcgis\gis\__init__.py, in __getattr__:
Line 13557: raise AttributeError(
AttributeError: 'Item' object has no attribute 'replace'
---------------------------------------------------------------------------
from arcgis import GIS
from arcgis.learn import Model, detect_objects
gis = GIS(
url='url', # fill with correct credentials
username='username',
password='username',
)
detect_objects_model_package = gis.content.get('some_id')
raster = gis.content.get('some_other_id')
detect_objects_model = Model(detect_objects_model_package)
detect_objects_model.install(gis=gis)
test_notebook = gis.content.get('another_id') # this is the target feature service
context = {
'cellSize': 0.1,
'processorType':'GPU'
}
out_objects = detect_objects(
input_raster=raster,
model=detect_objects_model,
output_name=test_notebook,
context=context,
gis=gis
)
My goal is to append the inferencing result to an existing feature service
detect_objects
only? (I have the work around with .edit_features()
, but to me the documentation implies it can use an existing feature service as the output, so I'm curious)Thanks!
Upvotes: 1
Views: 42
Reputation: 395
Note: Not a fix -- just wanted to post this to highlight how you can further investigate the traceback by inspecting ArcGIS API for Python source to confirm/deny your suspicions.
Yes, looking at the detect_objects()
function in version 2.3.1
of the ArcGIS API for Python, it only has logic to handle str
or None
input for output_name
.
Inspecting arcgis/learn/__init__.py
> detect_objects()
reveals that it just calls gis._tools.rasteranalysis.detect_objects_using_deep_learning()
and arcgis/_impl/tools.py
> _RasterAnalysisTools.detect_objects_using_deep_learning()
(where the error occurs) only handles None
case, otherwise handling object like str
:
if output_objects is None:
output_service_name = (
"DetectObjectsUsingDeepLearning_" + _id_generator()
)
output_objects = output_service_name.replace(" ", "_")
else:
output_service_name = output_objects.replace(" ", "_")
Looks like you already submitted an issue for this: https://github.com/Esri/arcgis-python-api/issues/1947. Not much else to do for now, unless you want to edit source which you could do by updating arcgis/_impl/tools.py
> _RasterAnalysisTools.detect_objects_using_deep_learning()
to handle an arcgis.gis.Item
object.
Upvotes: 0