From bb299a46686c0777b9cbf7b1ccdba489034635af Mon Sep 17 00:00:00 2001 From: Nikolay Polyarniy Date: Fri, 8 Apr 2022 17:12:06 +0300 Subject: [PATCH] detect_objects: workaround for 'FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead', see https://github.com/pandas-dev/pandas/issues/35407 --- src/detect_objects.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/detect_objects.py b/src/detect_objects.py index 0dbfc0b..58da8c1 100644 --- a/src/detect_objects.py +++ b/src/detect_objects.py @@ -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): @@ -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 @@ -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) @@ -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) @@ -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():