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

cleanup, restructure, and redesign #5

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
65 changes: 25 additions & 40 deletions ...uation_panel/evaluation_panel/__init__.py → __init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import fiftyone as fo
import fiftyone.brain as fob
import fiftyone.core.fields as fof
import fiftyone.core.labels as fol
import fiftyone.core.patches as fop
import fiftyone.operators as foo
import fiftyone.operators.types as types
import fiftyone.zoo.models as fozm
import numpy as np
from fiftyone import ViewField as F
from fiftyone.brain import Similarity


class EvaluationPanel(foo.Panel):
Expand Down Expand Up @@ -367,7 +360,7 @@ def _update_table_data(self, ctx):
new_row = {"class": "All", "AP": int(results.mAP() * 1000) / 1000}
mAP_list.append(new_row)
ctx.panel.set_data("my_stack.mAP_evaluations", mAP_list)

# Compare key DOES exist, update c_(table_name) instead
else:
c_eval = ctx.dataset.get_evaluation_info(compare_key).serialize()
Expand Down Expand Up @@ -512,9 +505,9 @@ def _update_plot_data(
ctx,
):
# _update_plot_data is called in on_change_config
# The function updates the DATA of all the plots in the panel,
# The function updates the DATA of all the plots in the panel,
# including histograms and confusion matrices# _update_plot_data is called in on_change_config
# The function updates the DATA of all the plots in the panel,
# The function updates the DATA of all the plots in the panel,
# including histograms and confusion matrices

# Grab the basic info
Expand Down Expand Up @@ -629,25 +622,24 @@ def _update_plot_data(
],
)

#Calculate recall, precision, and f1. Dont forget to check for divide by 0!
# Calculate recall, precision, and f1. Dont forget to check for divide by 0!
tp = np.array(ctx.dataset.values(f"{eval_key}_tp"))
fp = np.array(ctx.dataset.values(f"{eval_key}_fp"))
fn = np.array(ctx.dataset.values(f"{eval_key}_fn"))

n = tp.astype(np.float64)
d = (tp+fp).astype(np.float64)
p = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (tp + fp).astype(np.float64)
p = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
p = np.nan_to_num(p, nan=0.0)


n = tp.astype(np.float64)
d = (tp+fn).astype(np.float64)
r = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (tp + fn).astype(np.float64)
r = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
r = np.nan_to_num(r, nan=0.0)

n = (2 * (p * r)).astype(np.float64)
d = (p+r).astype(np.float64)
f1 = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (p + r).astype(np.float64)
f1 = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
f1 = np.nan_to_num(f1, nan=0.0)

p_left_edges, p_counts, p_widths = compute_histogram(p, 10)
Expand Down Expand Up @@ -736,7 +728,6 @@ def _update_plot_data(

conf = sum(conf_total) / len(conf_total)


if tp + fp != 0:
p = tp / (tp + fp)
p = np.nan_to_num(p, nan=0.0)
Expand Down Expand Up @@ -899,7 +890,7 @@ def _update_plot_data(
else:
r = 0
r = np.nan_to_num(r, nan=0.0)
if p+r !=0:
if p + r != 0:
f1 = 2 * (p * r) / (p + r)
else:
f1 = 0
Expand Down Expand Up @@ -1093,35 +1084,33 @@ def _update_plot_data(
c_fn = np.array(ctx.dataset.values(f"{compare_key}_fn"))

n = tp.astype(np.float64)
d = (tp+fp).astype(np.float64)
p = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (tp + fp).astype(np.float64)
p = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
p = np.nan_to_num(p, nan=0.0)


n = tp.astype(np.float64)
d = (tp+fn).astype(np.float64)
r = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (tp + fn).astype(np.float64)
r = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
r = np.nan_to_num(r, nan=0.0)

n = (2 * (p * r)).astype(np.float64)
d = (p+r).astype(np.float64)
f1 = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (p + r).astype(np.float64)
f1 = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
f1 = np.nan_to_num(f1, nan=0.0)

n = c_tp.astype(np.float64)
d = (c_tp+c_fp).astype(np.float64)
c_p = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (c_tp + c_fp).astype(np.float64)
c_p = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
c_p = np.nan_to_num(c_p, nan=0.0)


n = c_tp.astype(np.float64)
d = (c_tp+c_fn).astype(np.float64)
c_r = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (c_tp + c_fn).astype(np.float64)
c_r = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
c_r = np.nan_to_num(r, nan=0.0)

n = (2 * (c_p * c_r)).astype(np.float64)
d = (c_p+c_r).astype(np.float64)
c_f1 = np.divide(n, d, out=np.full_like(n, np.nan), where=d!= 0)
d = (c_p + c_r).astype(np.float64)
c_f1 = np.divide(n, d, out=np.full_like(n, np.nan), where=d != 0)
c_f1 = np.nan_to_num(f1, nan=0.0)

p_left_edges, p_counts, p_widths = compute_histogram(p, 10)
Expand Down Expand Up @@ -1242,8 +1231,6 @@ def _update_plot_data(

conf = sum(conf_total) / len(conf_total)



if tp + fp != 0:
p = tp / (tp + fp)
p = np.nan_to_num(p, nan=0.0)
Expand Down Expand Up @@ -1316,7 +1303,6 @@ def _update_plot_data(
else:
c_f1 = 0


c_p_class_list.append(c_p)
c_r_class_list.append(c_r)
c_f1_class_list.append(c_f1)
Expand Down Expand Up @@ -1538,7 +1524,7 @@ def _update_plot_data(
else:
r = 0
r = np.nan_to_num(r, nan=0.0)
if p+r !=0:
if p + r != 0:
f1 = 2 * (p * r) / (p + r)
else:
f1 = 0
Expand Down Expand Up @@ -1720,7 +1706,6 @@ def _add_plots(self, ctx, stack):
# Start the ones that always appear regardless of model type and follow by eval_type
# specific ones afterwards


# Start by grabbing some basics
eval_key = ctx.panel.get_state("my_stack.menu.actions.eval_key")
compare_key = ctx.panel.get_state("my_stack.menu.actions.compare_key", None)
Expand All @@ -1744,7 +1729,7 @@ def _add_plots(self, ctx, stack):

# After the plot layout/config is defined, add the property to the stack with the
# appropriate on_call and on_selected calls
#TODO add on_selected
# TODO add on_selected
stack.add_property(
"confidence",
types.Property(
Expand Down
Loading