|
85 | 85 | raise Exception("Incompatible Metashape version: {} != {}".format(found_major_version, compatible_major_version))
|
86 | 86 |
|
87 | 87 |
|
| 88 | +def pandas_append(df, row, ignore_index=False): |
| 89 | + import pandas as pd |
| 90 | + if isinstance(row, pd.DataFrame): |
| 91 | + result = pd.concat([df, row], ignore_index=ignore_index) |
| 92 | + elif isinstance(row, pd.core.series.Series): |
| 93 | + result = pd.concat([df, row.to_frame().T], ignore_index=ignore_index) |
| 94 | + elif isinstance(row, dict): |
| 95 | + result = pd.concat([df, pd.DataFrame(row, index=[0], columns=df.columns)]) |
| 96 | + else: |
| 97 | + raise RuntimeError("pandas_append: unsupported row type - {}".format(type(row))) |
| 98 | + return result |
| 99 | + |
| 100 | + |
88 | 101 | class DetectObjectsDlg(QtWidgets.QDialog):
|
89 | 102 |
|
90 | 103 | def __init__(self, parent):
|
@@ -386,7 +399,7 @@ def train_on_user_data(self):
|
386 | 399 | cv2.imwrite(self.dir_train_subtiles + empty_tile_name, empty_tile)
|
387 | 400 |
|
388 | 401 | # See https://github.com/weecology/DeepForest/issues/216
|
389 |
| - all_annotations = all_annotations.append({'image_path': empty_tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True) |
| 402 | + all_annotations = pandas_append(all_annotations, {'image_path': empty_tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True) |
390 | 403 |
|
391 | 404 | nempty_tiles = 0
|
392 | 405 |
|
@@ -483,10 +496,10 @@ def train_on_user_data(self):
|
483 | 496 |
|
484 | 497 | nannotated_tiles += 1
|
485 | 498 | for (xmin, ymin), (xmax, ymax) in tile_annotations_version:
|
486 |
| - all_annotations = all_annotations.append({'image_path': tile_name, 'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax, 'label': 'Tree'}, ignore_index=True) |
| 499 | + all_annotations = pandas_append(all_annotations, {'image_path': tile_name, 'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax, 'label': 'Tree'}, ignore_index=True) |
487 | 500 | if len(tile_annotations_version) == 0:
|
488 | 501 | if self.tiles_without_annotations_supported:
|
489 |
| - all_annotations = all_annotations.append({'image_path': tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True) |
| 502 | + all_annotations = pandas_append(all_annotations, {'image_path': tile_name, 'xmin': '0', 'ymin': '0', 'xmax': '0', 'ymax': '0', 'label': 'Tree'}, ignore_index=True) |
490 | 503 | nempty_tiles += 1
|
491 | 504 |
|
492 | 505 | cv2.imwrite(self.dir_train_subtiles + tile_name, tile_version)
|
@@ -788,9 +801,9 @@ def detect(self):
|
788 | 801 | continue
|
789 | 802 | xmin, xmax = map(lambda x: fromx + x, [xmin, xmax])
|
790 | 803 | ymin, ymax = map(lambda y: fromy + y, [ymin, ymax])
|
791 |
| - subtile_inner_trees_debug = subtile_inner_trees_debug.append(row, ignore_index=True) |
| 804 | + subtile_inner_trees_debug = pandas_append(subtile_inner_trees_debug, row, ignore_index=True) |
792 | 805 | row.xmin, row.ymin, row.xmax, row.ymax = xmin, ymin, xmax, ymax
|
793 |
| - subtile_inner_trees = subtile_inner_trees.append(row, ignore_index=True) |
| 806 | + subtile_inner_trees = pandas_append(subtile_inner_trees, row, ignore_index=True) |
794 | 807 |
|
795 | 808 | if self.debug_tiles:
|
796 | 809 | img_with_trees = self.debug_draw_trees(subtile, subtile_trees)
|
@@ -862,7 +875,7 @@ def detect(self):
|
862 | 875 | for idx, row in a.iterrows():
|
863 | 876 | if row.label == "Suppressed":
|
864 | 877 | continue
|
865 |
| - big_tile_trees = big_tile_trees.append(row, ignore_index=True) |
| 878 | + big_tile_trees = pandas_append(big_tile_trees, row, ignore_index=True) |
866 | 879 |
|
867 | 880 | idx_on_borders = []
|
868 | 881 | for idx, rowA in big_tile_trees.iterrows():
|
|
0 commit comments