-
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
8 changed files
with
557 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from deepforest import main | ||
from deepforest.utilities import read_file | ||
from deepforest.preprocess import split_raster | ||
import os | ||
import geopandas as gpd | ||
import pandas as pd | ||
|
||
gdf = gpd.read_file("/orange/ewhite/DeepForest/Araujo_2020/crown_delineation_shapefile.shp") | ||
gdf = gdf[gdf.geometry.type=="Polygon"] | ||
gdf["image_path"] = "Orthomosaic_WGS84_UTM20S.tif" | ||
gdf["label"] = "Tree" | ||
gdf["source"] = "Araujo et al. 2020" | ||
df = read_file(gdf, root_dir="/orange/ewhite/DeepForest/Araujo_2020/") | ||
df = df[["geometry", "image_path", "label", "source"]] | ||
df["polygon"] = df.geometry.apply(lambda x: x.wkt) | ||
df.drop(columns=["geometry"], inplace=True) | ||
df = pd.DataFrame(df) | ||
split_files = split_raster(df, path_to_raster="/orange/ewhite/DeepForest/Araujo_2020/Orthomosaic_WGS84_UTM20S.tif", root_dir="/orange/ewhite/DeepForest/Araujo_2020/", | ||
base_dir="/orange/ewhite/DeepForest/Araujo_2020/crops/", patch_size=1500, patch_overlap=0) | ||
|
||
split_files["image_path"] = split_files["image_path"].apply(lambda x: os.path.join("/orange/ewhite/DeepForest/Araujo_2020/crops/", x)) | ||
split_files.to_csv("/orange/ewhite/DeepForest/Araujo_2020/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,42 @@ | ||
import glob | ||
import os | ||
import pandas as pd | ||
import shutil | ||
import geopandas as gpd | ||
from deepforest.utilities import read_file | ||
|
||
## Train annotations ## | ||
BASE_PATH = "/orange/ewhite/b.weinstein/NeonTreeEvaluation/hand_annotations/" | ||
#convert hand annotations from xml into retinanet format | ||
xmls = glob.glob(BASE_PATH + "*.xml") | ||
annotation_list = [] | ||
for xml in xmls: | ||
#check if it is in the directory | ||
image_name = "{}.tif".format(os.path.splitext(os.path.basename(xml))[0]) | ||
if os.path.exists(os.path.join(BASE_PATH, image_name)): | ||
print(xml) | ||
annotation = read_file(xml) | ||
annotation_list.append(annotation) | ||
|
||
#Collect hand annotations | ||
annotations = pd.concat(annotation_list, ignore_index=True) | ||
|
||
#collect shapefile annotations | ||
shps = glob.glob(BASE_PATH + "*.shp") | ||
shps_tifs = glob.glob(BASE_PATH + "*.tif") | ||
shp_results = [] | ||
for shp in shps: | ||
print(shp) | ||
rgb = "{}.tif".format(os.path.splitext(shp)[0]) | ||
gdf = gpd.read_file(shp) | ||
gdf["label"] = "Tree" | ||
gdf["image_path"] = os.path.join(BASE_PATH, rgb) | ||
shp_df = read_file(gdf, root_dir=BASE_PATH) | ||
shp_df = pd.DataFrame(shp_df) | ||
shp_results.append(shp_df) | ||
|
||
shp_results = pd.concat(shp_results, ignore_index=True) | ||
annotations = pd.concat([annotations, shp_results]) | ||
|
||
#Ensure column order | ||
annotations["source"] = "Weecology_University_Florida" | ||
annotations["label"] = "Tree" | ||
annotations["image_path"] = annotations.image_path.apply(lambda x: os.path.join("/orange/ewhite/DeepForest/NEON_benchmark/images/", x)) | ||
|
||
annotations.to_csv("/orange/ewhite/DeepForest/NEON_benchmark/University_of_Florida.csv") | ||
# Define the base path | ||
BASE_PATH = "/orange/ewhite/b.weinstein/NeonTreeEvaluation/hand_annotations/crops" | ||
|
||
# Load all CSV files in the specified directory | ||
csv_files = glob.glob(os.path.join(BASE_PATH, "*.csv")) | ||
csv_list = [] | ||
|
||
for csv_file in csv_files: | ||
print(csv_file) | ||
df = read_file(csv_file) | ||
df["image_path"] = df["image_path"].apply(lambda x: os.path.join(BASE_PATH, x)) | ||
df["source"] = "Weecology_University_Florida" | ||
df["label"] = "Tree" | ||
csv_list.append(df) | ||
|
||
# Concatenate all CSV dataframes | ||
annotations = pd.concat(csv_list, ignore_index=True) | ||
|
||
# Save the combined annotations to a CSV file | ||
output_path = "/orange/ewhite/DeepForest/NEON_benchmark/University_of_Florida.csv" | ||
|
||
# Save the combined annotations to a CSV file | ||
annotations.to_csv(output_path, index=False) | ||
|
||
# Load the existing annotations file | ||
existing_annotations_path = "/orange/ewhite/DeepForest/NEON_benchmark/NeonTreeEvaluation_annotations.csv" | ||
existing_annotations = pd.read_csv(existing_annotations_path) | ||
|
||
# Check for overlapping data based on a common column, e.g., 'image_path' | ||
overlapping_data = pd.merge(annotations, existing_annotations, on='image_path', how='inner') | ||
|
||
# Print the overlapping data | ||
print("Overlapping data:") | ||
print(overlapping_data) | ||
annotations.to_csv(output_path, 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.