Hello, I trained ChangeDetector model and I used predict function for Inference. My inputs are two georeferenced TIFF images but the result is a PNG image which is not georeferenced. Is there any way to have a georeferenced output? For other models the Classify pixels using deep learning tool can be used and the output of model would be georeferenced but this tool cannot be used for ChangeDetector model.
Solved! Go to Solution.
Ok, I have created a simple test PNG file of 1081 x 1005 pixels. I then created a .pgw file for it. The last step was to run the Define Projection tool as set the coordinate system to WGS 1984. Bringing this into Pro looks like it matches your location ok. Attached is the zipped test image.
Now what you can try is delete all the test5_predict files apart from the .png (so delete .pgw, .png.aux.xml etc.). Then copy my test.pgw file and rename it test5_predict.pgw. Then before adding it to a map in Pro, run the Define Projection tool and set to WGS 1984. This should now bring it into the right location when you add to the map. Because you are working in decimal degrees, there could be some precision errors due to the large number of decimal places.
If the source images have an additional header file (like .TFW), then the easiest way would be to copy that file and rename to match your output filename.
If there is no .TFW file, then you could write a script to read the origin point and cell size from the source images and create the TFW file yourself. If you need to set the projection then the Define Projection tool could do that.
Note: this will probably not work if the images have been georeferenced (scaled, rotated etc.) because the parameters would be in the .aux.xml file and would be hard to apply to a new image. If it's just a normal image then you should be ok though.
Let me know if you need any more info.
Thank you for your response. My input images are georeferenced and I have .TFW file for them but I copied that file and renamed to match the output and it didn't work. So, it only works when the input is not georeferenced?
I tried but it doesn't work. I think the problem is georeferencing as you mentioned before since I have .tif.aux.xml, .tif.ovr, and .tfw for each image (I also tried changing all to .png.aux.xml; .png.ovr; .pgw but it didn't work either).
@Tim_McGinnes do you have any idea how I can control the cell size? I just found that apart from losing location information, the cell size of output is different from the cell size of input. Therefore, the output image is longer alongside y direction. Unfortunately I can't even solve it using scale in the Georeference tool bar since it scales the image in both x and y directions. I couldn't find any argument to control this in predict function. I also tried doing prediction with the same image I used for training to see whether it changes the cell size or not but same thing happened.
I have done my own change detector model, based on the sample notebook. My before and after inferencing images have the same coordinate system and pixel dimensions (2861 x 4013). When I do the cd.predict step I have crop_predict=True and save=True. The output image is called detected_change.png and has the same dimensions as the input images. This image doesn't know anything about cell size as it is just a simple image. For me, I just copy the .tfw file from one of the input images, copy it into the same folder as detected_change.png and rename it to detected_change.pgw. I can do a Define Projection to make it the same coordinate system as my input images but this is not necessary.
I think there must be something with your before and after input images that is giving you problems later. Are you able to share them? If not can you provide screenshots of the Source properties for both the before and after images? Make sure you expand the Raster Information, Extent and Spatial Reference sections.
Thank you for your quick response. I do the same for creating .pgw file but it doesn't work (I renamed detected_change to test5_predict). Am I missing something?
Unfortunately I can't share the images.
This is the code:
from arcgis.learn import ChangeDetector
torch.cuda.is_available = lambda : False
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model_path = r'C:/Users/maryam.barzegar/Desktop/hongkong/testcase4/change detection/Training6/models/change_detection_pansharpened_NIR8_resnet34'
cd = ChangeDetector.from_model (model_path, data= None)
test_images = r'C:/Users/maryam.barzegar/Desktop/hongkong/Testcase5/Training9/Inference/image'
before_img = os.path.join(test_images, 'test5_before.tif')
after_img = os.path.join(test_images, 'test5_after.tif')