Skip to content

Commit

Permalink
Merge branch 'main' of github.com:weecology/MillionTrees into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Nov 12, 2024
2 parents 4301378 + 6b3536a commit d59814a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
3 changes: 2 additions & 1 deletion data_prep/collect_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"/orange/ewhite/DeepForest/Alejandro_Chile/alejandro/annotations.csv",
"/orange/ewhite/DeepForest/UrbanLondon/annotations.csv",
"/orange/ewhite/DeepForest/OliveTrees_spain/Dataset_RGB/annotations.csv",
"/orange/ewhite/DeepForest/Araujo_2020/annotations.csv"
"/orange/ewhite/DeepForest/Araujo_2020/annotations.csv",
"/orange/ewhite/DeepForest/justdiggit-drone/label_sample/annotations.csv"
]

# Current errors
Expand Down
38 changes: 27 additions & 11 deletions data_prep/justdiggit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,46 @@
from deepforest.utilities import read_file
from deepforest.visualize import plot_results
from matplotlib import pyplot as plt
import rasterio as rio

with open("/orange/ewhite/DeepForest/justdiggit-drone/label_sample/Annotations_trees_only.json") as jsonfile:
data = json.load(jsonfile)
ids = [x["id"] for x in data["images"]]
image_paths = [x["file_name"] for x in data["images"]]
id_df = pd.DataFrame({"id":ids,"image_path":image_paths})
id_dict = {key:value for key, value in zip(ids,image_paths)}
annotation_df = []
for row in data["annotations"]:
b = {"id":row["id"],"xmin":row["bbox"][0],"ymin":row["bbox"][1],"xmax":row["bbox"][2],"ymax":row["bbox"][3]}
polygon = row["segmentation"][0]

# split each pair into a tuple
as_tuples = [(polygon[i],polygon[i+1]) for i in range(0,len(polygon)-1,2)]

# close the polygon
as_tuples.append(as_tuples[0])

# convert polygon to wkt format
polygon_coordinates = ",".join(["{} {}".format(i[0],i[1]) for i in as_tuples])
polygon = "POLYGON ((" + polygon_coordinates + "))"

b = {"id":row["id"],"polygon":polygon}
b["image_path"] = id_dict[row["image_id"]]
annotation_df.append(b)
annotation_df = pd.DataFrame(annotation_df)
annotations = annotation_df.merge(id_df)
annotations["label"] = "Tree"
annotations["source"] = "Justdiggit et al. 2023"
annotation_df["label"] = "Tree"
annotation_df["source"] = "Justdiggit 2023"

print("There are {} annotations in {} images".format(annotations.shape[0], len(annotations.image_path.unique())))
print("There are {} annotations in {} images".format(annotation_df.shape[0], len(annotation_df.image_path.unique())))

annotations["image_path"] = "/orange/ewhite/DeepForest/justdiggit-drone/label_sample/" + annotations["image_path"]
annotations = read_file(annotations, root_dir="/orange/ewhite/DeepForest/justdiggit-drone/label_sample/")
annotations = read_file(annotation_df, root_dir="/orange/ewhite/DeepForest/justdiggit-drone/label_sample/")

for image in annotations.image_path.unique():
print(image)
gdf = annotations[annotations.image_path == image]
gdf.root_dir = "/orange/ewhite/DeepForest/justdiggit-drone/label_sample/"
plot_results(gdf)
plt.savefig("current.png")
annotations.to_csv("/orange/ewhite/DeepForest/justdiggit-drone/label_sample/train.csv")
width, height = rio.open(gdf.root_dir + image).shape

#plot_results(gdf, height=height, width=width)
#plt.savefig("current.png")

annotations["image_path"] = "/orange/ewhite/DeepForest/justdiggit-drone/label_sample/" + annotations["image_path"]
annotations.to_csv("/orange/ewhite/DeepForest/justdiggit-drone/label_sample/annotations.csv")
Binary file added docs/public/Justdiggit_2023.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion tests/test_TreeBoxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import torch
import pytest
import os
import pandas as pd
import numpy as np

# Check if running on hipergator
Expand Down

0 comments on commit d59814a

Please sign in to comment.