Skip to content

Commit

Permalink
detect_objects: workaround for 'FutureWarning: The frame.append metho…
Browse files Browse the repository at this point in the history
…d is deprecated and will be removed from pandas in a future version. Use pandas.concat instead', see pandas-dev/pandas#35407
  • Loading branch information
PolarNick239 committed Apr 8, 2022
1 parent 099ce2d commit bb299a4
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/detect_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@
raise Exception("Incompatible Metashape version: {} != {}".format(found_major_version, compatible_major_version))


def pandas_append(df, row, ignore_index=False):
import pandas as pd
if isinstance(row, pd.DataFrame):
result = pd.concat([df, row], ignore_index=ignore_index)
elif isinstance(row, pd.core.series.Series):
result = pd.concat([df, row.to_frame().T], ignore_index=ignore_index)
elif isinstance(row, dict):
result = pd.concat([df, pd.DataFrame(row, index=[0], columns=df.columns)])
else:
raise RuntimeError("pandas_append: unsupported row type - {}".format(type(row)))
return result


class DetectObjectsDlg(QtWidgets.QDialog):

def __init__(self, parent):
Expand Down Expand Up @@ -386,7 +399,7 @@ def train_on_user_data(self):
cv2.imwrite(self.dir_train_subtiles + empty_tile_name, empty_tile)

# See https://github.com/weecology/DeepForest/issues/216
all_annotations = all_annotations.append({'image_path': empty_tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
all_annotations = pandas_append(all_annotations, {'image_path': empty_tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)

nempty_tiles = 0

Expand Down Expand Up @@ -483,10 +496,10 @@ def train_on_user_data(self):

nannotated_tiles += 1
for (xmin, ymin), (xmax, ymax) in tile_annotations_version:
all_annotations = all_annotations.append({'image_path': tile_name, 'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax, 'label': 'Tree'}, ignore_index=True)
all_annotations = pandas_append(all_annotations, {'image_path': tile_name, 'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax, 'label': 'Tree'}, ignore_index=True)
if len(tile_annotations_version) == 0:
if self.tiles_without_annotations_supported:
all_annotations = all_annotations.append({'image_path': tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
all_annotations = pandas_append(all_annotations, {'image_path': tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True)
nempty_tiles += 1

cv2.imwrite(self.dir_train_subtiles + tile_name, tile_version)
Expand Down Expand Up @@ -788,9 +801,9 @@ def detect(self):
continue
xmin, xmax = map(lambda x: fromx + x, [xmin, xmax])
ymin, ymax = map(lambda y: fromy + y, [ymin, ymax])
subtile_inner_trees_debug = subtile_inner_trees_debug.append(row, ignore_index=True)
subtile_inner_trees_debug = pandas_append(subtile_inner_trees_debug, row, ignore_index=True)
row.xmin, row.ymin, row.xmax, row.ymax = xmin, ymin, xmax, ymax
subtile_inner_trees = subtile_inner_trees.append(row, ignore_index=True)
subtile_inner_trees = pandas_append(subtile_inner_trees, row, ignore_index=True)

if self.debug_tiles:
img_with_trees = self.debug_draw_trees(subtile, subtile_trees)
Expand Down Expand Up @@ -862,7 +875,7 @@ def detect(self):
for idx, row in a.iterrows():
if row.label == "Suppressed":
continue
big_tile_trees = big_tile_trees.append(row, ignore_index=True)
big_tile_trees = pandas_append(big_tile_trees, row, ignore_index=True)

idx_on_borders = []
for idx, rowA in big_tile_trees.iterrows():
Expand Down

0 comments on commit bb299a4

Please sign in to comment.