@JayantaPoddar Thank you very much for your information. So I need to use arcpy instead. Now I can get the layer from my ArcGIS Pro from my map object.
But looking back to my original purpose, to use it inside arcgis.learn libraries, I think I have some knowledge gap here. Now I am not sure I can use this layer object from arcpy to input as parameters inside the export_training_data function.
My first attempt running the export_training_data function with the local layers produce error: "ArcGIS Online does not support export_training_data function." The error sounds like not related to ArcPy though.
Here is my script:
from arcgis.gis import GIS
my_gis = GIS()
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.listMaps("Map")[0]
for lyr in aprxMap.listLayers():
if lyr.name == "clipped_building":
boundaryLayer = lyr
elif lyr.name == "20200428SA1_B05_grid.tif":
imageLayer = lyr
from arcgis import GIS, learn
from arcgis.learn import export_training_data
outFolder = r"E:\Data\Out\building"
export = export_training_data(input_raster=imageLayer,
output_location=outFolder,
input_class_data=boundaryLayer,
chip_format="PNG",
tile_size={"x":448,"y":448},
stride_size={"x":224,"y":224}, metadata_format="PASCAL_VOC_rectangles",
classvalue_field = "CLASSNO",
buffer_radius = 6
)