I am attempting to save a deep learning model to my arcgis online account using arcgis.learn, then install the model to run on a raster. However, using the Model() function outputs <empty Model> even after I am able to fetch the model, and .install() outputs:
RuntimeError Traceback (most recent call last) In [86]: Line 1: detect_objects_model.install() File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\learn\__init__.py, in install: Line 1412: "model object should be created from a portal item or a portal url" RuntimeError: model object should be created from a portal item or a portal url
I've set up my gis using my university portal and logged in successfully. I'm not sure why this is happening; it's doing this for every model.
import arcgis
import sys
from arcgis import GIS, learn
from arcgis.raster import analytics
from arcgis.raster.functions import extract_band, apply, clip
from arcgis.raster.analytics import list_datastore_content
from arcgis.learn import SingleShotDetector, prepare_data, Model, list_models, detect_objects
arcgis.env.verbose = True
from arcgis.geocoding import geocode
import os
from pathlib import Path
gis = GIS('https://umainegis.maps.arcgis.com/', '#####', '#####')
data_path = Path(r"I:\Other Maps\Deep_Learning\dl_trial1")
data_path
data = prepare_data(data_path, {0:'GBBG', 1:'HERG', 2:'DCCO'}, batch_size=162, no_check=True)
data.classes
data.show_batch()
ssd = SingleShotDetector(data, grids=[8], zooms=[1.0], ratios=[[1.0, 1.0]])
ssd.lr_find()
ssd.fit(10, lr=slice(2e-3, 3e-2))
ssd.show_results(thresh=0.8)
ssd.save('BirdDetector-ssd3', publish=True, gis=gis)
detect_objects_model = gis.content.get('4f22749c8265400ea560303dd708b90b')
detect_objects_model
detect_objects_model = Model(detect_objects_model_package)
detect_objects_model
detect_objects_model.install()
ArcGIS version 2.9.1.
Are you using these frameworks and instructions?
Yes, I've installed the deep learning installer (2.9) and all of the corresponding packages are installed. I was able to create a model, but I cannot use the following lines without throwing the runtime error provided above:
detect_objects_model = Model(detect_objects_model_package) detect_objects_model detect_objects_model.install()
The main problem is that detect_objects_model_package is not declared or populated anywhere in your script.
It should be something like (from this answer)
detect_objects_model_package = gis.content.get(item_id) detect_objects_model = Model(detect_objects_model_package) detect_objects_model.install(gis=gis)
You have hardcoded the AGOL ItemID as well - are you sure that's the correct one? Running the script again will probably give you a new ItemID each time.