Skip to content

Commit

Permalink
continue working on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
favyen2 committed Jan 14, 2025
1 parent fab4a5f commit 0062745
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
50 changes: 32 additions & 18 deletions docs/satlas_marine_infra.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ can use the code below to identify a suitable bounding box:

longitude = 120.148
latitude = 24.007
window_size = 4096

import json
import shapely
Expand All @@ -40,11 +41,15 @@ can use the code below to identify a suitable bounding box:
src_geom = STGeometry(WGS84_PROJECTION, shapely.Point(longitude, latitude), None)
dst_projection = get_utm_ups_projection(longitude, latitude, 10, -10)
dst_geom = src_geom.to_projection(dst_projection)
center_point = (
int(dst_geom.shp.x) // 2048 * 2048,
int(dst_geom.shp.y) // 2048 * 2048,
)
bounds = (
int(dst_geom.shp.x) - 2048,
int(dst_geom.shp.y) - 2048,
int(dst_geom.shp.x) + 2048,
int(dst_geom.shp.y) + 2048,
center_point[0] - window_size // 2,
center_point[1] - window_size // 2,
center_point[0] + window_size // 2,
center_point[1] + window_size // 2,
)
print(json.dumps(dst_projection.serialize()))
print(json.dumps(bounds))
Expand All @@ -54,8 +59,10 @@ time range, it should be a seven month range to give enough options to pick the
30-day mosaics, note that the timestamps are ISO 8601 formatted.

mkdir out_dir
mkdir scratch_dir
python -m rslp.main satlas predict MARINE_INFRA '{"crs": "EPSG:32651", "x_resolution": 10, "y_resolution": -10}' '[18937, -267842, 23033, -263746]' '["2024-01-01T00:00:00+00:00", "2024-08-01T00:00:00+00:00"]' out_dir/ scratch_dir/ --use_rtree_index false
python -m rslp.main satlas predict MARINE_INFRA '{"crs": "EPSG:32651", "x_resolution": 10, "y_resolution": -10}' '[18432, -268288, 22528, -264192]' '["2024-01-01T00:00:00+00:00", "2024-08-01T00:00:00+00:00"]' out_dir/ scratch_dir/ --use_rtree_index false

You may need to delete the "scratch_dir" directory if it exists already. This is used
to store a temporary rslearn dataset for ingesting the Sentinel-2 input images.

This generates a GeoJSON in out_dir but it is in pixel coordinates. Convert to
longitude/latitude coordinates using this script (which can also be used to merge
Expand All @@ -76,24 +83,31 @@ Training
First, download the training dataset:

cd rslearn_projects
mkdir -p project_data/datasets/sentinel2_vessels/
wget https://storage.googleapis.com/ai2-rslearn-projects-data/sentinel2_vessels/sentinel2_vessels.tar -O project_data/datasets/sentinel2_vessels.tar
tar xvf project_data/datasets/sentinel2_vessels.tar --directory project_data/datasets/sentinel2_vessels/
mkdir -p project_data/datasets/satlas_marine_infra/
wget https://storage.googleapis.com/ai2-rslearn-projects-data/satlas_marine_infra/satlas_marine_infra.tar -O project_data/datasets/satlas_marine_infra.tar
tar xvf project_data/datasets/satlas_marine_infra.tar --directory project_data/datasets/satlas_marine_infra/

It is an rslearn dataset consisting of window folders like
`windows/sargassum_train/1186117_1897173_158907/`. Inside each window folder:
`windows/label/2102272_1262592/`. Inside each window folder:

- `layers/sentinel2/` contains different Sentinel-2 bands used by the model, such as
`layers/sentinel2/R_G_B/image.png`.
- `layers/label/data.geojson` contains the positions of ships. These are offset from
the bounds of the window which are in `metadata.json`, so subtract the window's
bounds to get pixel coordinates relative to the image.
- `layers/sentinel2{.1,.2,.3}/` contains the four input Sentinel-2 mosaics.
- `layers/label/data.geojson` contains the positions of marine infrastructure. These
are offset from the bounds of the window which are in `metadata.json`, so subtract
the window's bounds to get pixel coordinates relative to the image.
- `layers/mask/mask/image.png` contains a mask specifying the valid portion of the
window. The labels were originally annotated in WebMercator projection, but have been
re-projected to UTM in this dataset; the transformation results in a non-rectangular
extent, so the window corresponds to the rectangular bounds of that extent while the
mask specifies the extent within those bounds. This is used in the mask step in the
model configuration file `data/satlas_marine_infra/config.yaml` to black out the
other parts of the input image.

To train the model, run:
Use the command below to train the model. Note that Weights & Biases is needed. You can
disable W&B with `--no_log true` but then it may be difficult to track the metrics.

python -m rslp.rslearn_main model fit --config data/sentinel2_vessels/config.yaml --data.init_args.path project_data/datasets/sentinel2_vessels/
python -m rslp.rslearn_main model fit --config data/satlas_marine_infra/config.yaml --data.init_args.path project_data/datasets/satlas_marine_infra/

To visualize outputs on the validation set:

mkdir vis
python -m rslp.rslearn_main model test --config data/sentinel2_vessels/config.yaml --data.init_args.path project_data/datasets/sentinel2_vessels/ --model.init_args.visualize_dir=vis/
python -m rslp.rslearn_main model test --config data/satlas_marine_infra/config.yaml --data.init_args.path project_data/datasets/satlas_marine_infra/ --model.init_args.visualize_dir=vis/
3 changes: 2 additions & 1 deletion docs/sentinel2_vessels.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ It is an rslearn dataset consisting of window folders like
the bounds of the window which are in `metadata.json`, so subtract the window's
bounds to get pixel coordinates relative to the image.

To train the model, run:
Use the command below to train the model. Note that Weights & Biases is needed. You can
disable W&B with `--no_log true` but then it may be difficult to track the metrics.

python -m rslp.rslearn_main model fit --config data/sentinel2_vessels/config.yaml --data.init_args.path project_data/datasets/sentinel2_vessels/

Expand Down

0 comments on commit 0062745

Please sign in to comment.