-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
96 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import glob | ||
import os | ||
import shutil | ||
import pandas as pd | ||
from deepforest.utilities import read_file | ||
|
||
BENCHMARK_PATH = "/orange/idtrees-collab/NeonTreeEvaluation/" | ||
tifs = glob.glob(BENCHMARK_PATH + "evaluation/RGB/*.tif") | ||
xmls = [os.path.splitext(os.path.basename(x))[0] for x in tifs] | ||
xmls = [os.path.join(BENCHMARK_PATH, "annotations", x) + ".xml" for x in xmls] | ||
|
||
#Load and format xmls, not every RGB image has an annotation | ||
annotation_list = [] | ||
for xml_path in xmls: | ||
try: | ||
annotation = read_file(xml_path) | ||
except: | ||
continue | ||
annotation_list.append(annotation) | ||
benchmark_annotations = pd.concat(annotation_list, ignore_index=True) | ||
|
||
benchmark_annotations["source"] = "NEON_benchmark" | ||
benchmark_annotations["label"] = "Tree" | ||
|
||
for image_path in benchmark_annotations.image_path.unique(): | ||
dst = os.path.join(BENCHMARK_PATH, "evaluation/RGB/", image_path) | ||
shutil.copy(dst, "/orange/ewhite/DeepForest/NEON_benchmark/images/") | ||
|
||
benchmark_annotations["image_path"] = benchmark_annotations.image_path.apply(lambda x: os.path.join("/orange/ewhite/DeepForest/NEON_benchmark/images/", x)) | ||
benchmark_annotations.to_csv("/orange/ewhite/DeepForest/NEON_benchmark/NeonTreeEvaluation_annotations.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import pandas as pd | ||
from deepforest.utilities import read_file | ||
import json | ||
|
||
# Define the directory containing the JSON files | ||
json_dir = "/orange/ewhite/DeepForest/Guangzhou2022/GZIndividualTree_Anno" | ||
|
||
# Initialize an empty list to store data | ||
data = [] | ||
|
||
# Iterate over all JSON files in the directory | ||
for filename in os.listdir(json_dir): | ||
if filename.endswith(".json"): | ||
file_path = os.path.join(json_dir, filename) | ||
# Read the JSON file | ||
|
||
with open(file_path, 'r') as f: | ||
coco_data = json.load(f) | ||
|
||
# Extract annotations | ||
for annotation in coco_data['annotations']: | ||
image_id = annotation['image_id'] | ||
image_info = next(item for item in coco_data['images'] if item['id'] == image_id) | ||
if 'treeInstance300' in file_path: | ||
image_path = os.path.join(json_dir, 'train', image_info['file_name']) | ||
elif 'test' in file_path: | ||
image_path = os.path.join(json_dir, 'test', image_info['file_name']) | ||
else: | ||
image_path = os.path.join(json_dir, image_info['file_name']) | ||
|
||
if not os.path.exists(image_path): | ||
continue | ||
|
||
xmin = annotation['bbox'][0] | ||
ymin = annotation['bbox'][1] | ||
xmax = xmin + annotation['bbox'][2] | ||
ymax = ymin + annotation['bbox'][3] | ||
|
||
# Append the data to the list | ||
data.append([image_path, xmin, xmax, ymin, ymax]) | ||
|
||
# Create a DataFrame | ||
df = pd.DataFrame(data, columns=['image_path', 'xmin', 'xmax', 'ymin', 'ymax']) | ||
df = read_file(df) | ||
df["label"] = "Tree" | ||
df["source"] = "Sun et al. 2022" | ||
|
||
# Save the DataFrame to a CSV file | ||
df.to_csv('/orange/ewhite/DeepForest/Guangzhou2022/annotations.csv', index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.