Is there any way to retrain a change detector model?

313
3
Jump to solution
06-25-2021 11:21 PM
MaryamBarzegar
New Contributor II

Hello, I trained the ChangeDetector model with a training dataset and now I want to retrain the saved model with another dataset. I found train_model function for training a saved model but this function doesn't support the changedetector model. Is there any way to train a model in 2 steps? I mean using half of training dataset first and then retrain the saved model with other half?

0 Kudos
1 Solution

Accepted Solutions
Tim_McGinnes
Occasional Contributor III

Yes, the ChangeDetector class has a from_model function to load an existing model from disk.

So, first training do something like this:

from arcgis.learn import ChangeDetector, prepare_data
data_path = r'<path_to_first_data_folder>'
data = prepare_data(data_path, batch_size=1, dataset_type='ChangeDetection')
model = ChangeDetector(data)
model.fit(10, lr=1e-4)
model.show_results()
model.save(r'<path_to_save_folder>',save_inference_file=True)

And next time do this:

from arcgis.learn import ChangeDetector, prepare_data
data_path = r'<path_to_second_data_folder>'
data = prepare_data(data_path, batch_size=1, dataset_type='ChangeDetection')
model = ChangeDetector.from_model(r'<path_to_model_emd_file>',data)
model.fit(10, lr=1e-4)
model.show_results()
model.save(r'<path_to_save_folder>',save_inference_file=True)

In line 2 change the path to your second set of data. In line 4 it is now loading your saved model from the .emd file instead of creating a new one. I presume you could then save over the original model or save to a new file.

FYI - In version 1.8.5 of the ArcGIS Python API, the prepare_data function accepts a single path, or a list of paths, so you could train using multiple data folders in a single step if required.

View solution in original post

0 Kudos
3 Replies
MaryamBarzegar
New Contributor II

Hi @Tim_McGinnes , I was wondering if you know the answer 

0 Kudos
Tim_McGinnes
Occasional Contributor III

Yes, the ChangeDetector class has a from_model function to load an existing model from disk.

So, first training do something like this:

from arcgis.learn import ChangeDetector, prepare_data
data_path = r'<path_to_first_data_folder>'
data = prepare_data(data_path, batch_size=1, dataset_type='ChangeDetection')
model = ChangeDetector(data)
model.fit(10, lr=1e-4)
model.show_results()
model.save(r'<path_to_save_folder>',save_inference_file=True)

And next time do this:

from arcgis.learn import ChangeDetector, prepare_data
data_path = r'<path_to_second_data_folder>'
data = prepare_data(data_path, batch_size=1, dataset_type='ChangeDetection')
model = ChangeDetector.from_model(r'<path_to_model_emd_file>',data)
model.fit(10, lr=1e-4)
model.show_results()
model.save(r'<path_to_save_folder>',save_inference_file=True)

In line 2 change the path to your second set of data. In line 4 it is now loading your saved model from the .emd file instead of creating a new one. I presume you could then save over the original model or save to a new file.

FYI - In version 1.8.5 of the ArcGIS Python API, the prepare_data function accepts a single path, or a list of paths, so you could train using multiple data folders in a single step if required.

View solution in original post

0 Kudos
MaryamBarzegar
New Contributor II

Sorry for late reply, thank you so much!

0 Kudos