Spaces:
Sleeping
Sleeping
florinbarbisch
commited on
Commit
·
d955727
1
Parent(s):
85b44b9
Added: aws s3 replacement
Browse files- .env.template +3 -3
- inference.py +3 -17
- pages/2_Perform_Crop_Classification.py +2 -3
- requirements.txt +0 -1
.env.template
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
1 |
+
USE_LOCAL_DATA=False
|
2 |
+
TITILER_ENDPOINT=
|
3 |
+
COG_URL=
|
inference.py
CHANGED
@@ -11,7 +11,6 @@ import numpy as np
|
|
11 |
from rasterio.features import shapes
|
12 |
from shapely.geometry import shape
|
13 |
import geopandas as gpd
|
14 |
-
import boto3
|
15 |
from dotenv import load_dotenv
|
16 |
|
17 |
from messis.messis import LogConfusionMatrix
|
@@ -203,28 +202,15 @@ def crop_predictions_to_gdf(field_ids, targets, predictions, transform, crs, cla
|
|
203 |
|
204 |
return gdf
|
205 |
|
206 |
-
def generate_presigned_url(bucket_name, object_key, expiration=3600):
|
207 |
-
"""Generate a pre-signed URL for an S3 object."""
|
208 |
-
s3_client = boto3.client('s3', region_name='eu-central-1')
|
209 |
-
presigned_url = s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': object_key}, ExpiresIn=expiration)
|
210 |
-
return presigned_url
|
211 |
-
|
212 |
def perform_inference(lon, lat, model, config, debug=False):
|
213 |
-
# Bucket and object paths
|
214 |
-
bucket_name = 'messis-demo'
|
215 |
-
features_key = 'stacked_features_cog.tif'
|
216 |
-
labels_key = 'labels_cog.tif'
|
217 |
-
field_ids_key = 'field_ids_cog.tif'
|
218 |
-
|
219 |
if os.environ.get('USE_LOCAL_DATA') == "True":
|
220 |
features_path = "./data/stacked_features_cog.tif"
|
221 |
labels_path = "./data/labels_cog.tif"
|
222 |
field_ids_path = "./data/field_ids_cog.tif"
|
223 |
else:
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
field_ids_path = generate_presigned_url(bucket_name, field_ids_key)
|
228 |
|
229 |
# Local paths for stats and dataset info
|
230 |
stats_path = "./data/chips_stats.yaml"
|
|
|
11 |
from rasterio.features import shapes
|
12 |
from shapely.geometry import shape
|
13 |
import geopandas as gpd
|
|
|
14 |
from dotenv import load_dotenv
|
15 |
|
16 |
from messis.messis import LogConfusionMatrix
|
|
|
202 |
|
203 |
return gdf
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
def perform_inference(lon, lat, model, config, debug=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
if os.environ.get('USE_LOCAL_DATA') == "True":
|
207 |
features_path = "./data/stacked_features_cog.tif"
|
208 |
labels_path = "./data/labels_cog.tif"
|
209 |
field_ids_path = "./data/field_ids_cog.tif"
|
210 |
else:
|
211 |
+
features_path = "https://huggingface.co/datasets/crop-classification/zueri-crop-2/resolve/main/stacked_features_cog.tif"
|
212 |
+
labels_path = "https://huggingface.co/datasets/crop-classification/zueri-crop-2/resolve/main/labels_cog.tif"
|
213 |
+
field_ids_path = "https://huggingface.co/datasets/crop-classification/zueri-crop-2/resolve/main/field_ids_cog.tif"
|
|
|
214 |
|
215 |
# Local paths for stats and dataset info
|
216 |
stats_path = "./data/chips_stats.yaml"
|
pages/2_Perform_Crop_Classification.py
CHANGED
@@ -6,7 +6,6 @@ import os
|
|
6 |
|
7 |
from messis.messis import Messis
|
8 |
from inference import perform_inference
|
9 |
-
from inference import generate_presigned_url
|
10 |
|
11 |
from dotenv import load_dotenv
|
12 |
|
@@ -92,10 +91,10 @@ def perform_inference_step():
|
|
92 |
vmax=vmin_vmax[selected_band][1],
|
93 |
)
|
94 |
else:
|
95 |
-
presigned_url = generate_presigned_url('messis-demo', 'stacked_features_cog.tif')
|
96 |
m.add_cog_layer(
|
97 |
-
url=
|
98 |
name="Sentinel-2 Satellite Imagery",
|
|
|
99 |
bands=selected_bands,
|
100 |
rescale=f"{vmin_vmax[selected_band][0]},{vmin_vmax[selected_band][1]}"
|
101 |
)
|
|
|
6 |
|
7 |
from messis.messis import Messis
|
8 |
from inference import perform_inference
|
|
|
9 |
|
10 |
from dotenv import load_dotenv
|
11 |
|
|
|
91 |
vmax=vmin_vmax[selected_band][1],
|
92 |
)
|
93 |
else:
|
|
|
94 |
m.add_cog_layer(
|
95 |
+
url=os.environ.get("COG_URL"),
|
96 |
name="Sentinel-2 Satellite Imagery",
|
97 |
+
titiler_endpoint=os.environ.get("TITILER_ENDPOINT"),
|
98 |
bands=selected_bands,
|
99 |
rescale=f"{vmin_vmax[selected_band][0]},{vmin_vmax[selected_band][1]}"
|
100 |
)
|
requirements.txt
CHANGED
@@ -20,5 +20,4 @@ numpy==1.26.4
|
|
20 |
lion-pytorch==0.2.2
|
21 |
timm==0.9.16
|
22 |
pyproj
|
23 |
-
boto3
|
24 |
python-dotenv
|
|
|
20 |
lion-pytorch==0.2.2
|
21 |
timm==0.9.16
|
22 |
pyproj
|
|
|
23 |
python-dotenv
|