I have written python code to run the "Export Training Data for Deep Learning" tool several times with different extents each time. I am not used to altering environments and am also a beginner with python, but I am very familiar with the "Export Training ..." tool. I have not had success getting the tool to run with the extents I specify, it always runs it with the default extents. I have had success getting it to only process the extents I want it to when I ran the tool through the geoprocessing tab instead of in python.
I have tried two ways to set my extents. Previous to this block of code I have already defined Xmin, Ymin, Xmax, and Ymax, along with all my variables for the "Export Training ..." tool. Here are the two lines of code for the first method I tried:
arcpy.env.extent = arcpy.Extent(Xmin,Ymin,Xmax,Ymax)
arcpy.ia.ExportTrainingDataForDeepLearning(in_raster, [...] )
Here is the code for the second method:
with arcpy.EnvManager(extent=str(Xmin)+" "+str(Ymin)+" "+str(Xmax)+" "+str(Ymax)):
#below I print that last command to check I got this in the same format as I hope it is in
#it has printed how I expect it to
print("extent="+str(Xmin)+" "+str(Ymin)+" "+str(Xmax)+" "+str(Ymax))
arcpy.ia.ExportTrainingDataForDeepLearning(in_raster, [...] )
Here is the code for the time it worked from the geoprocessing window:
with arcpy.EnvManager(extent="186250 1556250 302500 1767500"):
arcpy.ia.ExportTrainingDataForDeepLearning("Extract Bands_Gr1_03E", r"D:\LHD_GIS\ResearchAttempt4\TestExports\Dam58_03", "LHD_Poly_all_TileName", "TIFF", 1024, 1024, 128, 128, "ONLY_TILES_WITH_FEATURES", "PASCAL_VOC_rectangles", 0, None, 0, None, 45, "MAP_SPACE", "PROCESS_AS_MOSAICKED_IMAGE", "NO_BLACKEN", "FIXED_SIZE")
The tool runs perfectly except that it still uses default extents. Thus far I haven't let it loop through to run the command a second time because it takes 4 hours to run on the entire raster rather than the extents I want it to run on. Any ideas would be much appreciated! I have ArcGIS Pro 2.7.3. Here are some screenshots.
Here is the report from the history window the time the tool worked from the geoproccessing window.

This is the my most recent run (currently being processed) that should have extents set:
