aletrn commited on
Commit
3d82071
·
1 Parent(s): e945b1f

[debug] add debug logs, set os.environ['MPLCONFIGDIR']

Browse files
src/app.py CHANGED
@@ -71,6 +71,7 @@ def get_parsed_bbox_points(request_input: RequestBody) -> Dict:
71
  source_type = request_input["source_type"] if "zoom" in request_input else SOURCE_TYPE
72
  app_logger.info(f"try to validate input request {request_input}...")
73
  request_body = RequestBody(ne=request_input["ne"], sw=request_input["sw"], model=model_name, zoom=zoom, source_type=source_type)
 
74
  return {
75
  "bbox": [
76
  request_body.ne.lat, request_body.sw.lat,
 
71
  source_type = request_input["source_type"] if "zoom" in request_input else SOURCE_TYPE
72
  app_logger.info(f"try to validate input request {request_input}...")
73
  request_body = RequestBody(ne=request_input["ne"], sw=request_input["sw"], model=model_name, zoom=zoom, source_type=source_type)
74
+ app_logger.info(f"unpacking {request_body}...")
75
  return {
76
  "bbox": [
77
  request_body.ne.lat, request_body.sw.lat,
src/prediction_api/samgeo_predictors.py CHANGED
@@ -1,23 +1,33 @@
1
  # Press the green button in the gutter to run the script.
2
  import json
 
3
 
4
  from src import app_logger
5
  from src.utilities.constants import ROOT, MODEL_NAME, ZOOM, SOURCE_TYPE
6
- from src.utilities.type_hints import input_floatlist, input_floatlist2
 
7
 
8
 
9
- def samgeo_fast_predict(bbox: input_floatlist, zoom: float = ZOOM, model_name: str = MODEL_NAME, root_folder: str = ROOT, source_type: str = SOURCE_TYPE) -> dict:
 
 
10
  import tempfile
11
  from samgeo import tms_to_geotiff
12
  from samgeo.fast_sam import SamGeo
13
 
 
 
 
 
 
 
14
  with tempfile.NamedTemporaryFile(prefix=f"{source_type}_", suffix=".tif", dir=root_folder) as image_input_tmp:
15
  app_logger.info(f"start tms_to_geotiff using bbox:{bbox}, type:{type(bbox)}, download image to {image_input_tmp.name} ...")
16
  for coord in bbox:
17
  app_logger.info(f"coord:{coord}, type:{type(coord)}.")
18
 
19
  # bbox: image input coordinate
20
- tms_to_geotiff(output=image_input_tmp.name, bbox=bbox, zoom=zoom, source=source_type, overwrite=True)
21
  app_logger.info(f"geotiff created, start to initialize SamGeo instance (read model {model_name} from {root_folder})...")
22
 
23
  predictor = SamGeo(
 
1
  # Press the green button in the gutter to run the script.
2
  import json
3
+ import os
4
 
5
  from src import app_logger
6
  from src.utilities.constants import ROOT, MODEL_NAME, ZOOM, SOURCE_TYPE
7
+ from src.utilities.type_hints import input_floatlist
8
+ from src.utilities.utilities import get_system_info
9
 
10
 
11
+ def samgeo_fast_predict(
12
+ bbox: input_floatlist, zoom: float = ZOOM, model_name: str = MODEL_NAME, root_folder: str = ROOT, source_type: str = SOURCE_TYPE, crs="EPSG:4326"
13
+ ) -> dict:
14
  import tempfile
15
  from samgeo import tms_to_geotiff
16
  from samgeo.fast_sam import SamGeo
17
 
18
+ try:
19
+ os.environ['MPLCONFIGDIR'] = root_folder
20
+ get_system_info()
21
+ except Exception as e:
22
+ app_logger.error(f"Error while setting 'MPLCONFIGDIR':{e}.")
23
+
24
  with tempfile.NamedTemporaryFile(prefix=f"{source_type}_", suffix=".tif", dir=root_folder) as image_input_tmp:
25
  app_logger.info(f"start tms_to_geotiff using bbox:{bbox}, type:{type(bbox)}, download image to {image_input_tmp.name} ...")
26
  for coord in bbox:
27
  app_logger.info(f"coord:{coord}, type:{type(coord)}.")
28
 
29
  # bbox: image input coordinate
30
+ tms_to_geotiff(output=image_input_tmp.name, bbox=bbox, zoom=zoom, source=source_type, overwrite=True, crs=crs)
31
  app_logger.info(f"geotiff created, start to initialize SamGeo instance (read model {model_name} from {root_folder})...")
32
 
33
  predictor = SamGeo(
src/utilities/utilities.py CHANGED
@@ -1,4 +1,5 @@
1
  """Various utilities (logger, time benchmark, args dump, numerical and stats info)"""
 
2
 
3
 
4
  def is_base64(sb):
@@ -17,6 +18,22 @@ def is_base64(sb):
17
  return False
18
 
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def base64_decode(s):
21
  import base64
22
 
 
1
  """Various utilities (logger, time benchmark, args dump, numerical and stats info)"""
2
+ from src import app_logger
3
 
4
 
5
  def is_base64(sb):
 
18
  return False
19
 
20
 
21
+ def get_system_info():
22
+ import multiprocessing
23
+ import torch.multiprocessing as mp
24
+ import os
25
+ import subprocess
26
+
27
+ app_logger.info(f"mp::cpu_count:{mp.cpu_count()}.")
28
+ app_logger.info(f"multiprocessing::cpu_count:{multiprocessing.cpu_count()}.")
29
+ app_logger.info(f"os::cpu_count:{os.cpu_count()}")
30
+ app_logger.info(f"os::sched_getaffinity:{len(os.sched_getaffinity(0))}")
31
+ lscpu_output = subprocess.run("/usr/bin/lscpu", capture_output=True)
32
+ app_logger.info(f"lscpu:{lscpu_output.stdout.decode('utf-8')}.")
33
+ free_mem_output = subprocess.run(["/usr/bin/free", "-m"], capture_output=True)
34
+ app_logger.info(f"free_mem_output:{free_mem_output.stdout.decode('utf-8')}.")
35
+
36
+
37
  def base64_decode(s):
38
  import base64
39