Spaces:
Runtime error
Runtime error
app
Browse files58 unmodified lines596061626364656667686970717273747576777879808182838485868788899058 unmodified linesTILE_H = 40def run_detectree2(geotiff_path: str, environment: str, conf_threshold: float):"""1) Tile TIFF, 2) Predict with Detectron2 model, 3) Project & stitch crowns,4) Clean, 5) Save GPKG + render overlay PNG.Returns (overlay_png_path, crowns_gpkg_path, stats_dict, log_str_or_empty)"""# Create a unique, writable workspace under /tmpworkdir = tempfile.mkdtemp(prefix="dtr2_")tiles_dir = os.path.join(workdir, "tilespred")os.makedirs(tiles_dir, exist_ok=True)try:# Copy input to working dir (some libs assume same FS)infile = os.path.join(workdir, os.path.basename(geotiff_path))shutil.copy2(geotiff_path, infile)# 1) Tiletile_data(infile, tiles_dir, BUFFER, TILE_W, TILE_H, dtype_bool=True)# 2) Config + predictorweights = WEIGHTS.get(environment) or WEIGHTS[DEFAULT_ENV]if not os.path.exists(weights):return None, None, None, f"Error: weights not found at {weights}"cfg = setup_cfg(update_model=weights)cfg.MODEL.DEVICE = DEVICE# IMPORTANT: ensure all detectron/detectree2 outputs go to our temp dircfg.OUTPUT_DIR = os.path.join(workdir, "train_outputs")os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)58 unmodified lines596061626364656667686970717273747576777879808158 unmodified linesTILE_H = 40def run_detectree2(geotiff_path: str, environment: str, conf_threshold: float):workdir = tempfile.mkdtemp(prefix="dtr2_")tiles_dir = os.path.join(workdir, "tilespred")os.makedirs(tiles_dir, exist_ok=True)# 👇 Add this so any relative writes (like "./train_outputs") land in /tmpos.chdir(workdir)try:infile = os.path.join(workdir, os.path.basename(geotiff_path))shutil.copy2(geotiff_path, infile)# ...weights = WEIGHTS.get(environment) or WEIGHTS[DEFAULT_ENV]cfg = setup_cfg(update_model=weights)# make absolutely sure outputs stay in our temp workspacecfg.MODEL.DEVICE = DEVICEcfg.OUTPUT_DIR = os.path.join(workdir, "train_outputs")os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
app.py+6-15