.root_dir attribute isn't maintained when filtering results objects
In the endless battle about the root_dir attribute, it really trips the user up that when you filter a results object, you can't immediately visualize. I don't see an obvious solution, but I think its important to highlight that this is a poor structure.
from deepforest import main
from deepforest import visualize
import matplotlib.pyplot as plt
m = main.deepforest()
m.load_model("Weecology/deepforest-bird")
image_path="/Users/benweinstein/Downloads/example_airborne_birds/5.jpg"
predictions = m.predict_tile(image_path, patch_size=600, patch_overlap=0)
# visualize the predictions
# This works, root dir is defined in predictions.root_dir from predict_tile
visualize.plot_results(predictions)
plt.show()
high_confidence = predictions[predictions.score>0.2]
# When you filter predictions, it loses the attribute.
# This is ugly and non-pythonic.
high_confidence.root_dir = "/Users/benweinstein/Downloads/example_airborne_birds"
visualize.plot_results(high_confidence)
Related to #1210 I wonder if we made DeepForest data class a subclass of Geopandas, we could alter the filter behavior to maintain root dir.
Related to https://github.com/weecology/DeepForest/pull/1210 I wonder if we made DeepForest data class a subclass of Geopandas, we could alter the filter behavior to maintain root dir.
Certainly seems reasonable
Pandas has a way to do this, trying it now.
import pandas as pd
class MyDataFrame(pd.DataFrame):
_metadata = ["custom_attribute"]
@property
def _constructor(self):
return MyDataFrame
df = MyDataFrame({'data': range(10)})
df.custom_attribute = 'my_value'
# Slicing the DataFrame will preserve the custom_attribute
sliced_df = df[:5]
print(sliced_df.custom_attribute)