Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve point plotting behavior for ground truth with no scores. #879

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/deepforest/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ def convert_to_sv_format(df, width=None, height=None):
labels = df['label'].map(label_mapping).values.astype(int)

# Extract scores as a numpy array
scores = np.array(df['score'].tolist())
try:
scores = np.array(df['score'].tolist())
except KeyError:
scores = np.ones(len(labels))

scores = np.expand_dims(np.stack(scores), 1)

# Create a reverse mapping from integer to string labels
Expand Down
20 changes: 18 additions & 2 deletions tests/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ def test_plot_results_point(m, tmpdir):
'y': [15, 25],
'label': ['Tree', 'Tree'],
'image_path': [get_data("OSBS_029.tif"), get_data("OSBS_029.tif")],
'score': [0.9, 0.8],
'label': ['Tree', 'Tree']
'score': [0.9, 0.8]
}
df = pd.DataFrame(data)
gdf = read_file(df, root_dir=os.path.dirname(get_data("OSBS_029.tif")))
Expand All @@ -178,6 +177,23 @@ def test_plot_results_point(m, tmpdir):
# Assertions
assert os.path.exists(os.path.join(tmpdir, "OSBS_029.png"))

def test_plot_results_point_no_label(m, tmpdir):
# Create a mock DataFrame with point annotations
data = {
'x': [15, 25],
'y': [15, 25],
'label': ['Tree', 'Tree'],
'image_path': [get_data("OSBS_029.tif"), get_data("OSBS_029.tif")],
}
df = pd.DataFrame(data)
gdf = read_file(df, root_dir=os.path.dirname(get_data("OSBS_029.tif")))
gdf.root_dir = os.path.dirname(get_data("OSBS_029.tif"))

# Call the function
visualize.plot_results(gdf, savedir=tmpdir)

# Assertions
assert os.path.exists(os.path.join(tmpdir, "OSBS_029.png"))

def test_plot_results_polygon(m, tmpdir):
# Create a mock DataFrame with polygon annotations
Expand Down
Loading