Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HELP] Using eo-learn for the classification of land surface types of Ukraine #674

Closed
fuckingsore opened this issue May 28, 2023 · 23 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@fuckingsore
Copy link

Hi guys!
I am doing research work for my university and I have a task to create a module for the classification of land surface types of Ukraine based on the analysis of aerial and space images with the help of your library - eo-learn. I have to train the model in Slovenia and then test it in Ukraine. Or immediately develop a model based on the geodata of Ukraine.
I am new to AI and your library. Please tell me how to correctly perform this problem using your library. Maybe there is a detailed instruction or an example?
I will be very grateful for the help and a detailed answer.

@fuckingsore fuckingsore added help wanted Extra attention is needed question Further information is requested labels May 28, 2023
@zigaLuksic
Copy link
Collaborator

Hi @fuckingsore
here it an example of how we did land-cover/land-use classification for Slovenia, it might be the starting point that you're looking for.

@fuckingsore
Copy link
Author

Hi, thank you.
On which sites and how can I find these files, but with geodata of Ukraine?
svn_border.geojson
land_use_10class_reference_slovenia_partial.gpkg

@zigaLuksic
Copy link
Collaborator

I do not know where you could find LULC data for Ukraine, since it's very country specific.
You might have some luck with the OSM data or perhaps this. You might be able to find some more data online.

@fuckingsore
Copy link
Author

Why I have problems with these imports?
pycharm64_SsjhvIeoMb

@zigaLuksic
Copy link
Collaborator

Why I have problems with these imports?

Seems like you are trying to run some outdated code

@fuckingsore
Copy link
Author

Thanks, that's what I thought

@fuckingsore
Copy link
Author

Good evening.
If I run your example with Slovenia, and then just substitute pictures of Ukraine, will I get a classification of the land of Ukraine?

@zigaLuksic
Copy link
Collaborator

You can train a model on Slovenian data and apply it to Ukraine, yes

however since the model will be trained on the Slovenian surface, it will very likely perform worse on Ukraine than a model trained on Ukrainian surface. It mostly depends on how similar the two regions are, for instance a model trained on Slovenia will perform poorly in Egypt (lots of bare land) or Norway (lots of snow and sea).

If you are lacking good quality data in Ukraine it might still be worth a try. In the past we also tried mixing high-accuracy (in terms of label) Slovenian data and lower accuracy data from a different country (where only some regions had good labels for instance).

@fuckingsore
Copy link
Author

I don't understand what I need to change in order to run a trained model on Slovenian data to classify the territory of Ukraine. Tell me what needs to be changed in this example and how, please.
https://github.com/sentinel-hub/eo-learn/blob/master/examples/land-cover-map/SI_LULC_pipeline.ipynb

@mlubej
Copy link
Contributor

mlubej commented Jun 5, 2023

Hi @fuckingsore

I don't understand what I need to change in order to run a trained model on Slovenian data to classify the territory of Ukraine. Tell me what needs to be changed in this example and how, please.

  1. run the notebook to obtain the model trained on data from Slovenia
  2. create a copy of the notebook and keep the sections for downloading data and applying the model to get the predictions
  3. change the area and time of interest to suit your needs and run the predictions on the obtained data using the model from step 1.

For more information, you can follow along the blog posts on medium:

@fuckingsore
Copy link
Author

So I need to change geojson from step 1? but how to change it correctly so that it fits the code further?

@mlubej
Copy link
Contributor

mlubej commented Jun 5, 2023

So I need to change geojson from step 1? but how to change it correctly so that it fits the code further?

Once the AOI is set and the eopatches are downloaded, it doesn't matter where the eopatches are coming from, from the code point of view it should all fit together regardless.

At the same time, the notebook is just an example tutorial on how to use the library and how to construct a pipeline for land use classification, it is not meant to be an out-of-the-box solution for all kinds of problems, so it is expected of the users to make changes of their own and use it as a base to build their own project.

My suggestion would be to try to understand how it all fits together and read the documentation and the blog posts for details. We cannot solve the whole problem for you, but we are happy to help with details and specific problems. However, please keep in mind to provide specific details about the problem you are facing, comments like above are too vague and hard to pinpoint the exact issues you are dealing with.

@fuckingsore
Copy link
Author

fuckingsore commented Jun 5, 2023

Why there is this error and how fix it?

Draw the RGB image

fig, axs = plt.subplots(nrows=5, ncols=5, figsize=(20, 20))

time_id = np.where(feature_importances == np.max(feature_importances))[0][0]

for i in tqdm(range(len(patchIDs))):
sample_path = os.path.join(EOPATCH_SAMPLES_FOLDER, f"eopatch_{i}")
eopatch = EOPatch.load(sample_path, lazy_loading=True)
ax = axs[i // 5][i % 5]
ax.imshow(np.clip(eopatch.data["FEATURES"][time_id][..., [2, 1, 0]] * 2.5, 0, 1))
ax.set_xticks([])
ax.set_yticks([])
ax.set_aspect("auto")
del eopatch

fig.subplots_adjust(wspace=0, hspace=0)
pycharm64_TgspZGUT3F

@fuckingsore
Copy link
Author

And I also have this error in this part of code:
fig, axs = plt.subplots(nrows=5, ncols=5, figsize=(20, 25))

for i in tqdm(range(len(patchIDs))):
eopatch_path = os.path.join(EOPATCH_SAMPLES_FOLDER, f"eopatch_{i}")
eopatch = EOPatch.load(eopatch_path, lazy_loading=True)
ax = axs[i // 5][i % 5]
im = ax.imshow(eopatch.mask_timeless["LBL_GBM"].squeeze(), cmap=lulc_cmap, norm=lulc_norm)
ax.set_xticks([])
ax.set_yticks([])
ax.set_aspect("auto")
del eopatch

fig.subplots_adjust(wspace=0, hspace=0)

cb = fig.colorbar(im, ax=axs.ravel().tolist(), orientation="horizontal", pad=0.01, aspect=100)
cb.ax.tick_params(labelsize=20)
cb.set_ticks([entry.id for entry in LULC])
cb.ax.set_xticklabels([entry.name for entry in LULC], rotation=45, fontsize=15)
plt.show()
pycharm64_55iZ2628jp

@fuckingsore
Copy link
Author

Before I used another geojson, eopatches were downloaded successfully and in first part of this notebook rgb picture was painted

@mlubej
Copy link
Contributor

mlubej commented Jun 5, 2023

The first error states you are trying to access temporal slice 11, but the size of the temporal array is 2, perhaps manually set the time_id to 0 or 1. Perhaps the data you downloaded is not of the size you expect, so I would check the downloaded eopatches

the second issue is probably related to some problem which occurred in between. You are accessing the LBL_GBM key in the eopatch, but it doesn't seem to exist, meaning that something seemed to have gone wrong in the prediction step. What exactly went wrong, I cannot say.

What is the temporal range you are using?

@fuckingsore
Copy link
Author

I used temporal range 2022-06-01, 2022-06-30

@mlubej
Copy link
Contributor

mlubej commented Jun 5, 2023

I used temporal range 2022-06-01, 2022-06-30

Well, that explains it. You are using 1 month of data with Sentinel-2 imagery, there aren't always that many satellite images available in such a short time span, especially with cloud filtering applied.

The classification process in the notebook expects a full year worth of data, so try to change as little as possible aside from the AOI and year of the time period if you don't wish to run into unexpected problems

@mlubej
Copy link
Contributor

mlubej commented Jun 5, 2023

For starters I would suggest focusing on a small AOI in Ukraine and 1 year of data, so you can create a working prototype of the project. Perhaps you could use a shorter period than 1 year, but definitely more than just a few months.

@fuckingsore
Copy link
Author

Hello, guys!
Why does this happen? The area is ~13900 km2.
In QGIS and on first step, I have correct image of this area.
pycharm64_3E3CCvc8V2
pycharm64_6HetsFUlsT

@fuckingsore
Copy link
Author

I have one more question. If I understand correctly, you collect data per pixel for almost a year. This is so that the result is not affected by the time of year. Can I train a model based on just one snapshot, i.e. split the time series into separate data and train on that? Is it realistic to implement and how to implement it correctly?

@mlubej
Copy link
Contributor

mlubej commented Jun 12, 2023

Why does this happen? The area is ~13900 km2.

the area that you are splitting seems to span 2 UTM zones, so the one on the right is plotted with the wrong UTM zone. Probably the notebook you are using to plot assumes a single UTM vector file, so if you want a proper plot, you should convert to some common CRS (like WGS84) just for plotting.

I have one more question. If I understand correctly, you collect data per pixel for almost a year. This is so that the result is not affected by the time of year.

Correct, or rather to take the full year info into account, so we're not affected by missing data, bad images, or some temporary change on the land.

Can I train a model based on just one snapshot, i.e. split the time series into separate data and train on that? Is it realistic to implement and how to implement it correctly?

You are using the words "one snapshot" and "time series" together, which probably doesn't make sense. If you use just one snapshot, there will be no time series, just a single image.

But sure, you can still do classification based on a single image, but as I mentioned, that image has to be nearly perfect (no clouds, cloud shadows, haze, artifacts, etc... ), in those areas the classification will likely fail

@fuckingsore
Copy link
Author

Thank you, guys!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants