-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tile.py
More file actions
37 lines (33 loc) · 1.49 KB
/
Copy pathrun_tile.py
File metadata and controls
37 lines (33 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from deepforest import main
import argparse
import os
from dotenv import load_dotenv
#Load Hugging Face token from .env file
load_dotenv()
hf_token = os.getenv("HF_TOKEN")
os.environ["HUGGINGFACE_HUB_TOKEN"] = hf_token
#Settings
parser = argparse.ArgumentParser()
parser.add_argument("--image_path", type=str, required=True, help="Path to the input image")
parser.add_argument("--patch_size", type=int, default=800, help="Size of the patches to split the image into")
parser.add_argument("--patch_overlap", type=float, default=0.25, help="Overlap between patches (0-1)")
parser.add_argument("--score_threshold", type=float, default=0.2, help="Minimum score threshold for predictions (0-1)")
parser.add_argument("--iou_threshold", type=float, default=0.15, help="IOU threshold for non-max suppression (0-1)")
parser.add_argument("--batch_size", type=int, default=16, help="Batch size for prediction")
parser.add_argument("--output_gdf", type=str, help="Path to the output GeoDataFrame file")
args = parser.parse_args()
model = main.deepforest()
gdf = model.predict_tile(
path=args.image_path,
patch_size=args.patch_size,
patch_overlap=args.patch_overlap,
iou_threshold=args.iou_threshold,
# batch_size=args.batch_size
)
# Filter predictions by score threshold
gdf = gdf[gdf['score'] >= args.score_threshold]
#Force overwrite if file exists
if os.path.exists(args.output_gdf):
os.remove(args.output_gdf)
gdf.to_csv(args.output_gdf, index=False)
print(f"\nSaved predictions to {args.output_gdf}")