The output of predict function using ChangeDetector model is not georeferenced

1836
13
Jump to solution
04-25-2021 10:48 PM
MaryamBarzegar
New Contributor III

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.  

0 Kudos
1 Solution

Accepted Solutions
Tim_McGinnes
Occasional Contributor III

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.

location.jpg

View solution in original post

0 Kudos
13 Replies
Tim_McGinnes
Occasional Contributor III

Hi Maryam,

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.

0 Kudos
MaryamBarzegar
New Contributor III

Hi Tim

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? 

0 Kudos
Tim_McGinnes
Occasional Contributor III

Sorry, should have noticed that your output format is PNG. If you rename that copied file from .TFW to .PGW it should work.

0 Kudos
MaryamBarzegar
New Contributor III

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).

0 Kudos
MaryamBarzegar
New Contributor III

@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. 

MaryamBarzegar_0-1620528926673.png

 

  

0 Kudos
MaryamBarzegar
New Contributor III

The image has the same rows and columns and looks like a rectangle

MaryamBarzegar_0-1620531614248.pngMaryamBarzegar_1-1620531628455.png

 

0 Kudos
Tim_McGinnes
Occasional Contributor III

Hi Maryam,

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. 

0 Kudos
MaryamBarzegar
New Contributor III

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?

MaryamBarzegar_8-1620604933816.png

 

Unfortunately I can't share the images. 

Before:

MaryamBarzegar_4-1620604758987.png

MaryamBarzegar_5-1620604776489.png

 

After:

MaryamBarzegar_6-1620604831672.pngMaryamBarzegar_7-1620604847493.png

This is the code:

 

from arcgis.learn import ChangeDetector
import os
import torch
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')


cd.predict(crop_predict= True,
before_image=before_img,
after_image=after_img,
save=True)

 

 

 

0 Kudos
MaryamBarzegar
New Contributor III

Prediction:

MaryamBarzegar_10-1620605486695.png

 

0 Kudos